PublicKey publicKey = keyFactory.generatePublic(keySpec);
私钥创建过程与公钥类似
AlgorithmParameterGenerator对象创建过程
1、调用AlgorithmParameterGenerator.getInstance()方法:
1)在方法getInstance()内部调用Security.getImpl(algorithm, "AlgorithmParameterGenerator", (String)null);方法返回一个对象数组
2)在调用带参数的构造函数创建新的AlgorithmParameterGenerator对象返回
new AlgorithmParameterGenerator((AlgorithmParameterGeneratorSpi)objs[0], (Provider)objs[1], algorithm);
2、Initializes this parameter generator for a certain size.
public final void init(int size)
getInstance源码:
public static AlgorithmParameterGenerator getInstance(String algorithm,
String provider)
throws NoSuchAlgorithmException, NoSuchProviderException
{
if (provider == null || provider.length() == 0)
throw new IllegalArgumentException("missing provider");
Object[] objs = Security.getImpl(algorithm,
"AlgorithmParameterGenerator",
provider);
return new AlgorithmParameterGenerator
((AlgorithmParameterGeneratorSpi)objs[0], (Provider)objs[1],
algorithm);
}
AlgorithmParameters、AlgorithmParameterGenerator等类的getInstance()方法内部实现结构基本相同。
X509EncodedKeySpec用于构建公钥规范,PKCS8EncodedKeySpec用于构建私钥规范
SecretKeySpec接口是KeySpec的实现类,用于构建秘密秘钥规范
原文地址:http://blog.csdn.net/u014682413/article/details/42102033