Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Im trying to make a crypt/decrypt routine using mcrypt but it seems to mess the data im trying to encrypt.

Heres the code:

 $data = 'Some important data'; $key = "mycryptKey"; $cipher = "rijndael-128"; $encryptedData = mcrypt_encrypt($cipher, $key, $data, MCRYPT_MODE_ECB); $decryptedData = mcrypt_decrypt($cipher, $key, $encryptedData, MCRYPT_MODE_ECB); var_dump($data); //string 'Some important data' (length=19) var_dump($encryptedData); //string '™ì{*¾xv-&n5’Œü½Ýëc®n)mSƒ7]' (length=32) var_dump($decryptedData); //string 'Some important data�������������' (length=32) 

It keeps adding those characters at the end of the original string. I saw an example at How do you Encrypt and Decrypt a PHP String?How do you Encrypt and Decrypt a PHP String? but it didn't work

Thats the actual test. The key and data I'm using are the same posted here

Edit

I realized, after @jonhopkins comment, that mcrypt was padding some "\0" characters after $data content, so i clean it up after decryption using 'strtok':

$decryptedData = \strtok( mcrypt_decrypt($cipher, $key, $encryptedData, MCRYPT_MODE_ECB), "\0" ); var_dump($decryptedData); //string 'Some important data' (length=19) 

Im trying to make a crypt/decrypt routine using mcrypt but it seems to mess the data im trying to encrypt.

Heres the code:

 $data = 'Some important data'; $key = "mycryptKey"; $cipher = "rijndael-128"; $encryptedData = mcrypt_encrypt($cipher, $key, $data, MCRYPT_MODE_ECB); $decryptedData = mcrypt_decrypt($cipher, $key, $encryptedData, MCRYPT_MODE_ECB); var_dump($data); //string 'Some important data' (length=19) var_dump($encryptedData); //string '™ì{*¾xv-&n5’Œü½Ýëc®n)mSƒ7]' (length=32) var_dump($decryptedData); //string 'Some important data�������������' (length=32) 

It keeps adding those characters at the end of the original string. I saw an example at How do you Encrypt and Decrypt a PHP String? but it didn't work

Thats the actual test. The key and data I'm using are the same posted here

Edit

I realized, after @jonhopkins comment, that mcrypt was padding some "\0" characters after $data content, so i clean it up after decryption using 'strtok':

$decryptedData = \strtok( mcrypt_decrypt($cipher, $key, $encryptedData, MCRYPT_MODE_ECB), "\0" ); var_dump($decryptedData); //string 'Some important data' (length=19) 

Im trying to make a crypt/decrypt routine using mcrypt but it seems to mess the data im trying to encrypt.

Heres the code:

 $data = 'Some important data'; $key = "mycryptKey"; $cipher = "rijndael-128"; $encryptedData = mcrypt_encrypt($cipher, $key, $data, MCRYPT_MODE_ECB); $decryptedData = mcrypt_decrypt($cipher, $key, $encryptedData, MCRYPT_MODE_ECB); var_dump($data); //string 'Some important data' (length=19) var_dump($encryptedData); //string '™ì{*¾xv-&n5’Œü½Ýëc®n)mSƒ7]' (length=32) var_dump($decryptedData); //string 'Some important data�������������' (length=32) 

It keeps adding those characters at the end of the original string. I saw an example at How do you Encrypt and Decrypt a PHP String? but it didn't work

Thats the actual test. The key and data I'm using are the same posted here

Edit

I realized, after @jonhopkins comment, that mcrypt was padding some "\0" characters after $data content, so i clean it up after decryption using 'strtok':

$decryptedData = \strtok( mcrypt_decrypt($cipher, $key, $encryptedData, MCRYPT_MODE_ECB), "\0" ); var_dump($decryptedData); //string 'Some important data' (length=19) 
added 345 characters in body
Source Link
CarlosCarucce
  • 3.6k
  • 3
  • 31
  • 56

Im trying to make a crypt/decrypt routine using mcrypt but it seems to mess the data im trying to encrypt.

