Search in sources :

Example 11 with IvParameterSpec

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

the class ContainerEncryptionParamsTest method testEquals_Success.

public void testEquals_Success() 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, ENCRYPTED_START, DATA_END);
    assertEquals(params1, params2);
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) IvParameterSpec(javax.crypto.spec.IvParameterSpec)

Example 12 with IvParameterSpec

use of javax.crypto.spec.IvParameterSpec 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 13 with IvParameterSpec

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

the class ContainerEncryptionParamsTest method testParcel.

public void testParcel() throws Exception {
    ContainerEncryptionParams expected = new ContainerEncryptionParams(ENC_ALGORITHM, ENC_PARAMS, ENC_KEY, MAC_ALGORITHM, null, MAC_KEY, MAC_TAG, AUTHENTICATED_START, ENCRYPTED_START, DATA_END);
    Parcel parcel = Parcel.obtain();
    expected.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    ContainerEncryptionParams actual = ContainerEncryptionParams.CREATOR.createFromParcel(parcel);
    assertEquals(ENC_ALGORITHM, actual.getEncryptionAlgorithm());
    if (!(actual.getEncryptionSpec() instanceof IvParameterSpec)) {
        fail("encryption parameters should be IvParameterSpec");
    } else {
        IvParameterSpec actualParams = (IvParameterSpec) actual.getEncryptionSpec();
        assertTrue(Arrays.equals(IV_BYTES, actualParams.getIV()));
    }
    assertEquals(ENC_KEY, actual.getEncryptionKey());
    assertEquals(MAC_ALGORITHM, actual.getMacAlgorithm());
    assertNull(actual.getMacSpec());
    assertEquals(MAC_KEY, actual.getMacKey());
    assertTrue(Arrays.equals(MAC_TAG, actual.getMacTag()));
    assertEquals(AUTHENTICATED_START, actual.getAuthenticatedDataStart());
    assertEquals(ENCRYPTED_START, actual.getEncryptedDataStart());
    assertEquals(DATA_END, actual.getDataEnd());
}
Also used : Parcel(android.os.Parcel) IvParameterSpec(javax.crypto.spec.IvParameterSpec)

Example 14 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 15 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)

Aggregations

IvParameterSpec (javax.crypto.spec.IvParameterSpec)202 Cipher (javax.crypto.Cipher)130 SecretKeySpec (javax.crypto.spec.SecretKeySpec)96 SecretKey (javax.crypto.SecretKey)45 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)44 InvalidKeyException (java.security.InvalidKeyException)40 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)37 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)36 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)29 BadPaddingException (javax.crypto.BadPaddingException)27 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)23 KeyGenerator (javax.crypto.KeyGenerator)19 Key (java.security.Key)18 SecureRandom (java.security.SecureRandom)17 IOException (java.io.IOException)15 MyCipher (org.apache.harmony.crypto.tests.support.MyCipher)15 GeneralSecurityException (java.security.GeneralSecurityException)13 PBEParameterSpec (javax.crypto.spec.PBEParameterSpec)13 KeyParameter (org.bouncycastle.crypto.params.KeyParameter)13 UnsupportedEncodingException (java.io.UnsupportedEncodingException)11