密码功能:错误的最终块长度Android Studio。

时间:2022-06-15 23:06:56

There are a lot of threads on stack overflow with this topic, and always the same solutions, but these doesn't work for me. I am looking for a way to decrypt the value byte[] encrypted and return byte[] decodedBytes.

这个主题有很多关于堆栈溢出的线程,并且总是相同的解决方案,但是这些方法对我不起作用。我正在寻找一种方法来解密该值字节[]加密和返回字节[]解码字节。

With the method AESCrypt. I use compile 'com.scottyab:aescrypt:0.0.1'

AESCrypt与方法。我使用编译com.scottyab:aescrypt:0.0.1的

private void testAES() {
    try {

       final byte[] encrypted = Base64.decode("R3JhbmRlIFZpY3RvaXJlICE=", Base64.NO_WRAP);

       byte[] keyBytes = Base64.decode("L/91ZYrliXvmhYt9FKEkkDDni+PzcnOuV9cikm188+4=", Base64.NO_WRAP);
       final byte[] ivBytes = Base64.decode("gqjFHI+YQiP7XYEfcIEJHw==".getBytes(), Base64.NO_WRAP);

       final SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES");

       byte[] decodedBytes = AESCrypt.decrypt(keySpec, ivBytes, encrypted);

   } catch (Exception e) {
       e.printStackTrace();
   }
 }

With the value Cipher, i use it like that.

有了valuecipher,我就像这样使用它。

private static byte[] testCipher() {

    try {

        final byte[] encrypted = Base64.decode("R3JhbmRlIFZpY3RvaXJlICE=", Base64.NO_WRAP);

        byte[] keyBytes = Base64.decode("L/91ZYrliXvmhYt9FKEkkDDni+PzcnOuV9cikm188+4=", Base64.NO_WRAP);
        byte[] ivBytes = Base64.decode("gqjFHI+YQiP7XYEfcIEJHw==".getBytes(), Base64.NO_WRAP);

        final IvParameterSpec ivSpecForData = new IvParameterSpec(ivBytes);

        SecretKeySpec decodedKeySpec = new SecretKeySpec(keyBytes, "AES");
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, decodedKeySpec, ivSpecForData);

        byte[] decodedBytes = cipher.doFinal(encrypted); // I have the error here //

        return decodedBytes;

    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}

Whatever i do, i allways have the same error :

无论我做什么,我总是有同样的错误:

error:1e06b07b:Cipher functions:EVP_DecryptFinal_ex:WRONG_FINAL_BLOCK_LENGTH

错误:1 e06b07b:密码功能:EVP_DecryptFinal_ex:WRONG_FINAL_BLOCK_LENGTH

I try to put in Cipher.getInstance (AES/CBC/NoPadding, AES/CBC/PKCS5Padding, AES/CBC/PKCS7Padding) but nothing change. Do you have any idea to help me ?

我试着写密码。getInstance (AES/CBC/ nopadd, AES/CBC/PKCS5Padding, AES/CBC/PKCS7Padding)但没有变化。你有什么办法帮我吗?

1 个解决方案

#1


1  

"R3JhbmRlIFZpY3RvaXJlICE=" decoded to 17 hex bytes 4772616E646520566963746F6972652021 which is the ASCII text: "Grande Victoire !".

"R3JhbmRlIFZpY3RvaXJlICE="解码到17十六进制字节4772616E646520566963746F6972652021,这是ASCII文本:"Grande Victoire !"

17 bytes is not a valid size for AES which is a block cipher that requires encrypted data to be a multiple of the block size of 16-bytes.

对于AES来说,17字节不是一个有效的大小,它是一个块密码,需要加密的数据是16字节块大小的倍数。

There is no encryption just Base64 encoding.

没有加密,只有Base64编码。

#1


1  

"R3JhbmRlIFZpY3RvaXJlICE=" decoded to 17 hex bytes 4772616E646520566963746F6972652021 which is the ASCII text: "Grande Victoire !".

"R3JhbmRlIFZpY3RvaXJlICE="解码到17十六进制字节4772616E646520566963746F6972652021,这是ASCII文本:"Grande Victoire !"

17 bytes is not a valid size for AES which is a block cipher that requires encrypted data to be a multiple of the block size of 16-bytes.

对于AES来说,17字节不是一个有效的大小,它是一个块密码,需要加密的数据是16字节块大小的倍数。

There is no encryption just Base64 encoding.

没有加密,只有Base64编码。