0

I am using the zend mcrypt function for the encryption of a text.

The encryption is done using the code below,

use Zend\Crypt\BlockCipher;
use Zend\Crypt\Symmetric\Mcrypt;

$blockCipher = new BlockCipher(new Mcrypt(array('algo' => 'aes'));
$blockCipher->setKey('enCryKey');
$result = $blockCipher->encrypt('this is a secret message');
echo "Encrypted text: $result \n";

There are some special characters appearing in the encrypted text. But, i have to use this in a URL and i don't want any special characters in the URL, because of url encoding difference for different mails.

Is there any way to avoid the special characters from the encrypted text which uses zend mcrypt(aes) for encryption?

Prifulnath
  • 463
  • 7
  • 24
  • When you say "don't want any special characters in the URL", is this actually going to be part of a URL? If it is, why not use `urlencode()`?. The security implications of what you may be suggesting are a different matter altogether, however... – DaveP Apr 24 '17 at 11:51
  • Thanks for your comment :) i am using this encrypted text in a URL for some authentication. Some of the mail like `zoho` decode the URL twice so special chars like `+` in the text is converted to `%252B`, where other mails encode it into `%2B` so this difference in the URL make it hard to process. That's why i wanted to avoid the special characters. – Prifulnath Apr 24 '17 at 12:06
  • Can you not hex encode it? – Luke Joshua Park Apr 24 '17 at 23:46
  • @LukePark But how? can you please explain? – Prifulnath Apr 25 '17 at 03:37
  • use preg_replace (http://stackoverflow.com/questions/14114411/remove-all-special-characters-from-a-string) – rubinmon Apr 26 '17 at 12:30
  • @rubin I cant just replace the all the special characters with null, because i have to decrypt the string. With out the full string we cant decrypt the string currectly right? – Prifulnath Apr 27 '17 at 04:11
  • ohh sure @kuttoozz try this.. (http://php.net/manual/en/function.mcrypt-encrypt.php) – rubinmon Apr 27 '17 at 04:58
  • @rubin i think a little more clarification. suppose i have a text `hi..hello` and i have encrypted it into `XfHd3$%fd` and using `preg_match` i have converted the string into `XfHd3fd`. Then is it really possible to decrypt `XfHd3fd` to `hi..hello`. – Prifulnath Apr 27 '17 at 06:00
  • yes sure, you decrypt the `$string` you get your actual text.. thanks. – rubinmon Apr 27 '17 at 08:51
  • I tried it but it was not working @rubin – Prifulnath May 04 '17 at 07:11

0 Answers0