Search in sources :

Example 31 with EncodedKeySpec

use of java.security.spec.EncodedKeySpec in project j2objc by google.

the class EncodedKeySpecTest method testGetEncoded.

/**
 * Tests that <code>getEncoded()</code> method returns valid byte array
 */
public final void testGetEncoded() {
    byte[] encodedKey = new byte[] { (byte) 1, (byte) 2, (byte) 3, (byte) 4 };
    EncodedKeySpec meks = new MyEncodedKeySpec(encodedKey);
    /* Get encoded key */
    byte[] ek = meks.getEncoded();
    /* Check returned array */
    boolean result = true;
    for (int i = 0; i < encodedKey.length; i++) {
        if (encodedKey[i] != ek[i]) {
            /* indicate failure */
            result = false;
        }
    }
    /* passed */
    assertTrue(result);
}
Also used : MyEncodedKeySpec(org.apache.harmony.security.tests.support.spec.MyEncodedKeySpec) EncodedKeySpec(java.security.spec.EncodedKeySpec) MyEncodedKeySpec(org.apache.harmony.security.tests.support.spec.MyEncodedKeySpec)

Example 32 with EncodedKeySpec

use of java.security.spec.EncodedKeySpec in project j2objc by google.

the class PKCS8EncodedKeySpecTest method testPKCS8EncodedKeySpec.

// 
// Tests
// 
/**
 * Test for <code>PKCS8EncodedKeySpec</code> constructor<br>
 * Assertion: constructs new <code>PKCS8EncodedKeySpec</code>
 * object using valid parameter
 */
public final void testPKCS8EncodedKeySpec() {
    byte[] encodedKey = new byte[] { (byte) 1, (byte) 2, (byte) 3, (byte) 4 };
    EncodedKeySpec eks = new PKCS8EncodedKeySpec(encodedKey);
    assertTrue(eks instanceof PKCS8EncodedKeySpec);
    try {
        eks = new PKCS8EncodedKeySpec(null);
        fail("expected NullPointerException");
    } catch (NullPointerException e) {
    // ok
    }
}
Also used : PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) EncodedKeySpec(java.security.spec.EncodedKeySpec) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec)

Example 33 with EncodedKeySpec

use of java.security.spec.EncodedKeySpec in project j2objc by google.

the class X509EncodedKeySpecTest method testX509EncodedKeySpec.

// 
// Test cases
// 
/**
 * Test for <code>X509EncodedKeySpec</code> constructor<br>
 * Assertion: constructs new <code>X509EncodedKeySpec</code>
 * object using valid parameter
 */
public final void testX509EncodedKeySpec() {
    byte[] encodedKey = new byte[] { (byte) 1, (byte) 2, (byte) 3, (byte) 4 };
    EncodedKeySpec eks = new X509EncodedKeySpec(encodedKey);
    assertTrue(eks instanceof X509EncodedKeySpec);
    try {
        eks = new X509EncodedKeySpec(null);
        fail("expected NullPointerException");
    } catch (NullPointerException e) {
    // ok
    }
}
Also used : X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec) EncodedKeySpec(java.security.spec.EncodedKeySpec) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec)

Example 34 with EncodedKeySpec

use of java.security.spec.EncodedKeySpec in project gocd by gocd.

the class EncryptionHelper method getRSAPublicKeyFrom.

private static PublicKey getRSAPublicKeyFrom(String content) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
    PemReader reader = new PemReader(new StringReader(content));
    EncodedKeySpec spec = new X509EncodedKeySpec(reader.readPemObject().getContent());
    return KeyFactory.getInstance("RSA").generatePublic(spec);
}
Also used : PemReader(org.bouncycastle.util.io.pem.PemReader) StringReader(java.io.StringReader) X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec) EncodedKeySpec(java.security.spec.EncodedKeySpec) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec)

Aggregations

EncodedKeySpec (java.security.spec.EncodedKeySpec)34 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)21 KeyFactory (java.security.KeyFactory)19 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)16 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)15 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)15 MyEncodedKeySpec (org.apache.harmony.security.tests.support.spec.MyEncodedKeySpec)8 PublicKey (java.security.PublicKey)3 RSAPublicKey (java.security.interfaces.RSAPublicKey)3 SecretKeyFactory (javax.crypto.SecretKeyFactory)3 TypedArray (android.content.res.TypedArray)2 IOException (java.io.IOException)2 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 PKCS1EncodedKeySpec (net.oauth.signature.pem.PKCS1EncodedKeySpec)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 InvalidKeyException (java.security.InvalidKeyException)1 KeyPair (java.security.KeyPair)1