I have read about this error but can't seem to get anything working.
The function of AES decrypt is:
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;
}
The function of encrypt is just the same except for
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
I am calling these functions as follows on Android:
BufferedInputStream bis = new BufferedInputStream(photoStream);
byte[] mybytearray = new byte[photoStream.available()];
mybytearray = encrypted_Data(mybytearray);
And on the server as follows:
byte[] mybytearray = new byte[10000000];
mybytearray_1 = decrypted_Data(mybytearray_1);
This is the first time i use these encryption functions, what am I doing wrong as I am receiving:
javax.crypto.BadPaddingException: Given final block not properly padded