use of java.security.spec.RSAPrivateCrtKeySpec in project j2objc by google.
the class RSAPrivateCrtKeySpecTest method testGetPrimeExponentP.
/**
* Test for <code>getPrimeExponentP()</code> method<br>
* Assertion: returns prime exponent P
*/
public final void testGetPrimeExponentP() {
RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.valueOf(5L), BigInteger.ONE, BigInteger.ONE);
assertTrue(BigInteger.valueOf(5L).equals(ks.getPrimeExponentP()));
}
use of java.security.spec.RSAPrivateCrtKeySpec in project j2objc by google.
the class RSAPrivateCrtKeySpecTest method testGetPrimeExponentQ.
/**
* Test for <code>getPrimeExponentQ()</code> method<br>
* Assertion: returns prime exponent Q
*/
public final void testGetPrimeExponentQ() {
RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.valueOf(5L), BigInteger.ONE);
assertTrue(BigInteger.valueOf(5L).equals(ks.getPrimeExponentQ()));
}
use of java.security.spec.RSAPrivateCrtKeySpec in project j2objc by google.
the class RSAPrivateCrtKeySpecTest method testGetPrimeP.
/**
* Test for <code>getPrimeP()</code> method<br>
* Assertion: returns prime P
*/
public final void testGetPrimeP() {
RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.valueOf(5L), BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE);
assertTrue(BigInteger.valueOf(5L).equals(ks.getPrimeP()));
}
use of java.security.spec.RSAPrivateCrtKeySpec in project vert.x by eclipse.
the class PrivateKeyParser method getRSAKeySpec.
/**
* Convert PKCS#1 encoded private key into RSAPrivateCrtKeySpec.
* <p/>
* <p/>The ASN.1 syntax for the private key with CRT is
* <p/>
* <pre>
* --
* -- Representation of RSA private key with information for the CRT algorithm.
* --
* RSAPrivateKey ::= SEQUENCE {
* version Version,
* modulus INTEGER, -- n
* publicExponent INTEGER, -- e
* privateExponent INTEGER, -- d
* prime1 INTEGER, -- p
* prime2 INTEGER, -- q
* exponent1 INTEGER, -- d mod (p-1)
* exponent2 INTEGER, -- d mod (q-1)
* coefficient INTEGER, -- (inverse of q) mod p
* otherPrimeInfos OtherPrimeInfos OPTIONAL
* }
* </pre>
*
* @param keyBytes PKCS#1 encoded key
* @return KeySpec
* @throws VertxException
*/
public static RSAPrivateCrtKeySpec getRSAKeySpec(byte[] keyBytes) throws VertxException {
DerParser parser = new DerParser(keyBytes);
Asn1Object sequence = parser.read();
if (sequence.getType() != DerParser.SEQUENCE) {
throw new VertxException("Invalid DER: not a sequence");
}
// Parse inside the sequence
parser = sequence.getParser();
// Skip version
parser.read();
BigInteger modulus = parser.read().getInteger();
BigInteger publicExp = parser.read().getInteger();
BigInteger privateExp = parser.read().getInteger();
BigInteger prime1 = parser.read().getInteger();
BigInteger prime2 = parser.read().getInteger();
BigInteger exp1 = parser.read().getInteger();
BigInteger exp2 = parser.read().getInteger();
BigInteger crtCoef = parser.read().getInteger();
return new RSAPrivateCrtKeySpec(modulus, publicExp, privateExp, prime1, prime2, exp1, exp2, crtCoef);
}
use of java.security.spec.RSAPrivateCrtKeySpec in project dbeaver by serge-rider.
the class PKCS1Util method loadPrivateKeyFromPKCS1.
public static PrivateKey loadPrivateKeyFromPKCS1(String privateKeyPem) throws GeneralSecurityException, IOException {
DerInputStream derReader = new DerInputStream(Base64.decode(privateKeyPem));
DerValue[] seq = derReader.getSequence(0);
if (seq.length < 9) {
throw new GeneralSecurityException("Could not parse a PKCS1 private key.");
}
// skip version seq[0];
BigInteger modulus = seq[1].getBigInteger();
BigInteger publicExp = seq[2].getBigInteger();
BigInteger privateExp = seq[3].getBigInteger();
BigInteger prime1 = seq[4].getBigInteger();
BigInteger prime2 = seq[5].getBigInteger();
BigInteger exp1 = seq[6].getBigInteger();
BigInteger exp2 = seq[7].getBigInteger();
BigInteger crtCoef = seq[8].getBigInteger();
RSAPrivateCrtKeySpec keySpec = new RSAPrivateCrtKeySpec(modulus, publicExp, privateExp, prime1, prime2, exp1, exp2, crtCoef);
KeyFactory factory = KeyFactory.getInstance("RSA");
return factory.generatePrivate(keySpec);
}
Aggregations