Search in sources :

Example 21 with RSAPrivateCrtKeySpec

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);
}
Also used : RSAPrivateCrtKeySpec(java.security.spec.RSAPrivateCrtKeySpec) BigInteger(java.math.BigInteger) IOException(java.io.IOException)

Example 22 with RSAPrivateCrtKeySpec

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);
}
Also used : RSAPrivateCrtKeySpec(java.security.spec.RSAPrivateCrtKeySpec) RSAPrivateKeySpec(java.security.spec.RSAPrivateKeySpec) KeySpec(java.security.spec.KeySpec) RSAPrivateCrtKeySpec(java.security.spec.RSAPrivateCrtKeySpec)

Example 23 with 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()));
}
Also used : RSAPrivateCrtKeySpec(java.security.spec.RSAPrivateCrtKeySpec)

Example 24 with RSAPrivateCrtKeySpec

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);
}
Also used : RSAPrivateCrtKeySpec(java.security.spec.RSAPrivateCrtKeySpec) RSAPrivateKeySpec(java.security.spec.RSAPrivateKeySpec) RSAPrivateKeySpec(java.security.spec.RSAPrivateKeySpec) KeySpec(java.security.spec.KeySpec) RSAPrivateCrtKeySpec(java.security.spec.RSAPrivateCrtKeySpec)

Example 25 with RSAPrivateCrtKeySpec

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()));
}
Also used : RSAPrivateCrtKeySpec(java.security.spec.RSAPrivateCrtKeySpec)

Aggregations

RSAPrivateCrtKeySpec (java.security.spec.RSAPrivateCrtKeySpec)48 KeyFactory (java.security.KeyFactory)16 BigInteger (java.math.BigInteger)14 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)12 PrivateKey (java.security.PrivateKey)11 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)10 RSAPrivateKeySpec (java.security.spec.RSAPrivateKeySpec)9 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)9 RSAPrivateCrtKey (java.security.interfaces.RSAPrivateCrtKey)8 PublicKey (java.security.PublicKey)7 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)7 KeySpec (java.security.spec.KeySpec)6 IOException (java.io.IOException)5 KeyPair (java.security.KeyPair)5 RSAPublicKey (java.security.interfaces.RSAPublicKey)5 GeneralSecurityException (java.security.GeneralSecurityException)4 InvalidKeyException (java.security.InvalidKeyException)4 Signature (java.security.Signature)4 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)4 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)4