本文整理汇总了Java中java.security.interfaces.RSAPrivateCrtKey.getEncoded方法的典型用法代码示例。如果您正苦于以下问题:Java RSAPrivateCrtKey.getEncoded方法的具体用法?Java RSAPrivateCrtKey.getEncoded怎么用?Java RSAPrivateCrtKey.getEncoded使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.interfaces.RSAPrivateCrtKey
的用法示例。
在下文中一共展示了RSAPrivateCrtKey.getEncoded方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.security.interfaces.RSAPrivateCrtKey; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// Create an RSA Private Key from the CRT information
RSAPrivateCrtKeySpec rsaCrtSpec =
new RSAPrivateCrtKeySpec(new BigInteger(1, modulus),
new BigInteger(1, pubExpo),
new BigInteger(1, priExpo),
new BigInteger(1, primeP),
new BigInteger(1, primeQ),
new BigInteger(1, expoP),
new BigInteger(1, expoQ),
new BigInteger(1, coeff));
// Create an RSA private key from the CRT specification
KeyFactory kf = KeyFactory.getInstance("RSA", "SunRsaSign");
RSAPrivateCrtKey rsaPriKey =
(RSAPrivateCrtKey) kf.generatePrivate(rsaCrtSpec);
// test resulting key against original specification
if (!rsaPriKey.getCrtCoefficient().equals(rsaCrtSpec.getCrtCoefficient()))
throw new Exception("coefficients not equal");
if (!rsaPriKey.getPrimeExponentP().equals(rsaCrtSpec.getPrimeExponentP()))
throw new Exception("primeExponentPs not equal");
if (!rsaPriKey.getPrimeExponentQ().equals(rsaCrtSpec.getPrimeExponentQ()))
throw new Exception("primeExponentQs not equal");
if (!rsaPriKey.getPrimeP().equals(rsaCrtSpec.getPrimeP()))
throw new Exception("primePs not equal");
if (!rsaPriKey.getPrimeQ().equals(rsaCrtSpec.getPrimeQ()))
throw new Exception("primeQs not equal");
if (!rsaPriKey.getPublicExponent().equals(rsaCrtSpec.getPublicExponent()))
throw new Exception("public exponents not equal");
if (!rsaPriKey.getPrivateExponent().equals(rsaCrtSpec.getPrivateExponent()))
throw new Exception("private exponents not equal");
if (!rsaPriKey.getModulus().equals(rsaCrtSpec.getModulus()))
throw new Exception("modulus not equal");
if (!rsaPriKey.getFormat().equals("PKCS#8") &&
!rsaPriKey.getFormat().equals("PKCS8"))
throw new Exception("format not PKCS#8");
if (!rsaPriKey.getAlgorithm().equals("RSA"))
throw new Exception("algorithm not RSA");
if (rsaPriKey.getEncoded() == null)
throw new Exception("encoded key is null");
PKCS8EncodedKeySpec pkcs8Key =
new PKCS8EncodedKeySpec(rsaPriKey.getEncoded());
RSAPrivateCrtKey rsaPriKey2
= (RSAPrivateCrtKey) kf.generatePrivate(pkcs8Key);
if (!Arrays.equals(rsaPriKey.getEncoded(), rsaPriKey2.getEncoded()))
throw new Exception("encoded keys not equal");
}