一、Provider
提供DSA、RSA、MD5等算法
密钥的生成、转换、管理
二、Secruity
主要是管理Provider
public static int addProvider(Provider provider)
public static synchronized void removeProvider(String name)
public static Provider[] getProviders()
public static Provider getProvider(String name)
等等
for (Provider p: Security.getProviders()){
System.out.println(p);
for (Map.Entry<Object, Object> entry: p.entrySet()){
System.out.println("\t" + entry.getKey());
}
}
I/System.out: AndroidNSSP version 1.0
Provider.id info
Provider.id className
Provider.id version
Alg.Alias.TrustManagerFactory.X509
Provider.id name
TrustManagerFactory.PKIX
I/System.out: AndroidOpenSSL version 1.0
Alg.Alias.Cipher.RSA/None/OAEPWithSHA-1AndMGF1Padding
Cipher.AES_256/ECB/PKCS5Padding
Alg.Alias.Cipher.RSA/None/OAEPWithSHA-384AndMGF1Padding
Alg.Alias.Cipher.2.16.840.1.101.3.4.1.26
Cipher.RSA/ECB/NoPadding
Alg.Alias.Cipher.ChaCha20-Poly1305
Signature.SHA224withRSA SupportedKeyClasses
Alg.Alias.Signature.2.16.840.1.101.3.4.2.3with1.2.840.10045.2.1
Cipher.AES/ECB/PKCS5Padding
Alg.Alias.Mac.HMAC/SHA224
Cipher.AES_128/ECB/NoPadding
Alg.Alias.Mac.HMAC-SHA384
Cipher.AES/CBC/NoPadding
Provider.id name
KeyGenerator.AES
KeyFactory.EC
Alg.Alias.KeyGenerator.2.16.840.1.101.3.4.2.1
Signature.SHA256withRSA/PSS SupportedKeyClasses
Alg.Alias.Mac.1.3.6.1.5.5.8.1.2
Alg.Alias.Mac.1.3.6.1.5.5.8.1.1
Signature.SHA384withRSA SupportedKeyClasses
Alg.Alias.KeyGenerator.HMAC/SHA1
Alg.Alias.Signature.OID.1.2.840.10045.4.3.4
Alg.Alias.Signature.SHA-1/RSA
Alg.Alias.Signature.OID.1.2.840.10045.4.3.3
Alg.Alias.Signature.OID.1.2.840.10045.4.3.2
Alg.Alias.Signature.OID.1.2.840.10045.4.3.1
Alg.Alias.MessageDigest.SHA384
等等……
2、%JDK_HOME%\jre\lib\security\java.security
以下方法可以配置java.security文件:
public static String getProperty(String key)
public static void setProperty(String key, String datum)
三、MessageDigest
MessageDigest类实现了摘要算法,支持MD2、MD5、SHA-1(SHA)、SHA-256、SHA-384、SHA512,算法名不区分大小写。
MessageDigest类的实例:
public static MessageDigest getInstance(String algorithm)
throws NoSuchAlgorithmException;
public static MessageDigest getInstance(String algorithm,Provider provider)
throws NoSuchAlgorithmException
public static MessageDigest getInstance(String algorithm, String provider)
throws NoSuchAlgorithmException, NoSuchProviderException;