public static final Set<String> supportedHashes() { return new HashSet<>(Security.getAlgorithms("MessageDigest")); }
@Test public void allAlgorithmsForMessageDigestShouldBeAbleToHash() throws Exception { final String valueToHash = "My value to hash"; final Set<String> algorithms = Security.getAlgorithms("MessageDigest"); algorithms.forEach(algorithm -> { try { 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); } }); }
@Test public void allAlgorithmsForMessageDigestShouldBeAbleToHashDirectStellarCall() throws Exception { final String valueToHash = "My value to hash"; final Set<String> algorithms = Security.getAlgorithms("MessageDigest"); algorithms.forEach(algorithm -> { try { 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); } }); }
static String choosePssAlgorithmName(String legacyName) { for (String sigAlg : Security.getAlgorithms("Signature")) { if (RSASSA_PSS.equalsIgnoreCase(sigAlg)) { return sigAlg; } } return legacyName; } }
public static boolean isAvailable(String serviceName, String algorithm) { Set<String> algorithms = Security.getAlgorithms(serviceName); for (String serviceAlg : algorithms) { if (serviceAlg.equalsIgnoreCase(algorithm)) { return true; } } log.debug("{} is NOT available for {}. Algorithms available from underlying JCE: {}", algorithm, serviceName, algorithms); return false; } }
public boolean isAvailable() { Set<String> keyFactories = Security.getAlgorithms("KeyFactory"); Set<String> keyPairGenerators = Security.getAlgorithms("KeyPairGenerator"); String algorithm = getAlgorithm(); return keyPairGenerators.contains(algorithm) && keyFactories.contains(algorithm); } }
private static String[] listAvailablePbeCiphers() { 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")) { pbeCiphers.add(cipher); } } return (String[]) pbeCiphers.toArray(new String[pbeCiphers.size()]); }
private static String[] listAvailablePbeCiphers() { 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")) { pbeCiphers.add(cipher); } } return (String[]) pbeCiphers.toArray(new String[pbeCiphers.size()]); }
System.out.println("Providers: "); java.security.Provider[] providers = java.security.Security.getProviders(); for(int x = 0; x < providers.length; x++) { System.out.println("\t" + providers[x]); } System.out.println(); System.out.println("Algorithms: "); java.util.Set algs = java.security.Security.getAlgorithms("Cipher"); java.util.Iterator i_algs = algs.iterator(); while(i_algs.hasNext()) { System.out.println("\t" + i_algs.next()); }
/** * <p> * Returns a set with the names of all the registered digest algorithms. * This set will also include algorithms from any third-party (non-JVM) registered * providers. * </p> * * @since 1.7 * * @return a Set of Strings with the names of all the registered * digest algorithms. */ public static Set getAllDigestAlgorithms() { final List algos = new ArrayList(Security.getAlgorithms("MessageDigest")); Collections.sort(algos); return Collections.unmodifiableSet(new LinkedHashSet(algos)); }
/** * <p> * Returns a set with the names of all the registered digest algorithms. * This set will also include algorithms from any third-party (non-JVM) registered * providers. * </p> * * @since 1.7 * * @return a Set of Strings with the names of all the registered * digest algorithms. */ public static Set getAllDigestAlgorithms() { final List algos = new ArrayList(Security.getAlgorithms("MessageDigest")); Collections.sort(algos); return Collections.unmodifiableSet(new LinkedHashSet(algos)); }
/** * <p> * Returns a set with the names of all the registered digest algorithms. * This set will also include algorithms from any third-party (non-JVM) registered * providers. * </p> * * @since 1.7 * * @return a Set of Strings with the names of all the registered * digest algorithms. */ public static Set getAllDigestAlgorithms() { final List algos = new ArrayList(Security.getAlgorithms("MessageDigest")); Collections.sort(algos); return Collections.unmodifiableSet(new LinkedHashSet(algos)); }
/** * <p> * Returns a set with the names of all the registered PBE (Password-Based * Encryption) algorithms. * This set will also include algorithms from any third-party (non-JVM) registered * providers. * </p> * * @since 1.7 * * @return a Set of Strings with the names of all the registered * PBE algorithms. */ public static Set getAllPBEAlgorithms() { final List algos = new ArrayList(Security.getAlgorithms("Cipher")); Collections.sort(algos); final LinkedHashSet pbeAlgos = new LinkedHashSet(); final Iterator algosIter = algos.iterator(); while (algosIter.hasNext()) { final String algo = (String) algosIter.next(); if (algo != null && algo.startsWith("PBE")) { pbeAlgos.add(algo); } } return Collections.unmodifiableSet(pbeAlgos); }
/** * <p> * Returns a set with the names of all the registered PBE (Password-Based * Encryption) algorithms. * This set will also include algorithms from any third-party (non-JVM) registered * providers. * </p> * * @since 1.7 * * @return a Set of Strings with the names of all the registered * PBE algorithms. */ public static Set getAllPBEAlgorithms() { final List algos = new ArrayList(Security.getAlgorithms("Cipher")); Collections.sort(algos); final LinkedHashSet pbeAlgos = new LinkedHashSet(); final Iterator algosIter = algos.iterator(); while (algosIter.hasNext()) { final String algo = (String) algosIter.next(); if (algo != null && algo.startsWith("PBE")) { pbeAlgos.add(algo); } } return Collections.unmodifiableSet(pbeAlgos); }
/** * 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 * 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()]); }
/** * <p> * Returns a set with the names of all the registered PBE (Password-Based * Encryption) algorithms. * This set will also include algorithms from any third-party (non-JVM) registered * providers. * </p> * * @since 1.7 * * @return a Set of Strings with the names of all the registered * PBE algorithms. */ public static Set getAllPBEAlgorithms() { final List algos = new ArrayList(Security.getAlgorithms("Cipher")); Collections.sort(algos); final LinkedHashSet pbeAlgos = new LinkedHashSet(); final Iterator algosIter = algos.iterator(); while (algosIter.hasNext()) { final String algo = (String) algosIter.next(); if (algo != null && algo.startsWith("PBE")) { pbeAlgos.add(algo); } } return Collections.unmodifiableSet(pbeAlgos); }
/** * 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 * 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()]); }
return decipher.doFinal(Base64.decodeBase64(matcher.group("value"))); } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { log.trace("Available algorithms: " + Security.getAlgorithms("Cipher")); log.trace("Available security providers: " + Arrays.asList(Security.getProviders())); log.debug(e, e);
LOGGER.debug("Provider: {} - {}", prov.getName(), prov.getInfo()); final Set<String> signatures = Security.getAlgorithms("signature"); LOGGER.debug("+++ Availabe signatures +++"); for (String sig : signatures) {
/** * Returns the list of known algorithms */ public static Value hash_algos(Env env) { ArrayValue array = new ArrayValueImpl(); for (String name : _algorithmMap.keySet()) { array.put(env.createString(name)); } Collection<String> values = _algorithmMap.values(); for (String name : Security.getAlgorithms("MessageDigest")) { if (! values.contains(name)) array.put(env.createString(name)); } return array; }