List of usage examples for javax.crypto SecretKey getAlgorithm
public String getAlgorithm();
From source file:us.the.mac.android.jni.helpers.EncryptedStringTest.java
@Test public void javaDecryptWithSecretKey() throws Exception { String contents = TestConstants.TEST_ENCRYPTED_RESOURCE; byte[] keyBytes = TestConstants.TEST_ENCRYPTION_KEY.getBytes(); String[] parts = contents.split(":"); byte[] decodedKeyBytes = Base64.decodeBase64(keyBytes); byte[] initVector = Base64.decodeBase64(parts[0].getBytes()); byte[] decodedValueBytes = Base64.decodeBase64(parts[1].getBytes()); SecretKey originalKey = new SecretKeySpec(decodedKeyBytes, 0, decodedKeyBytes.length, "AES"); Cipher cipher = Cipher.getInstance(originalKey.getAlgorithm() + "/CBC/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, originalKey, new IvParameterSpec(initVector)); byte[] decryptedBytes = cipher.doFinal(decodedValueBytes); assertEquals(TestConstants.TEST_DECRYPT, new String(decryptedBytes)); }
From source file:us.the.mac.android.jni.helpers.EncryptedStringTest.java
@Test public void nativeDecryptWithSecretKey() throws Exception { String contents = TestConstants.TEST_ENCRYPTED_RESOURCE; String[] parts = contents.split(":"); byte[] initVector = Base64.decodeBase64(parts[0].getBytes()); byte[] decodedValueBytes = Base64.decodeBase64(parts[1].getBytes()); SecretKey originalKey = createSecretKeySpec(); Cipher cipher = Cipher.getInstance(originalKey.getAlgorithm() + "/CBC/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, originalKey, new IvParameterSpec(initVector)); byte[] decryptedBytes = cipher.doFinal(decodedValueBytes); assertEquals(TestConstants.TEST_DECRYPT, new String(decryptedBytes)); }