mcrypt

PHP script for DES/CBC/ with PKCS5Padding encryption and decryption

三世轮回 提交于 2019-12-01 09:30:40
I would like to know in the following code if PKCS#5 padding is added ? If not how to add ? $message = "insert plaintext message here"; $iv = pack('H*', 'insert hex iv here'); $key = pack('H*', 'insert hex key here'); $enc = mcrypt_encrypt(MCRYPT_DES, $key, $message, MCRYPT_MODE_CBC, $iv); echo bin2hex($enc); I also want to create a PHP code to decrypt a string created with DES/CBC/PKCS5Padding. I think the above mentioned code can be modified to get a decryption. The important thing for me is to get the PKCS#5 Padding and Unpadding script. No, it is not added. Unfortunately PHP / mcrypt uses

PHP script for DES/CBC/ with PKCS5Padding encryption and decryption

浪子不回头ぞ 提交于 2019-12-01 09:24:02
问题 I would like to know in the following code if PKCS#5 padding is added ? If not how to add ? $message = "insert plaintext message here"; $iv = pack('H*', 'insert hex iv here'); $key = pack('H*', 'insert hex key here'); $enc = mcrypt_encrypt(MCRYPT_DES, $key, $message, MCRYPT_MODE_CBC, $iv); echo bin2hex($enc); I also want to create a PHP code to decrypt a string created with DES/CBC/PKCS5Padding. I think the above mentioned code can be modified to get a decryption. The important thing for me

Node.js `crypto.final` make the encrypted result is different to PHP `mcrypt_encrypt`

六眼飞鱼酱① 提交于 2019-12-01 07:33:33
At first, Node.js crypto. // Both of key and IV are hex-string, but I hide them in Stackoverflow. var secretKey = new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), // 48 chars iv = new Buffer('bbbbbbbbbbbbbbbb', 'hex'); // 16 chars var str = 'This string will be encrypted.'; var cipher = crypto.createCipheriv('des-ede3-cbc', secretKey, iv), cryptedStr = cipher.update(str, 'utf8', 'base64') + cipher.final('base64'); Then, PHP mcrypt. $key = pack('H*', "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); $iv = pack('H*', "bbbbbbbbbbbbbbbb"); $string = 'This string will be

How to decrypt a string with OpenSSL which was previously encrypted with mcrypt?

孤者浪人 提交于 2019-12-01 05:54:13
Since mcrypt was deprecated in PHP 7.1 and I have a lot of data encrypted/decrypted with mcrypt in existing project, how to migrate my PHP code from mcrypt to OpenSSL? I have the following code to encrypt: $encoded = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, 'salt', 'source string', MCRYPT_MODE_ECB)); And decryption code is: $source = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, 'salt', base64_decode('encoded string'), MCRYPT_MODE_ECB); What openssl_ functions should I use in the above examples to get the same results without encoded data conversion? Or the only way is to run a script which

Node.js `crypto.final` make the encrypted result is different to PHP `mcrypt_encrypt`

送分小仙女□ 提交于 2019-12-01 04:56:53
问题 At first, Node.js crypto. // Both of key and IV are hex-string, but I hide them in Stackoverflow. var secretKey = new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), // 48 chars iv = new Buffer('bbbbbbbbbbbbbbbb', 'hex'); // 16 chars var str = 'This string will be encrypted.'; var cipher = crypto.createCipheriv('des-ede3-cbc', secretKey, iv), cryptedStr = cipher.update(str, 'utf8', 'base64') + cipher.final('base64'); Then, PHP mcrypt. $key = pack('H*',

How to decrypt a string with OpenSSL which was previously encrypted with mcrypt?

前提是你 提交于 2019-12-01 04:06:16
问题 Since mcrypt was deprecated in PHP 7.1 and I have a lot of data encrypted/decrypted with mcrypt in existing project, how to migrate my PHP code from mcrypt to OpenSSL? I have the following code to encrypt: $encoded = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, 'salt', 'source string', MCRYPT_MODE_ECB)); And decryption code is: $source = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, 'salt', base64_decode('encoded string'), MCRYPT_MODE_ECB); What openssl_ functions should I use in the above

Difference in PHP encryption from iOS and .NET

两盒软妹~` 提交于 2019-12-01 01:15:38
I have an issue when communicating encrypted between iOS and PHP. I have an app that encrypts a string and sends it to a PHP server that decrypts it. That part works just fine. Now the PHP server needs to send an encrypted response back to the app, which seems to be causing a bit more gray hair. The issue is, that when I encrypt a string in PHP it looks different from the same string encrypted in iOS and even .NET - obviously all places use the same algorithm, key and IV. I use Rijndael 128 in CBC mode with an IV consisting of empty bytes (so far). The PHP encryption looks so: $encrypted =

Decrypting AES with Javascript CryptoJS after encrypting with PHP mcrypt

本小妞迷上赌 提交于 2019-12-01 00:42:18
Encrypting in PHP with mcrypt <?php $string = 'Secret Message'; $key = 'd4b494e4502a62edd695a903a94c2701'; $iv = '02f30dffbb0d084755f438f7d8be4a7d'; $encrypted = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_CBC, $iv ) ); //$encrypted results in 'nYoFAiyDARVSI09lH/IPdim5TvE51izVjk6sc2AK9Rg=' ?> Decrypting in Javascript with CryptoJS <script> var encrypted = 'nYoFAiyDARVSI09lH/IPdim5TvE51izVjk6sc2AK9Rg='; var key = CryptoJS.enc.Hex.parse('d4b494e4502a62edd695a903a94c2701'); var iv = CryptoJS.enc.Hex.parse('02f30dffbb0d084755f438f7d8be4a7d'); var decrypted =

Decrypting AES with Javascript CryptoJS after encrypting with PHP mcrypt

末鹿安然 提交于 2019-11-30 19:59:56
问题 Encrypting in PHP with mcrypt <?php $string = 'Secret Message'; $key = 'd4b494e4502a62edd695a903a94c2701'; $iv = '02f30dffbb0d084755f438f7d8be4a7d'; $encrypted = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_CBC, $iv ) ); //$encrypted results in 'nYoFAiyDARVSI09lH/IPdim5TvE51izVjk6sc2AK9Rg=' ?> Decrypting in Javascript with CryptoJS <script> var encrypted = 'nYoFAiyDARVSI09lH/IPdim5TvE51izVjk6sc2AK9Rg='; var key = CryptoJS.enc.Hex.parse(

PHP sending encrypted data via the URL

泄露秘密 提交于 2019-11-30 19:05:07
I'm trying to send encrypted data over the url to another site (using file_get_contents("anotherUrl.php?hash=$encryptedString") . The problem is, sometimes, the encryption contains some special characters, like +, and this causes the decryption to fail. Here are my encryption / decryption methods: public function encrypt($string, $key) { return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key)))); } public function decrypt($encrypted, $key) { return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted), MCRYPT_MODE_CBC