Search in sources :

Example 16 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 17 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 18 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)

Example 19 with IvParameterSpec

use of javax.crypto.spec.IvParameterSpec in project Signal-Android by WhisperSystems.

the class DecryptingPartInputStream method initializeCipher.

private Cipher initializeCipher(SecretKeySpec key) throws InvalidKeyException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchPaddingException, IOException {
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    IvParameterSpec iv = readIv(cipher.getBlockSize());
    cipher.init(Cipher.DECRYPT_MODE, key, iv);
    return cipher;
}
Also used : IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher)

Example 20 with IvParameterSpec

use of javax.crypto.spec.IvParameterSpec in project remusic by aa112901.

the class AESTools method encrpty.

public static String encrpty(String paramString) {
    MessageDigest messageDigest = null;
    try {
        messageDigest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    messageDigest.update(INPUT.getBytes());
    byte[] stringBytes = messageDigest.digest();
    StringBuilder stringBuilder = new StringBuilder(stringBytes.length * 2);
    for (int i = 0; i < stringBytes.length; i++) {
        stringBuilder.append(CHARS[((stringBytes[i] & 0xF0) >>> 4)]);
        stringBuilder.append(CHARS[(stringBytes[i] & 0xF)]);
    }
    String str = stringBuilder.toString();
    SecretKeySpec localSecretKeySpec = new SecretKeySpec(str.substring(str.length() / 2).getBytes(), "AES");
    Cipher localCipher;
    try {
        localCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        localCipher.init(1, localSecretKeySpec, new IvParameterSpec(IV.getBytes()));
        return URLEncoder.encode(new String(BytesHandler.getChars(localCipher.doFinal(paramString.getBytes()))), "utf-8");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchPaddingException e) {
        e.printStackTrace();
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    } catch (InvalidAlgorithmParameterException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IllegalBlockSizeException e) {
        e.printStackTrace();
    } catch (BadPaddingException e) {
        e.printStackTrace();
    }
    return "";
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BadPaddingException(javax.crypto.BadPaddingException) InvalidKeyException(java.security.InvalidKeyException) SecretKeySpec(javax.crypto.spec.SecretKeySpec) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) MessageDigest(java.security.MessageDigest)

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