密码功能:Android Oreo中的OPENSSL_internal:BAD_DECRYPT

Tin*_*ina 5 encryption android aes android-8.0-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;

    }
Run Code Online (Sandbox Code Playgroud)

用于加密和解密的密钥是相同的。而且此代码适用于UAT(Android Oreo版本),但会给生产带来错误。