123
This commit is contained in:
@@ -8,13 +8,19 @@ import java.util.Base64;
|
||||
public class AES {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String jsonData ="zTmtrzE4t6jFriRIde3X+AFG9PQPSTQb5GrZcsBZySFUne3NGpRbb19LUbcKKLaRXj31TSE6nrVz3jLD7nCH+ArJzZwEgMb3hLXZPh53Xluk1Rkq/8wUMsDhAWjPRG012dhoaINUggAJwDKvKDqRgA==";
|
||||
// String jsonData = "123";
|
||||
String key = "K2AwvosrwtoAgOEP";
|
||||
String encod = encrypt(jsonData, key);
|
||||
String jsonData ="YRdHX2hqWMGguxfvSXfHzK5kuljBah5luDUo/YcmoQVKtSSAtEY2ndScZIi2dgLvjJ6noUDcIctq653wt83OCgj3P4+jgnopMps12RY1DnxHtLUd2Rnv3TCCKf+Br5+iGi9ruuq27JimqOYOjT+K8CWVESSQsoTN6knQA69s2kctSaHkmpirf4N3gJxp84BW4xi+hyayuKFe5/jva0X/Cg==";
|
||||
String key = "UCEfSKns45SWjHov";
|
||||
System.out.println(decrypt(jsonData,key));
|
||||
}
|
||||
|
||||
public static byte[] encrypt(byte[] data, String key) throws Exception {
|
||||
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
|
||||
byte[] encryptedBytes = cipher.doFinal(data);
|
||||
return Base64.getEncoder().encode(encryptedBytes);
|
||||
}
|
||||
|
||||
public static String encrypt(String data, String key) throws Exception {
|
||||
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
|
||||
|
||||
Reference in New Issue
Block a user