Search in sources :

Example 56 with IvParameterSpec

use of javax.crypto.spec.IvParameterSpec in project android_frameworks_base by ParanoidAndroid.

the class ContainerEncryptionParamsTest method testHashCode_EncKey_Failure.

public void testHashCode_EncKey_Failure() throws Exception {
    ContainerEncryptionParams params1 = new ContainerEncryptionParams(ENC_ALGORITHM, ENC_PARAMS, ENC_KEY, MAC_ALGORITHM, null, MAC_KEY, MAC_TAG, AUTHENTICATED_START, ENCRYPTED_START, DATA_END);
    ContainerEncryptionParams params2 = new ContainerEncryptionParams(new String(ENC_ALGORITHM), new IvParameterSpec(IV_BYTES.clone()), new SecretKeySpec("BLAHBLAH".getBytes(), "RAW"), new String(MAC_ALGORITHM), null, new SecretKeySpec(MAC_KEY_BYTES.clone(), "RAW"), MAC_TAG, AUTHENTICATED_START, ENCRYPTED_START, DATA_END);
    assertFalse(params1.hashCode() == params2.hashCode());
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) IvParameterSpec(javax.crypto.spec.IvParameterSpec)

Example 57 with IvParameterSpec

use of javax.crypto.spec.IvParameterSpec in project android_frameworks_base by ParanoidAndroid.

the class ContainerEncryptionParamsTest method testHashCode_AuthenticatedStart_Failure.

public void testHashCode_AuthenticatedStart_Failure() throws Exception {
    ContainerEncryptionParams params1 = new ContainerEncryptionParams(ENC_ALGORITHM, ENC_PARAMS, ENC_KEY, MAC_ALGORITHM, null, MAC_KEY, MAC_TAG, AUTHENTICATED_START, ENCRYPTED_START, DATA_END);
    ContainerEncryptionParams params2 = new ContainerEncryptionParams(new String(ENC_ALGORITHM), new IvParameterSpec(IV_BYTES.clone()), new SecretKeySpec(ENC_KEY_BYTES.clone(), "RAW"), new String(MAC_ALGORITHM), null, new SecretKeySpec(MAC_KEY_BYTES.clone(), "RAW"), MAC_TAG, AUTHENTICATED_START - 1, ENCRYPTED_START, DATA_END);
    assertFalse(params1.hashCode() == params2.hashCode());
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) IvParameterSpec(javax.crypto.spec.IvParameterSpec)

Example 58 with IvParameterSpec

use of javax.crypto.spec.IvParameterSpec in project android_frameworks_base by ParanoidAndroid.

the class ContainerEncryptionParamsTest method testEquals_MacTag_Failure.

public void testEquals_MacTag_Failure() throws Exception {
    ContainerEncryptionParams params1 = new ContainerEncryptionParams(ENC_ALGORITHM, ENC_PARAMS, ENC_KEY, MAC_ALGORITHM, null, MAC_KEY, MAC_TAG, AUTHENTICATED_START, ENCRYPTED_START, DATA_END);
    ContainerEncryptionParams params2 = new ContainerEncryptionParams(new String(ENC_ALGORITHM), new IvParameterSpec(IV_BYTES.clone()), new SecretKeySpec(ENC_KEY_BYTES.clone(), "RAW"), new String(MAC_ALGORITHM), null, new SecretKeySpec(MAC_KEY_BYTES.clone(), "RAW"), "broken".getBytes(), AUTHENTICATED_START, ENCRYPTED_START, DATA_END);
    assertFalse(params1.equals(params2));
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) IvParameterSpec(javax.crypto.spec.IvParameterSpec)

Example 59 with IvParameterSpec

use of javax.crypto.spec.IvParameterSpec in project android_frameworks_base by ParanoidAndroid.

the class ContainerEncryptionParamsTest method testEquals_MacAlgo_Failure.

public void testEquals_MacAlgo_Failure() throws Exception {
    ContainerEncryptionParams params1 = new ContainerEncryptionParams(ENC_ALGORITHM, ENC_PARAMS, ENC_KEY, MAC_ALGORITHM, null, MAC_KEY, MAC_TAG, AUTHENTICATED_START, ENCRYPTED_START, DATA_END);
    ContainerEncryptionParams params2 = new ContainerEncryptionParams(new String(ENC_ALGORITHM), new IvParameterSpec(IV_BYTES.clone()), new SecretKeySpec(ENC_KEY_BYTES.clone(), "RAW"), "BLAHBLAH", null, new SecretKeySpec(MAC_KEY_BYTES.clone(), "RAW"), MAC_TAG, AUTHENTICATED_START, ENCRYPTED_START, DATA_END);
    assertFalse(params1.equals(params2));
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) IvParameterSpec(javax.crypto.spec.IvParameterSpec)

Example 60 with IvParameterSpec

use of javax.crypto.spec.IvParameterSpec in project android_frameworks_base by ParanoidAndroid.

the class ContainerEncryptionParamsTest method testEquals_EncKey_Failure.

public void testEquals_EncKey_Failure() throws Exception {
    ContainerEncryptionParams params1 = new ContainerEncryptionParams(ENC_ALGORITHM, ENC_PARAMS, ENC_KEY, MAC_ALGORITHM, null, MAC_KEY, MAC_TAG, AUTHENTICATED_START, ENCRYPTED_START, DATA_END);
    ContainerEncryptionParams params2 = new ContainerEncryptionParams(new String(ENC_ALGORITHM), new IvParameterSpec(IV_BYTES.clone()), new SecretKeySpec("BLAHBLAH".getBytes(), "RAW"), new String(MAC_ALGORITHM), null, new SecretKeySpec(MAC_KEY_BYTES.clone(), "RAW"), MAC_TAG, AUTHENTICATED_START, ENCRYPTED_START, DATA_END);
    assertFalse(params1.equals(params2));
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) IvParameterSpec(javax.crypto.spec.IvParameterSpec)

Aggregations

IvParameterSpec (javax.crypto.spec.IvParameterSpec)229 Cipher (javax.crypto.Cipher)150 SecretKeySpec (javax.crypto.spec.SecretKeySpec)107 SecretKey (javax.crypto.SecretKey)49 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)46 InvalidKeyException (java.security.InvalidKeyException)43 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)42 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)39 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)30 BadPaddingException (javax.crypto.BadPaddingException)28 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)25 Key (java.security.Key)21 KeyGenerator (javax.crypto.KeyGenerator)21 IOException (java.io.IOException)19 SecureRandom (java.security.SecureRandom)17 GeneralSecurityException (java.security.GeneralSecurityException)15 MyCipher (org.apache.harmony.crypto.tests.support.MyCipher)15 PBEParameterSpec (javax.crypto.spec.PBEParameterSpec)14 MessageDigest (java.security.MessageDigest)13 KeyParameter (org.bouncycastle.crypto.params.KeyParameter)13