English 中文(简体)
PHP MyCrypt Encoding/Decoding don t work
原标题:PHP MyCrypt Encoding/Decoding doesn t work

i have a little problem: my decryption won t give me the same string i encoded, and i can t find the problem... looked in other posts, but nothing helpful there here are my functions:

public static function encryptData($data){
    if($key = self::getEncryptionKey()){
        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
        return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_ECB,$iv));
    } else {
        return false;
    }
}

public static function decryptData($data)
{
    if($key = self::getEncryptionKey()){
        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
        return mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($data), MCRYPT_MODE_ECB,$iv);
    } else {
        return false;
    }

}

问题在哪里? i 这里绝望......

问题回答

各位需要everything,在双方完全相同。 关键、模式、四和dding。

Looking at your code, you appear to be generating a new IV for decryption. Don t. Use the same IV as you used to encrypt.

你正确地明确指明了一种模式,但你采取了最可能的方式。 无偿使用ECB,泄漏信息。 采用CBC或CTR模式。

You don t specify a padding. Far better to specify it explicitly, use PKCS7 with Rijndael.

如果没有任何这种帮助,那么通过逐条检查你的钥匙,以确保其与加密和加密相同。





相关问题
Extend Contacts application on Android to provide encryption

I want to encrypt individual contacts stored by the Contacts application on Android based on user s preference. So, I am thinking I ll have to hook/extend the Contacts application before the it stores ...

Make md5 strong

Im making a website that will intergrate with game that only support md5 hashing metod (atm). Which ofc is not especially safe anymore. But how could i make it stronger? Should I just generate long ...

How to Pack/Encrypt/Unpack/Decrypt a bunch of files in Java?

I m essentially trying to do the following on a Java/JSP-driven web site: User supplies a password Password is used to build a strongly-encrypted archive file (zip, or anything else) containing a ...

Thread & Queue vs Serial performance

I though it ll be interesting to look at threads and queues, so I ve written 2 scripts, one will break a file up and encrypt each chunk in a thread, the other will do it serially. I m still very new ...

Convert PHP encryption code to C#

I m trying to convert this piece of code from PHP to C#. It s part of a Captive Portal. Could somebody explain what it does? $hexchal = pack ("H32", $challenge); if ($uamsecret) { $newchal = ...

Encryption: how to have 1 iv despite multiple fields

I ve been stuck trying to arrive at a best solution for this for a while. I know that an initialization vector has to be unique for each item being encrypted. So if I m encrypting an address and I ...

热门标签