badpaddingexception

RSA BadPaddingException in Java - encrypt in Android decrypt in JRE

妖精的绣舞 提交于 2019-12-03 04:00:36
i found some other questions but i did not find a explaination what causes this. I wrote a function in Java to encrypt data, store it into a file and decrypt it loading the file again. As it is a asymetric encryption, i have a public and a private key that is directly stored in the code for testing purpose. The problem seem to be a difference in the encryption itselfs as the function work on android as well as on a windows machine with java RE 7 installed. But it is not possible to encrypt the data from the Android on the JRE7 system using the same key and funktion with the result "bad padding

BadPaddingException when decrypting AES with the same key

牧云@^-^@ 提交于 2019-12-03 03:50:45
This is the tester: public class CryptographySimpleTests extends ActivityTestCase { public void testsCryptographyClass_encryptAndDecrypt() { final String orgVal = "hi world! :D"; final String key = "key"; try { final byte[] encryptKey = Cryptography.deriveAES256Key(key); final byte[] decryptKey = Cryptography.deriveAES256Key(key); //Deviation method Assert.assertTrue(Arrays.equals(encryptKey, decryptKey)); byte[] encrypted = Cryptography.encryptAES(encryptKey, orgVal.getBytes()); Assert.assertFalse(Arrays.equals(encrypted, orgVal.getBytes())); byte[] decrypted = Cryptography.decryptAES