|
|
@@ -8,7 +8,7 @@ import org.apache.commons.codec.binary.Base64;
|
|
|
|
|
|
public class AesUtils {
|
|
|
|
|
|
- public static String encrypt(String content, String key) {
|
|
|
+ public static String encrypt(String content, String key) throws Exception {
|
|
|
try {
|
|
|
String data = content;
|
|
|
String iv = key;
|
|
|
@@ -30,7 +30,7 @@ public class AesUtils {
|
|
|
|
|
|
cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec);
|
|
|
byte[] encrypted = cipher.doFinal(plaintext);
|
|
|
- System.out.println(ArrayUtils.toString(encrypted));
|
|
|
+
|
|
|
return Base64.encodeBase64String(encrypted);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
@@ -39,13 +39,13 @@ public class AesUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static String decrypt(String content, String key) {
|
|
|
+ public static String decrypt(String content, String key) throws Exception {
|
|
|
try {
|
|
|
String data = content;
|
|
|
String iv = key;
|
|
|
|
|
|
byte[] decoded = Base64.decodeBase64(data);
|
|
|
- System.out.println(ArrayUtils.toString(decoded));
|
|
|
+
|
|
|
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
|
|
|
SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
|
|
|
IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
|
|
|
@@ -68,8 +68,6 @@ public class AesUtils {
|
|
|
System.out.println(encrypted);
|
|
|
System.out.println(encrypted.length());
|
|
|
System.out.println(AesUtils.decrypt(encrypted, pwd));
|
|
|
- System.out.println("provider= " + javax.crypto.Cipher.getInstance("AES/CBC/NoPadding").getProvider());
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|