mcrypt

Encryption in JavaScript and decryption with PHP

折月煮酒 提交于 2019-11-26 16:44:09
I'm encrypting my user password in JavaScript like this: var encryptedPassword = CryptoJS.AES.encrypt(password, "Secret Passphrase"); It works fine but now I'm trying to decrypt in PHP on the server side like this: $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND); $decryptPassword = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, "Secret Passphrase", base64_decode($password), MCRYPT_MODE_CBC, $iv); it doesn't works at all, the decrypted password string looks very strange: string(64) ">�OX2MS��댗v�<$�ʕ��i�̄��_��P���\�կ=�_6(�m����,4WT7��a" Here is the current

php: mcrypt_encrypt to openssl_encrypt, and OPENSSL_ZERO_PADDING problems

本小妞迷上赌 提交于 2019-11-26 12:46:58
问题 I have this mcrypt_encrypt call, for a given $key , $message and $iv : $string = mcrypt_encrypt(MCRYPT_3DES, $key, $message, MCRYPT_MODE_CBC, $iv); I\'d like to change the mcrypt_encrypt call to an openssl_encrypt one, to future-proof this. By having $mode = \'des-ede3-cbc\' or $mode = \'3DES\'; and $options = true I get the more similar response, but not identical. Is there other way to call it to get a perfect match? I\'m getting this (base64_encoded) for a lorem-ipsum $message + $key

Installing mcrypt extension for PHP on OSX Mountain Lion

梦想与她 提交于 2019-11-26 12:35:59
问题 Apologies in advance for the potential n00b questions, I am trying to install the mcrypt extension for PHP on my OSX Mountain Lion machine. The following steps in terminal is what I have done so far to achieve my PHP install cd /path/to/downloaded/php-5.3.21/ext/mcrypt/ /usr/bin/phpize ./configure cd /path/to/downloaded/php-5.3.21 ./configure --with-config-file-path=/private/etc/php.ini --with-apxs2=/usr/sbin/apxs make sudo make install Which seems to work well and installs PHP 5.3.21 fine. I

3DES 数据加密(3DES/ECB/zeroPadding)PHP &lt;= 7.0.x

久未见 提交于 2019-11-26 12:21:05
1. 3DES 简介   3DES(即Triple DES)是DES向AES过渡的加密算法(1999年,NIST将3-DES指定为过渡的加密标准),加密算法,其具体实现如下:设Ek()和Dk()代表DES算法的加密和解密过程,K代表DES算法使用的密钥,M代表明文,C代表密文,这样: 3DES加密过程为: C = Ek3(Dk2(Ek1(M))) 3DES解密过程为: M = Dk1(EK2(Dk3(C)))   常见的“对称密钥”加密算法主要有DES、3DES(TripleDES)、AES、RC2、RC4、RC5和Blowfish等,具体每个算法的实现我就不再这里说了,感兴趣的自己去查找。 2. 加解密类 Crypt3Des class Crypt3Des { public $key = ""; function __construct($key) { $this->key = $key; } /** * 数据加密 * @param string $input * @return void */ function encrypt($input) { $size = mcrypt_get_block_size(MCRYPT_3DES, 'ecb'); $input = $this->pkcs5_pad($input, $size); // $key = str_pad($this-

How to do AES256 decryption in PHP?

此生再无相见时 提交于 2019-11-26 11:19:13
问题 I have an encrypted bit of text that I need to decrypt. It\'s encrypted with AES-256-CBC. I have the encrypted text, key, and iv. However, no matter what I try I just can\'t seem to get it to work. The internet has suggested that mcrypt\'s Rijndael cypher should be able to do this, so here\'s what I have now: function decrypt_data($data, $iv, $key) { $cypher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, \'\', MCRYPT_MODE_CBC, \'\'); // initialize encryption handle if (mcrypt_generic_init($cypher,

Cross platform (php to C# .NET) encryption/decryption with Rijndael

雨燕双飞 提交于 2019-11-26 09:27:32
问题 I\'m currently having a bit of problem with decrypting a message encrypted by php mcrypt. The php code is as following: <?php //$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); $iv = \"45287112549354892144548565456541\"; $key = \"anjueolkdiwpoida\"; $text = \"This is my encrypted message\"; $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_CBC, $iv); $crypttext = urlencode($crypttext); $crypttext64=base64_encode($crypttext); print($crypttext64) . \"

PHP7.1 mcrypt alternative

空扰寡人 提交于 2019-11-26 07:46:22
问题 Mcrypt function has been deprecated as of PHP 7.1.0. My deprecated string encode / decode functions: $key: secret key $str: string $encoded = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $str, MCRYPT_MODE_CBC, md5(md5($key)))); $decoded = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($str), MCRYPT_MODE_CBC, md5(md5($key))), \"\\0\"); Can you suggest some alternatives? 回答1: You should use openssl_encrypt instead. 回答2: Consider using defuse or RNCryptor,

Replace Mcrypt with OpenSSL

放肆的年华 提交于 2019-11-26 05:02:43
currently we have a mcrypt implentation on our systems to crypt some sensible data in our PHP application. Now we have a new requirement that we have to change the crypt module to openssl. Another thing which is important know is that we are using the cipher blowfish and the mode ecb. So I began to test what are differences and how I can decrypt mcrypt encrypted strings with openssl. I used the standard PHP function: mcrypt_encrypt vs. openssl_encrypt mcrypt_decrypt vs. openssl_decrypt Both methods are delivering different results. Second thing is that in the given cipher (blowfish) and mode

Encryption in JavaScript and decryption with PHP

耗尽温柔 提交于 2019-11-26 04:54:26
问题 I\'m encrypting my user password in JavaScript like this: var encryptedPassword = CryptoJS.AES.encrypt(password, \"Secret Passphrase\"); It works fine but now I\'m trying to decrypt in PHP on the server side like this: $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND); $decryptPassword = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, \"Secret Passphrase\", base64_decode($password), MCRYPT_MODE_CBC, $iv); it doesn\'t works at all, the decrypted password string

Encrypting / Decrypting file with Mcrypt

泄露秘密 提交于 2019-11-26 03:55:51
Trying to write a couple of functions that will encrypt or decrypt a file and am using the class found here to try and accomplish this: http://www.itnewb.com/v/PHP-Encryption-Decryption-Using-the-MCrypt-Library-libmcrypt The encryption function below seems to work, in that it appears to encrypt the file and place it in the intended directory. I'm trying to decrypt the file now, and it just dies with the message "Failed to complete decryption" (which is coded in there...) There's nothing in the php error logs, so I'm not sure why it's failing, but as mcrypt is entirely new to me, I'm more than