相关文章推荐
满身肌肉的包子  ·  MSB4018 - MSBuild | ...·  3 周前    · 
安静的海龟  ·  vtkIterativeClosestPoi ...·  3 月前    · 
近视的人字拖  ·  JavaScript/JS ...·  6 月前    · 
道上混的上铺  ·  Qt中void ...·  7 月前    · 
快乐的哑铃  ·  TypeScript 5.1 ...·  1 年前    · 
绅士的剪刀  ·  makefile输出变量-掘金·  1 年前    · 
javax.crypto.BadPaddingException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT 2018-11-12 18:55:12

在做AES、DES 等加密的时候会出现该类问题:

12-10 05:34:21.721  4043   724 W System.err: javax.crypto.BadPaddingException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT
12-10 05:34:21.721  4043   724 W System.err: 	at com.android.org.conscrypt.NativeCrypto.EVP_CipherFinal_ex(Native Method)
12-10 05:34:21.721  4043   724 W System.err: 	at com.android.org.conscrypt.OpenSSLCipher$EVP_CIPHER.doFinalInternal(OpenSSLCipher.java:570)
12-10 05:34:21.721  4043   724 W System.err: 	at com.android.org.conscrypt.OpenSSLCipher.engineDoFinal(OpenSSLCipher.java:351)
12-10 05:34:21.721  4043   724 W System.err: 	at javax.crypto.Cipher.doFinal(Cipher.java:1741)
12-10 05:34:21.721  4043   724 W System.err: 	at com.shift.encrytion.core.BlockEncryptionHelper.encrypt(BlockEncryptionHelper.java:126)
12-10 05:34:21.721  4043   724 W System.err: 	at com.shift.encrytion.aes.AESHelper.encrypt(AESHelper.java:17)
12-10 05:34:21.721  4043   724 W System.err: 	at com.shift.encrytion.aes.AESEncryption.encrypt(AESEncryption.java:23)
12-10 05:34:21.721  4043   724 W System.err: 	at com.shift.encrytion.core.BlockEncryption.decryptFile(BlockEncryption.java:103)
12-10 05:34:21.721  4043   724 W System.err: 	at com.shift.encrytion.FileEncryption.decryptFiles(FileEncryption.java:171)
12-10 05:34:21.721  4043   724 W System.err: 	at com.shift.encrytion.FileEncryption.operation(FileEncryption.java:210)
12-10 05:34:21.721  4043   724 W System.err: 	at com.shift.encrytion.FileEncryption.-wrap0(Unknown Source:0)
12-10 05:34:21.721  4043   724 W System.err: 	at com.shift.encrytion.FileEncryption$EncryptionTask.doInBackground(FileEncryption.java:223)
12-10 05:34:21.722  4043   724 W System.err: 	at com.shift.encrytion.FileEncryption$EncryptionTask.doInBackground(FileEncryption.java:221)
12-10 05:34:21.722  4043   724 W System.err: 	at android.os.AsyncTask$2.call(AsyncTask.java:333)
12-10 05:34:21.722  4043   724 W System.err: 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
12-10 05:34:21.722  4043   724 W System.err: 	at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
12-10 05:34:21.722  4043   724 W System.err: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
12-10 05:34:21.722  4043   724 W System.err: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
12-10 05:34:21.722  4043   724 W System.err: 	at java.lang.Thread.run(Thread.java:764)

主要确定下一下几点:

1、算法的名称与加密时是否相同

2、加密和解密时的模式、填充是否相同

3、加密和解密时的密钥是否相同

4、模式、填充是否是该算法支持的

根本原因就是code 书写不正确,详细确认!

数据加密 ---- 总篇

public void test(){ String str = "adf4976d917a07e0513dce45b6981919"; String miwei = "{\"你好\":\"2020\"}"; String abc = ""; byte[] cipher Text = null; byte[] decr java x. crypto . Bad Padding Exception : Given final block not properly padded. Such issues can arise if a bad key is used during decrypt ion. at com.sun. crypto .provider. Cipher Core.doFinal(Ciph... Android codeString apiResponse = "EcUZvMifMethod:protected void decrypt DataWithAES(String apiResponse, String key) {try {es(StandardCharsets.UTF_8);byte[] decodedResult = Base64.decode(apiResponse, Ba... 1. Error : java .util.concurrent.Execution Exception : com.android.tools.aapt2.Aapt2 Exception : AAPT2 error : check logs for details 在工程的gradle.properties文件中添加以下命令: android.enableAapt2=false