本文整理匯總了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");
}