List of usage examples for java.security Security getAlgorithms
public static Set<String> getAlgorithms(String serviceName)
From source file:org.apache.metron.stellar.common.utils.hashing.DefaultHasher.java
public static final Set<String> supportedHashes() { return new HashSet<>(Security.getAlgorithms("MessageDigest")); }
From source file:org.apache.metron.stellar.dsl.functions.HashFunctionsTest.java
@Test public void allAlgorithmsForMessageDigestShouldBeAbleToHash() throws Exception { final String valueToHash = "My value to hash"; final Set<String> algorithms = Security.getAlgorithms("MessageDigest"); algorithms.forEach(algorithm -> { try {// www . j a v a2 s. co m final MessageDigest expected = MessageDigest.getInstance(algorithm); expected.update(valueToHash.getBytes(StandardCharsets.UTF_8)); assertEquals(expectedHexString(expected), hash.apply(Arrays.asList(valueToHash, algorithm))); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }); }
From source file:org.apache.metron.stellar.dsl.functions.HashFunctionsTest.java
@Test public void allAlgorithmsForMessageDigestShouldBeAbleToHashDirectStellarCall() throws Exception { final String valueToHash = "My value to hash"; final Set<String> algorithms = Security.getAlgorithms("MessageDigest"); algorithms.forEach(algorithm -> { try {/*w w w.j ava 2s.c om*/ final Object actual = run("HASH('" + valueToHash + "', '" + algorithm + "')", Collections.emptyMap()); final MessageDigest expected = MessageDigest.getInstance(algorithm); expected.update(valueToHash.getBytes(StandardCharsets.UTF_8)); assertEquals(expectedHexString(expected), actual); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }); }
From source file:org.jets3t.service.security.EncryptionUtil.java
/** * Lists the PBE ciphers available on the system, optionally eliminating those * ciphers that are apparently available but cannot actually be used (perhaps due to * the lack of export-grade JCE settings). * * @param testAvailability/* w ww . j a v a2 s. c o m*/ * if true each apparently available cipher is tested and only those that pass * {@link #isCipherAvailableForUse(String)} are returned. * * @return * a list of all the available PBE cipher names on the system. */ public static String[] listAvailablePbeCiphers(boolean testAvailability) { Set ciphers = Security.getAlgorithms("Cipher"); Set pbeCiphers = new HashSet(); for (Iterator iter = ciphers.iterator(); iter.hasNext();) { String cipher = (String) iter.next(); if (cipher.toLowerCase().startsWith("pbe")) { if (!testAvailability || isCipherAvailableForUse(cipher)) { pbeCiphers.add(cipher); } } } return (String[]) pbeCiphers.toArray(new String[pbeCiphers.size()]); }
From source file:org.nuxeo.common.codec.Crypto.java
/** * The method returns either the decrypted {@code strToDecrypt}, either the {@code strToDecrypt} itself if it is not * recognized as a crypted string or if the decryption fails. The return value is a byte array for security purpose, * it is your responsibility to convert it then to a String or not (use of {@code char[]} is recommended). * * @param strToDecrypt//from ww w . ja v a 2 s.c om * @return the decrypted {@code strToDecrypt} as an array of bytes, never {@code null} * @see #getChars(byte[]) */ public byte[] decrypt(String strToDecrypt) { Matcher matcher = CRYPTO_PATTERN.matcher(strToDecrypt); if (!matcher.matches()) { return strToDecrypt.getBytes(); } Cipher decipher; try { String algorithm = new String(Base64.decodeBase64(matcher.group("algo"))); if (StringUtils.isBlank(algorithm)) { algorithm = DEFAULT_ALGO; } decipher = Cipher.getInstance(algorithm); decipher.init(Cipher.DECRYPT_MODE, getSecretKey(algorithm, secretKey)); final byte[] decryptedString = decipher.doFinal(Base64.decodeBase64(matcher.group("value"))); return decryptedString; } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { log.trace("Available algorithms: " + Security.getAlgorithms("Cipher")); log.trace("Available security providers: " + Arrays.asList(Security.getProviders())); log.debug(e, e); } catch (InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) { log.debug(e, e); } return strToDecrypt.getBytes(); }
From source file:org.xdi.oxauth.model.util.JwtUtil.java
public static void printAlgorithmsAndProviders() { Set<String> algorithms = Security.getAlgorithms("Signature"); for (String algorithm : algorithms) { log.trace("Algorithm (Signature): " + algorithm); }//from w w w . ja v a2 s . c o m algorithms = Security.getAlgorithms("MessageDigest"); for (String algorithm : algorithms) { log.trace("Algorithm (MessageDigest): " + algorithm); } algorithms = Security.getAlgorithms("Cipher"); for (String algorithm : algorithms) { log.trace("Algorithm (Cipher): " + algorithm); } algorithms = Security.getAlgorithms("Mac"); for (String algorithm : algorithms) { log.trace("Algorithm (Mac): " + algorithm); } algorithms = Security.getAlgorithms("KeyStore"); for (String algorithm : algorithms) { log.trace("Algorithm (KeyStore): " + algorithm); } Provider[] providers = Security.getProviders(); for (Provider provider : providers) { log.trace("Provider: " + provider.getName()); } }