@@ -215,29 +215,29 @@ private static String hmacX(String text, String key, String algorithm)
215
215
216
216
final static IvParameterSpec emptyIvSpec = new IvParameterSpec (new byte [] {0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 });
217
217
218
- private static String encrypt (String text , String hexKey , String hexIv ) throws Exception {
218
+ private static String encrypt (String text , String hexKey , String hexIv , String algorithm ) throws Exception {
219
219
if (text == null || text .length () == 0 ) {
220
220
return null ;
221
221
}
222
222
223
223
byte [] key = Hex .decode (hexKey );
224
224
SecretKey secretKey = new SecretKeySpec (key , KEY_ALGORITHM );
225
225
226
- Cipher cipher = Cipher .getInstance (CIPHER_ALGORITHM );
226
+ Cipher cipher = Cipher .getInstance (algorithm );
227
227
cipher .init (Cipher .ENCRYPT_MODE , secretKey , hexIv == null ? emptyIvSpec : new IvParameterSpec (Hex .decode (hexIv )));
228
228
byte [] encrypted = cipher .doFinal (text .getBytes ("UTF-8" ));
229
229
return Base64 .encodeToString (encrypted , Base64 .NO_WRAP );
230
230
}
231
231
232
- private static String decrypt (String ciphertext , String hexKey , String hexIv ) throws Exception {
232
+ private static String decrypt (String ciphertext , String hexKey , String hexIv , String algorithm ) throws Exception {
233
233
if (ciphertext == null || ciphertext .length () == 0 ) {
234
234
return null ;
235
235
}
236
236
237
237
byte [] key = Hex .decode (hexKey );
238
238
SecretKey secretKey = new SecretKeySpec (key , KEY_ALGORITHM );
239
239
240
- Cipher cipher = Cipher .getInstance (CIPHER_ALGORITHM );
240
+ Cipher cipher = Cipher .getInstance (algorithm );
241
241
cipher .init (Cipher .DECRYPT_MODE , secretKey , hexIv == null ? emptyIvSpec : new IvParameterSpec (Hex .decode (hexIv )));
242
242
byte [] decrypted = cipher .doFinal (Base64 .decode (ciphertext , Base64 .NO_WRAP ));
243
243
return new String (decrypted , "UTF-8" );
0 commit comments