小编典典
我没有看到任何你的代码错误,除了尝试打印任意byte[]使用new String(byte[])。尝试以下尺寸:
public static byte[] encrypt(String message) throws Exception
{
String salt = "1111111111111111";
SecretKeySpec key = new SecretKeySpec(salt.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding", "SunJCE");
cipher.init(Cipher.ENCRYPT_MODE, key);
return cipher.doFinal(message.getBytes());
}
public static void main (String[] args) throws Exception
{
String hello = Arrays.toString(encrypt("hello"));
System.out.println("hello:" + hello);
String helloWorld = Arrays.toString(encrypt("hello world"));
System.out.println("hello world:" + helloWorld);
}
哪些打印:
hello:[115, -73, -46, -121, 36, -106, -99, 100, 103, -24, -40, -38, 113, -8, 40, -57]
hello world:[5, 88, -31, 115, 4, 48, -75, 44, 83, 21, 105, -67, 78, -53, -13, -28]
我想我们都可以同意那是两个不同的字节数组。
2020-09-21