我已阅读有关此错误的信息,但似乎无法正常工作。
AES解密的功能是:
public static byte[] decrypted_Data(byte[] crypt) throws Exception {
String seed = "SuperSecretPassword";
KeyGenerator keygen = KeyGenerator.getInstance("AES");
SecureRandom secrand = SecureRandom.getInstance("SHA1PRNG");
secrand.setSeed(seed.getBytes());
keygen.init(128, secrand);
SecretKey seckey = keygen.generateKey();
byte[] rawKey = seckey.getEncoded();
SecretKeySpec skeySpec = new SecretKeySpec(rawKey, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] decrypted = cipher.doFinal(crypt);
return decrypted;
}
加密的功能是一样的,除了
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
我在 Android 上调用这些函数如下:
BufferedInputStream bis = new BufferedInputStream(photoStream);
byte[] mybytearray = new byte[photoStream.available()];
mybytearray = encrypted_Data(mybytearray);
在服务器上如下:
byte[] mybytearray = new byte[10000000];
mybytearray_1 = decrypted_Data(mybytearray_1);
这是我第一次使用这些加密功能,我在接收时做错了什么:
javax.crypto.BadPaddingException: Given final block not properly padded