Search in sources :

Example 96 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 97 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 98 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 99 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 100 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)171 PBEKeySpec (javax.crypto.spec.PBEKeySpec)71 SecretKeyFactory (javax.crypto.SecretKeyFactory)65 KeyFactory (java.security.KeyFactory)61 SecretKeySpec (javax.crypto.spec.SecretKeySpec)50 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)41 BigInteger (java.math.BigInteger)40 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)40 SecretKey (javax.crypto.SecretKey)39 DSAPublicKeySpec (java.security.spec.DSAPublicKeySpec)38 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)37 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)34 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)29 PublicKey (java.security.PublicKey)27 ECPublicKeySpec (java.security.spec.ECPublicKeySpec)24 RSAPrivateKeySpec (java.security.spec.RSAPrivateKeySpec)21 PrivateKey (java.security.PrivateKey)19 IOException (java.io.IOException)18 Cipher (javax.crypto.Cipher)16 InvalidKeyException (java.security.InvalidKeyException)15