PHP AES 解密工作加密 NOT

标签 php iphone ios encryption aes

所以,我有 4 个工作中的 3 个,iOS 加密解密来自这个 Link 而且我能够解密从 iOS 加密的数据 我在 PHP 端加密时遇到问题。 当我回显加密代码时。 PHP 打印类似F>HFl8aR 是什么意思?

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==) = "你好"

  • PHP 上的结果:Text = "7opqbb7sEVNoXplyQv/X8g=="
    解密=“你好”
    加密(你好) = "_~TPn~p3MF?"

最佳答案

我认为很明显,IOS 加密给出了 7 位结果(看起来像 base64 编码),而 PHP 给出了 8 位表示。

您似乎没有掌握撤消操作的诀窍。

解密是通过对输入进行base64_decode,然后应用mcrypt_decrypt 来执行的。因此,要反向执行此操作,您需要先mcrypt_encrypt,然后然后 base64_encode

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

关于PHP AES 解密工作加密 NOT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8179308/

相关文章:

ios - 强制 MKMapView 删除 MKOverlayRenderer

ios - 如何在iOS上为Clang生成链接映射文件?

php - Facebook 的 HipHop - 它有什么用?

php - 移动导航栏 Wordpress 神秘主题问题

php - 我如何将选择转换为复选框

php - Jquery AJAX 实时输出?

iphone - 添加 subview 到 UITableViewCell : Added several times when scrolling

iphone - 如何增加/减少 Unsigned Char?

iphone - 使用未签名证书的 SSL 连接

ios - 核心数据 : when to 'free' unused NSManagedObjects with [ refreshObject:obj mergeChanges:NO]?