Heres the code:

 $data = 'Some important data'; $key = "mycryptKey"; $cipher = "rijndael-128"; $encryptedData = mcrypt_encrypt($cipher, $key, $data, MCRYPT_MODE_ECB); $decryptedData = mcrypt_decrypt($cipher, $key, $encryptedData, MCRYPT_MODE_ECB); var_dump($data); //string 'Some important data' (length=19) var_dump($encryptedData); //string '™ì{*¾xv-&n5’Œü½Ýëc®n)mSƒ7]' (length=32) var_dump($decryptedData); //string 'Some important data�������������' (length=32) 

It keeps adding those characters at the end of the original string. I saw an example at How do you Encrypt and Decrypt a PHP String? but it didn't work

Thats the actual test. The key and data I'm using are the same posted here

Edit

I realized, after @jonhopkins comment, that mcrypt was padding some "\0" characters after $data content, so i clean it up after decryption using 'strtok':

$decryptedData = \strtok( mcrypt_decrypt($cipher, $key, $encryptedData, MCRYPT_MODE_ECB), "\0" ); var_dump($decryptedData); //string 'Some important data' (length=19) 

Im trying to make a crypt/decrypt routine using mcrypt but it seems to mess the data im trying to encrypt.

Heres the code:

 $data = 'Some important data'; $key = "mycryptKey"; $cipher = "rijndael-128"; $encryptedData = mcrypt_encrypt($cipher, $key, $data, MCRYPT_MODE_ECB); $decryptedData = mcrypt_decrypt($cipher, $key, $encryptedData, MCRYPT_MODE_ECB); var_dump($data); //string 'Some important data' (length=19) var_dump($encryptedData); //string '™ì{*¾xv-&n5’Œü½Ýëc®n)mSƒ7]' (length=32) var_dump($decryptedData); //string 'Some important data�������������' (length=32) 

It keeps adding those characters at the end of the original string. I saw an example at How do you Encrypt and Decrypt a PHP String? but it didn't work

Thats the actual test. The key and data I'm using are the same posted here

Im trying to make a crypt/decrypt routine using mcrypt but it seems to mess the data im trying to encrypt.

Heres the code:

 $data = 'Some important data'; $key = "mycryptKey"; $cipher = "rijndael-128"; $encryptedData = mcrypt_encrypt($cipher, $key, $data, MCRYPT_MODE_ECB); $decryptedData = mcrypt_decrypt($cipher, $key, $encryptedData, MCRYPT_MODE_ECB); var_dump($data); //string 'Some important data' (length=19) var_dump($encryptedData); //string '™ì{*¾xv-&n5’Œü½Ýëc®n)mSƒ7]' (length=32) var_dump($decryptedData); //string 'Some important data�������������' (length=32) 

It keeps adding those characters at the end of the original string. I saw an example at How do you Encrypt and Decrypt a PHP String? but it didn't work

Thats the actual test. The key and data I'm using are the same posted here

Edit

I realized, after @jonhopkins comment, that mcrypt was padding some "\0" characters after $data content, so i clean it up after decryption using 'strtok':

$decryptedData = \strtok( mcrypt_decrypt($cipher, $key, $encryptedData, MCRYPT_MODE_ECB), "\0" ); var_dump($decryptedData); //string 'Some important data' (length=19) 
Source Link
CarlosCarucce
  • 3.6k
  • 3
  • 31
  • 56

mcrypt messing with data

Im trying to make a crypt/decrypt routine using mcrypt but it seems to mess the data im trying to encrypt.

Heres the code:

 $data = 'Some important data'; $key = "mycryptKey"; $cipher = "rijndael-128"; $encryptedData = mcrypt_encrypt($cipher, $key, $data, MCRYPT_MODE_ECB); $decryptedData = mcrypt_decrypt($cipher, $key, $encryptedData, MCRYPT_MODE_ECB); var_dump($data); //string 'Some important data' (length=19) var_dump($encryptedData); //string '™ì{*¾xv-&n5’Œü½Ýëc®n)mSƒ7]' (length=32) var_dump($decryptedData); //string 'Some important data�������������' (length=32) 

It keeps adding those characters at the end of the original string. I saw an example at How do you Encrypt and Decrypt a PHP String? but it didn't work

Thats the actual test. The key and data I'm using are the same posted here