首页 > 解决方案 > 密码函数:OPENSSL_internal:BAD_DECRYPT in android Oreo

问题描述

Android Oreo 版本 8 在生产中引发错误的解密错误。对于其他 android 版本的代码工作正常。使用的算法是“AES/CBC/PKCS5Padding”。

public String decrypt(String _encryptedText, String _key, String _iv)
            throws InvalidKeyException, UnsupportedEncodingException,
            InvalidAlgorithmParameterException, IllegalBlockSizeException,
            BadPaddingException {
        //Log.d("enetered decryption", "enetered decryption");

        return encryptDecrypt(_encryptedText, _key, EncryptMode.DECRYPT, _iv);
    }


public String decryptionflag(String input, String iv) {
        String output = "";
        try {
            // CryptLib _crypt = new CryptLib();

            String plainText = input;

            CryptLib _crypt = new CryptLib();

            output = _crypt.decrypt(plainText, key, iv); // decrypt
            //Log.d("decrypted flag is", "" + output);
        } catch (InvalidAlgorithmParameterException e) {
            // TODO Auto-generated catch block
            Log.e("", "Exception" + e.getMessage());
        } catch (InvalidKeyException e){
            Log.e("", "Exception" + e.getMessage());
        } catch (UnsupportedEncodingException e){
            Log.e("", "Exception" + e.getMessage());
        } catch (BadPaddingException e){
            Log.e("", "Exception" + e.getMessage());
        } catch (IllegalBlockSizeException e){
            Log.e("", "Exception" + e.getMessage());
        } catch (NoSuchAlgorithmException e){
            Log.e("", "Exception" + e.getMessage());
        } catch (NoSuchPaddingException e){
            Log.e("", "Exception" + e.getMessage());
        }

        return output;

    }

用于加密和解密的密钥是相同的。并且此代码适用于 UAT(android oreo 版本),但生产时出错。

标签: androidencryptionaesandroid-8.0-oreo

解决方案


推荐阅读