PHP AES解密工作加密NOT [英] PHP AES Decryption working Encryption NOT

查看:170
本文介绍了PHP AES解密工作加密NOT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有4件工作,4加密,iOS加密解密从这个链接
我可以解密从iOS加密的数据我无法在PHP端加密。
当我做echo加密代码。 PHP打印像F>HFl8aRprints这是什么意思?



SALTKEY ='a16byteslongkey!';



解密代码:工作

  $ result = mcrypt_decrypt MCRYPT_RIJNDAEL_128,(SALTKEY。str_repeat(chr(0x00),16)),
base64_decode($ text),'ecb');
$ pad_char = ord(substr($ result,-1));
return substr($ result,0,strlen($ result) - $ pad_char);

加密代码:不工作

  $ result = mcrypt_encrypt(MCRYPT_RIJNDAEL_128,(SALTKEY。str_repeat(chr(0x00),16)),
base64_encode($ text),'ecb' ;
$ pad_char = ord(substr($ result,-1));
return substr($ result,0,strlen($ result) - $ pad_char);




  • iOS上的结果 Text =Hello

    加密=7opqbb7sEVNoXplyQv / X8g ==

    解密(7opqbb7sEVNoXplyQv / X8g ==)=Hello


  • PHP的结果:Text =7opqbb7sEVNoXplyQv / X8g ==

    Decryption =Hello

    加密(你好)=_〜TPn〜p3MF?



解决方案>

我认为IOS加密在给出一个8位的表示方面给出了7位的结果(看起来像是base64编码),这显然是很明显的。



您似乎没有将 的操作。



解密由 base64_decode 执行输入,然后应用 mcrypt_decrypt 。因此,要反过来执行,您需要先 mcrypt_encrypt ,然后然后 base64_encode

ie

  $ result = base64_encode(
mcrypt_encrypt(MCRYPT_RIJNDAEL_128,
(SALTKEY。str_repeat(chr(0x00),16)),
$ text,'ecb'));


So, I have 3 Pieces out of 4 working, iOS Encrypt-Decrypt from this Link And I am able to Decrypt the data Encrypted from iOS I am having trouble Encrypting on PHP side. When I do echo Encryption code. PHP prints something like F>HFl8aR what does it mean ?

SALTKEY = 'a16byteslongkey!';

Decryption Code: Working

     $result =  mcrypt_decrypt(MCRYPT_RIJNDAEL_128, (SALTKEY . str_repeat(chr(0x00), 16)), 
                               base64_decode($text), 'ecb');
     $pad_char = ord(substr($result, -1));
     return substr($result, 0, strlen($result) - $pad_char);

Encryption Code : Not Working

     $result =  mcrypt_encrypt(MCRYPT_RIJNDAEL_128, (SALTKEY . str_repeat(chr(0x00), 16)), 
                               base64_encode($text), 'ecb');
     $pad_char = ord(substr($result, -1));
     return substr($result, 0, strlen($result) - $pad_char);

  • Results on iOS : Text = "Hello"
    Encryption = "7opqbb7sEVNoXplyQv/X8g=="
    Decryption of (7opqbb7sEVNoXplyQv/X8g==) = "Hello"

  • Results on PHP : Text = "7opqbb7sEVNoXplyQv/X8g=="
    Decryption = "Hello"
    Encryption of (Hello) = "_~TPn~p3MF?"

解决方案

I think its fairly obvious that the IOS encryption is giving a 7-bit result (looks like base64 encoded) while the PHP is giving an 8-bit representation.

You don't seem to have got the hang of reversing the operation.

The decryption is performed by base64_decodeing the input, then applying mcrypt_decrypt. It follows that to perform this in reverse, you'd need to first mcrypt_encrypt, and then base64_encode.

i.e.

 $result =  base64_encode(
          mcrypt_encrypt(MCRYPT_RIJNDAEL_128, 
                (SALTKEY . str_repeat(chr(0x00), 16)), 
                $text, 'ecb'));

这篇关于PHP AES解密工作加密NOT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