Search in sources :

Example 16 with SecretKeySpec

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

the class ContainerEncryptionParamsTest method testEquals_AuthenticatedStart_Failure.

public void testEquals_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.equals(params2));
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) IvParameterSpec(javax.crypto.spec.IvParameterSpec)

Example 17 with SecretKeySpec

use of javax.crypto.spec.SecretKeySpec 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 18 with SecretKeySpec

use of javax.crypto.spec.SecretKeySpec 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 19 with SecretKeySpec

use of javax.crypto.spec.SecretKeySpec 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 20 with SecretKeySpec

use of javax.crypto.spec.SecretKeySpec 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)

Aggregations

SecretKeySpec (javax.crypto.spec.SecretKeySpec)432 Cipher (javax.crypto.Cipher)165 SecretKey (javax.crypto.SecretKey)128 Mac (javax.crypto.Mac)101 IvParameterSpec (javax.crypto.spec.IvParameterSpec)95 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)80 InvalidKeyException (java.security.InvalidKeyException)55 IOException (java.io.IOException)39 SecureRandom (java.security.SecureRandom)28 UnsupportedEncodingException (java.io.UnsupportedEncodingException)27 Key (java.security.Key)27 GeneralSecurityException (java.security.GeneralSecurityException)25 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)25 BadPaddingException (javax.crypto.BadPaddingException)23 MessageDigest (java.security.MessageDigest)22 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)21 Test (org.junit.Test)19 PrivateKey (java.security.PrivateKey)18 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)17 PublicKey (java.security.PublicKey)16