java.security.Security.getAlgorithms()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(274)

本文整理了Java中java.security.Security.getAlgorithms()方法的一些代码示例,展示了Security.getAlgorithms()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Security.getAlgorithms()方法的具体详情如下:
包路径:java.security.Security
类名称:Security
方法名:getAlgorithms

Security.getAlgorithms介绍

[英]Returns a Set of all registered algorithms for the specified cryptographic service. "Signature", "Cipher" and "KeyStore" are examples for such kind of services.
[中]返回指定加密服务的所有已注册算法的集合。“签名”、“密码”和“密钥库”就是此类服务的例子。

代码示例

代码示例来源:origin: apache/metron

public static final Set<String> supportedHashes() {
 return new HashSet<>(Security.getAlgorithms("MessageDigest"));
}

代码示例来源:origin: apache/metron

@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);
  }
 });
}

代码示例来源:origin: apache/metron

@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);
  }
 });
}

代码示例来源:origin: org.bitbucket.b_c/jose4j

static String choosePssAlgorithmName(String legacyName)
  {
    for (String sigAlg : Security.getAlgorithms("Signature"))
    {
      if (RSASSA_PSS.equalsIgnoreCase(sigAlg))
      {
        return sigAlg;
      }
    }

    return legacyName;
  }
}

代码示例来源:origin: org.bitbucket.b_c/jose4j

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;
  }
}

代码示例来源:origin: org.bitbucket.b_c/jose4j

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);
  }
}

代码示例来源:origin: net.java.dev.jets3t/jets3t

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()]);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jets3t

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()]);
}

代码示例来源:origin: stackoverflow.com

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());
}

代码示例来源:origin: org.apache.activemq/activemq-all

/**
 * <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));
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jasypt

/**
 * <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));
}

代码示例来源:origin: org.jasypt/jasypt

/**
 * <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));
}

代码示例来源:origin: org.jasypt/jasypt

/**
 * <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);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jasypt

/**
 * <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);
}

代码示例来源:origin: net.java.dev.jets3t/jets3t

/**
 * 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()]);
}

代码示例来源:origin: org.apache.activemq/activemq-all

/**
 * <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);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jets3t

/**
 * 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()]);
}

代码示例来源:origin: org.nuxeo.common/nuxeo-common

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);

代码示例来源:origin: eidottermihi/rpicheck

LOGGER.debug("Provider: {} - {}", prov.getName(), prov.getInfo());
final Set<String> signatures = Security.getAlgorithms("signature");
LOGGER.debug("+++ Availabe signatures +++");
for (String sig : signatures) {

代码示例来源:origin: org.vx68k.quercus/quercus

/**
 * 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;
}

相关文章