Java加密类型和算法名称(3)

通过观察,我们发现算法的类型,基本都对应java的一个类。算法类基本在jce.jar和rt.jar中。从这个结果中我们基本就能自己找算法了,比如要用MD5,在上面列表中发现类型是MessageDigest,则

MessageDigest md5 = MessageDigest.getInstance("MD5");

再仔细查看java.security.Provider类源码,发现此类在初始时就已经将这些算法类型初始化了,

static { addEngine("AlgorithmParameterGenerator", false, null); addEngine("AlgorithmParameters", false, null); addEngine("KeyFactory", false, null); addEngine("KeyPairGenerator", false, null); addEngine("KeyStore", false, null); addEngine("MessageDigest", false, null); addEngine("SecureRandom", false, null); addEngine("Signature", true, null); addEngine("CertificateFactory", false, null); addEngine("CertPathBuilder", false, null); addEngine("CertPathValidator", false, null); addEngine("CertStore", false, "java.security.cert.CertStoreParameters"); addEngine("Cipher", true, null); addEngine("ExemptionMechanism", false, null); addEngine("Mac", true, null); addEngine("KeyAgreement", true, null); addEngine("KeyGenerator", false, null); addEngine("SecretKeyFactory", false, null); addEngine("KeyManagerFactory", false, null); addEngine("SSLContext", false, null); addEngine("TrustManagerFactory", false, null); addEngine("GssApiMechanism", false, null); addEngine("SaslClientFactory", false, null); addEngine("SaslServerFactory", false, null); addEngine("Policy", false, "java.security.Policy$Parameters"); addEngine("Configuration", false, "javax.security.auth.login.Configuration$Parameters"); addEngine("XMLSignatureFactory", false, null); addEngine("KeyInfoFactory", false, null); addEngine("TransformService", false, null); addEngine("TerminalFactory", false, "java.lang.Object"); }

//还对大小写做了容错处理
  private static void addEngine(String paramString1, boolean paramBoolean, String paramString2)
  {
    EngineDescription localEngineDescription = new EngineDescription(paramString1, paramBoolean, paramString2);
    knownEngines.put(paramString1.toLowerCase(Locale.ENGLISH), localEngineDescription);
    knownEngines.put(paramString1, localEngineDescription);
  }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/fe2971efbf5c69747ddc0e30c73c298c.html