Rijndael-256加密-在解密字符串的末尾填充


Rijndael-256 encryption - Padding on end of decrypted string

所以,我试图使用加密解密Rijndael-256,这一切都很好。但是,在字符串的末尾有填充,使其长度恰好为32字节。知道为什么吗?下面是它的输出:

array (size=9)
  'cryptedText' => string 'O¿{žû¦ê§Þøµ; *¬rÄÅϧ„•T' (length=32)
  'IV' => string 'ÄêKG£ED^°“F¨ŠêFx)'e_¶üŠèJÂ|' (length=32)
  'title' => string 'Untitled' (length=8)
  'deleteKey' => string 'ff349d33af4cff27143f66680586121e3c17d1f81aee42c7beb645684ca95558447f0eba757c7ecc785ea39633cfad5a6144fd5ea5028ca9c342e15291d7fd60' (length=128)
  'date' => string '1356827615' (length=10)
  'uid' => string '0' (length=1)
  'urlID' => string '2' (length=1)
  'id' => string '2' (length=1)
  'decryptedText' => string 'hello woaaaaaaaaarld������������' (length=32)
                                                 ^^^^^^^^^^^^ This

如果我添加超过32个字符,它填充到64,等等…

我是这样解密的:

        $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, '');
        if (mcrypt_generic_init($cipher, $key, $result_set['IV']) != -1) {
            $decrypted = mdecrypt_generic($cipher, $result_set['cryptedText']);
            mcrypt_generic_deinit($cipher);
            mcrypt_module_close($cipher);
            $result_set['decryptedText'] = $decrypted;
        }

Rijndael-256加密数据以LONGBLOB(二进制)数据类型存储在我的数据库中,以及IV.

http://php.net/manual/en/function.mcrypt-encrypt.php

将用给定密码和模式加密的数据。如果数据的大小不是n * blocksize,数据将被填充与' ' 0

返回的密文可以大于

base64_encoding我的数据之前加密它解决了这个问题。耶!

相关文章: