use of java.security.spec.RSAPrivateCrtKeySpec in project bigbluebutton by bigbluebutton.
the class PKCS1EncodedKeySpec method decode.
/**
* Decode PKCS#1 encoded private key into RSAPrivateCrtKeySpec.
*
* <p/>The ASN.1 syntax for the private key with CRT is
*
* <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
* @throws IOException
*/
private void decode(byte[] keyBytes) throws IOException {
DerParser parser = new DerParser(keyBytes);
Asn1Object sequence = parser.read();
if (sequence.getType() != DerParser.SEQUENCE)
//$NON-NLS-1$
throw new IOException("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();
keySpec = new RSAPrivateCrtKeySpec(modulus, publicExp, privateExp, prime1, prime2, exp1, exp2, crtCoef);
}
use of java.security.spec.RSAPrivateCrtKeySpec in project robovm by robovm.
the class RSAPrivateCrtKeySpecTest method testRSAPrivateCrtKeySpec01.
/**
* Test #1 for <code>RSAPrivateCrtKeySpec</code> constructor
* Assertion: Constructs <code>RSAPrivateCrtKeySpec</code>
* object using valid parameters
*/
public final void testRSAPrivateCrtKeySpec01() {
KeySpec ks = new RSAPrivateCrtKeySpec(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE);
assertTrue(ks instanceof RSAPrivateCrtKeySpec);
}
use of java.security.spec.RSAPrivateCrtKeySpec in project robovm by robovm.
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 robovm by robovm.
the class RSAPrivateCrtKeySpecTest method testRSAPrivateCrtKeySpec02.
/**
* Test #2 for <code>RSAPrivateCrtKeySpec</code> constructor
* Assertion: Constructs <code>RSAPrivateCrtKeySpec</code>
* object using valid parameters
*/
public final void testRSAPrivateCrtKeySpec02() {
KeySpec ks = new RSAPrivateCrtKeySpec(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE);
assertTrue(ks instanceof RSAPrivateKeySpec);
}
use of java.security.spec.RSAPrivateCrtKeySpec in project robovm by robovm.
the class RSAPrivateCrtKeySpecTest method testGetModulus.
//
// Tests for inherited methods
//
/**
* Test for <code>getModulus()</code> method<br>
* Assertion: returns modulus
*/
public final void testGetModulus() {
RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec(BigInteger.valueOf(5L), BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE);
assertTrue(BigInteger.valueOf(5L).equals(ks.getModulus()));
}
Aggregations