android 6.0 javax.crypto.BadPaddingException:错误:1e000065:密码函数:OPENSSL_internal:BAD_DECRYPT

时间:2016-08-19 11:46:15

标签: android encryption android-6.0-marshmallow badpaddingexception

此代码在Android 6.0之前运行良好,但如果加密文件大小小于约1k字节,则会在6.0上出错。

public static byte[] decode(byte[] decrypteSrcBuffer) throws Exception {
    Key deskey = null;
    DESedeKeySpec spec = new DESedeKeySpec(mKeyBytes);
    SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");
    deskey = keyfactory.generateSecret(spec);
    Cipher cipher = Cipher.getInstance("desede/CBC/PKCS5Padding");
    IvParameterSpec ips = new IvParameterSpec(iv.getBytes());
    cipher.init(Cipher.DECRYPT_MODE, deskey, ips);
    byte[] decryptData = cipher.doFinal(decrypteSrcBuffer);

    return decryptData;
}

错误信息:

javax.crypto.BadPaddingException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT
at com.android.org.conscrypt.NativeCrypto.EVP_CipherFinal_ex(Native Method)
at com.android.org.conscrypt.OpenSSLCipher$EVP_CIPHER.doFinalInternal(OpenSSLCipher.java:568)
at com.android.org.conscrypt.OpenSSLCipher.engineDoFinal(OpenSSLCipher.java:350)
at javax.crypto.Cipher.doFinal(Cipher.java:2056)

0 个答案:

没有答案