@@ -61,9 +61,9 @@ public String getName() {
6161 }
6262
6363 @ ReactMethod
64- public void encrypt (String data , String keyBase64 , String ivBase64 , Promise promise ) {
64+ public void encrypt (String dataBase64 , String keyBase64 , String ivBase64 , Promise promise ) {
6565 try {
66- String result = encrypt (data , keyBase64 , ivBase64 );
66+ String result = encrypt (dataBase64 , keyBase64 , ivBase64 );
6767 promise .resolve (result );
6868 } catch (Exception e ) {
6969 promise .reject ("-1" , e .getMessage ());
@@ -116,8 +116,8 @@ public static String bytesToHex(byte[] bytes) {
116116
117117 final static IvParameterSpec emptyIvSpec = new IvParameterSpec (new byte [] {0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 });
118118
119- private static String encrypt (String text , String hexKey , String hexIv ) throws Exception {
120- if (text == null || text .length () == 0 ) {
119+ private static String encrypt (String textBase64 , String hexKey , String hexIv ) throws Exception {
120+ if (textBase64 == null || textBase64 .length () == 0 ) {
121121 return null ;
122122 }
123123
@@ -126,7 +126,8 @@ private static String encrypt(String text, String hexKey, String hexIv) throws E
126126
127127 Cipher cipher = Cipher .getInstance (CIPHER_ALGORITHM );
128128 cipher .init (Cipher .ENCRYPT_MODE , secretKey , hexIv == null ? emptyIvSpec : new IvParameterSpec (Hex .decode (hexIv )));
129- byte [] encrypted = cipher .doFinal (text .getBytes ("UTF-8" ));
129+ byte [] textBytes = Base64 .getEncoder ().decode (textBase64 );
130+ byte [] encrypted = cipher .doFinal (textBytes );
130131 return Base64 .encodeToString (encrypted , Base64 .NO_WRAP );
131132 }
132133
0 commit comments