Skip to content

Commit

Permalink
Merge branch 'release/v3.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
tectiv3 committed Sep 13, 2023
2 parents 9329512 + dbf70d1 commit 7f57f04
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions android/src/main/java/com/tectiv3/aes/RCTAes.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,29 +215,29 @@ private static String hmacX(String text, String key, String algorithm)

final static IvParameterSpec emptyIvSpec = new IvParameterSpec(new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00});

private static String encrypt(String text, String hexKey, String hexIv) throws Exception {
private static String encrypt(String text, String hexKey, String hexIv, String algorithm) throws Exception {
if (text == null || text.length() == 0) {
return null;
}

byte[] key = Hex.decode(hexKey);
SecretKey secretKey = new SecretKeySpec(key, KEY_ALGORITHM);

Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.ENCRYPT_MODE, secretKey, hexIv == null ? emptyIvSpec : new IvParameterSpec(Hex.decode(hexIv)));
byte[] encrypted = cipher.doFinal(text.getBytes("UTF-8"));
return Base64.encodeToString(encrypted, Base64.NO_WRAP);
}

private static String decrypt(String ciphertext, String hexKey, String hexIv) throws Exception {
private static String decrypt(String ciphertext, String hexKey, String hexIv, String algorithm) throws Exception {
if(ciphertext == null || ciphertext.length() == 0) {
return null;
}

byte[] key = Hex.decode(hexKey);
SecretKey secretKey = new SecretKeySpec(key, KEY_ALGORITHM);

Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.DECRYPT_MODE, secretKey, hexIv == null ? emptyIvSpec : new IvParameterSpec(Hex.decode(hexIv)));
byte[] decrypted = cipher.doFinal(Base64.decode(ciphertext, Base64.NO_WRAP));
return new String(decrypted, "UTF-8");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-aes-crypto",
"version": "3.0.0",
"version": "3.0.1",
"description": "AES crypto native module for react-native",
"main": "index.js",
"types": "index.d.ts",
Expand Down

0 comments on commit 7f57f04

Please sign in to comment.