Search in sources :

Example 56 with KeySpec

use of java.security.spec.KeySpec 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 57 with KeySpec

use of java.security.spec.KeySpec in project robovm by robovm.

the class RSAPrivateKeySpecTest method testRSAPrivateKeySpec.

/**
     * Test for <code>RSAPrivateKeySpec(BigInteger,BigInteger)</code> ctor
     * Assertion: constructs <code>RSAPrivateKeySpec</code>
     * object using valid parameters
     */
public final void testRSAPrivateKeySpec() {
    KeySpec ks = new RSAPrivateKeySpec(BigInteger.valueOf(1234567890L), BigInteger.valueOf(3L));
    assertTrue(ks instanceof RSAPrivateKeySpec);
}
Also used : RSAPrivateKeySpec(java.security.spec.RSAPrivateKeySpec) RSAPrivateKeySpec(java.security.spec.RSAPrivateKeySpec) KeySpec(java.security.spec.KeySpec)

Example 58 with KeySpec

use of java.security.spec.KeySpec in project robovm by robovm.

the class RSAPublicKeySpecTest method testRSAPublicKeySpec01.

/**
     * Test #1 for <code>RSAPublicKeySpec</code> constructor
     * Assertion: Constructs <code>RSAPublicKeySpec</code>
     * object using valid parameters
     */
public final void testRSAPublicKeySpec01() {
    KeySpec ks = new RSAPublicKeySpec(BigInteger.valueOf(1234567890L), BigInteger.valueOf(3L));
    assertTrue(ks instanceof RSAPublicKeySpec);
}
Also used : KeySpec(java.security.spec.KeySpec) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec)

Example 59 with KeySpec

use of java.security.spec.KeySpec in project platform_frameworks_base by android.

the class BackupManagerService method buildCharArrayKey.

private SecretKey buildCharArrayKey(String algorithm, char[] pwArray, byte[] salt, int rounds) {
    try {
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(algorithm);
        KeySpec ks = new PBEKeySpec(pwArray, salt, rounds, PBKDF2_KEY_SIZE);
        return keyFactory.generateSecret(ks);
    } catch (InvalidKeySpecException e) {
        Slog.e(TAG, "Invalid key spec for PBKDF2!");
    } catch (NoSuchAlgorithmException e) {
        Slog.e(TAG, "PBKDF2 unavailable!");
    }
    return null;
}
Also used : PBEKeySpec(javax.crypto.spec.PBEKeySpec) SecretKeySpec(javax.crypto.spec.SecretKeySpec) KeySpec(java.security.spec.KeySpec) PBEKeySpec(javax.crypto.spec.PBEKeySpec) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SecretKeyFactory(javax.crypto.SecretKeyFactory)

Example 60 with KeySpec

use of java.security.spec.KeySpec in project XobotOS by xamarin.

the class JCESecretKeyFactory method engineGetKeySpec.

protected KeySpec engineGetKeySpec(SecretKey key, Class keySpec) throws InvalidKeySpecException {
    if (keySpec == null) {
        throw new InvalidKeySpecException("keySpec parameter is null");
    }
    if (key == null) {
        throw new InvalidKeySpecException("key parameter is null");
    }
    if (SecretKeySpec.class.isAssignableFrom(keySpec)) {
        return new SecretKeySpec(key.getEncoded(), algName);
    }
    try {
        Class[] parameters = { byte[].class };
        Constructor c = keySpec.getConstructor(parameters);
        Object[] p = new Object[1];
        p[0] = key.getEncoded();
        return (KeySpec) c.newInstance(p);
    } catch (Exception e) {
        throw new InvalidKeySpecException(e.toString());
    }
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) Constructor(java.lang.reflect.Constructor) DESKeySpec(javax.crypto.spec.DESKeySpec) SecretKeySpec(javax.crypto.spec.SecretKeySpec) KeySpec(java.security.spec.KeySpec) PBEKeySpec(javax.crypto.spec.PBEKeySpec) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) InvalidKeyException(java.security.InvalidKeyException)

Aggregations

KeySpec (java.security.spec.KeySpec)79 PBEKeySpec (javax.crypto.spec.PBEKeySpec)29 SecretKeyFactory (javax.crypto.SecretKeyFactory)27 KeyFactory (java.security.KeyFactory)21 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)21 SecretKeySpec (javax.crypto.spec.SecretKeySpec)21 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)20 SecretKey (javax.crypto.SecretKey)19 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)15 RSAPrivateKeySpec (java.security.spec.RSAPrivateKeySpec)12 PrivateKey (java.security.PrivateKey)11 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)11 InvalidKeyException (java.security.InvalidKeyException)9 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)9 DESKeySpec (javax.crypto.spec.DESKeySpec)9 IOException (java.io.IOException)8 BigInteger (java.math.BigInteger)7 NoSuchProviderException (java.security.NoSuchProviderException)7 PublicKey (java.security.PublicKey)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6