Java Code Examples for java.security.Security#getAlgorithms()

The following examples show how to use java.security.Security#getAlgorithms() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SysInfo.java    From FxDock with Apache License 2.0 6 votes vote down vote up
protected void listSecurityAlgorithms(String name)
{
	print(name);

	try
	{
		CList<String> names = new CList<>(Security.getAlgorithms(name));
		CSorter.sort(names);
		
		for(String s: names)
		{
			print(2, s);
		}
	}
	catch(Exception e)
	{
		print(CKit.stackTrace(e));
	}
}
 
Example 2
Source File: HashFunctionsTest.java    From metron with Apache License 2.0 6 votes vote down vote up
@Test
public void allAlgorithmsForMessageDigestShouldBeAbleToHash() {
  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);
    }
  });
}
 
Example 3
Source File: HashFunctionsTest.java    From metron with Apache License 2.0 6 votes vote down vote up
@Test
public void allAlgorithmsForMessageDigestShouldBeAbleToHashDirectStellarCall() {
  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);
    }
  });
}
 
Example 4
Source File: RaspiQuery.java    From rpicheck with MIT License 6 votes vote down vote up
/**
 * Initialize a new RaspiQuery.
 *
 * @param host hostname or ip adress of a running raspberry pi
 * @param user username for ssh login
 * @param port ssh port to use (if null, default will be used)
 */
public RaspiQuery(final String host, final String user, final Integer port) {
    final Provider[] providers = Security.getProviders();
    LOGGER.debug("+++ Registered JCE providers +++");
    for (Provider prov : providers) {
        LOGGER.debug("Provider: {} - {}", prov.getName(), prov.getInfo());
    }
    final Set<String> signatures = Security.getAlgorithms("signature");
    LOGGER.debug("+++ Availabe signatures +++");
    for (String sig : signatures) {
        LOGGER.debug("Signature: {}", sig);
    }
    if (Strings.isNullOrEmpty(host)) {
        throw new IllegalArgumentException("hostname should not be blank.");
    } else if (Strings.isNullOrEmpty(user)) {
        throw new IllegalArgumentException("username should not be blank.");
    } else {
        LOGGER.info("Initialiazed new RaspiQuery for host {} on port {}", host, port);
        this.hostname = host;
        this.username = user;
        if (port != null) {
            this.port = port;
        }
    }
}
 
Example 5
Source File: AlgorithmRegistry.java    From jasypt with Apache License 2.0 5 votes vote down vote up
/**
 * <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);
}
 
Example 6
Source File: APIImportConfigAdapter.java    From apimanager-swagger-promote with Apache License 2.0 5 votes vote down vote up
private String[] extractKeystoreTypeFromCertFile(String certFileName) throws AppException {
	if(!certFileName.contains(":")) return new String[]{certFileName, null};
	int pos = certFileName.lastIndexOf(":");
	if(pos<3) return new String[]{certFileName, null}; // This occurs for the following format: c:/path/to/my/store
	String type = certFileName.substring(pos+1);
	if(!Security.getAlgorithms("KeyStore").contains(type)) {
		ErrorState.getInstance().setError("Unknown keystore type: '"+type+"'. Supported: " + Security.getAlgorithms("KeyStore"), ErrorCode.WRONG_KEYSTORE_PASSWORD);
		throw new AppException("Unknown keystore type: '"+type+"'. Supported: " + Security.getAlgorithms("KeyStore"), ErrorCode.WRONG_KEYSTORE_PASSWORD);
	}
	certFileName = certFileName.substring(0, pos);
	return new String[]{certFileName, type};
}
 
Example 7
Source File: AlgorithmAvailability.java    From Jose4j with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: KeyPairUtil.java    From Jose4j with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source File: HtmlHashPasswordReport.java    From javamelody with Apache License 2.0 4 votes vote down vote up
private SortedSet<String> getSortedAlgorithms() {
	return new TreeSet<String>(Security.getAlgorithms("MessageDigest"));
}
 
Example 10
Source File: DefaultHasher.java    From metron with Apache License 2.0 4 votes vote down vote up
public static final Set<String> supportedHashes() {
  return new HashSet<>(Security.getAlgorithms("MessageDigest"));
}
 
Example 11
Source File: AlgorithmRegistry.java    From jasypt with Apache License 2.0 2 votes vote down vote up
/**
 * <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));
}