`
siruoxian
  • 浏览: 231777 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

iOS AES加密 PHP解密

阅读更多

 

1.php代码

<?php  

$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);  

$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);  

$key = 'a16byteslongkey!a16byteslongkey!';  

$plaintext = "iphone";  

  

$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext, MCRYPT_MODE_ECB);  

$base64encoded_ciphertext = base64_encode($ciphertext);  

echo "ciphertext: ".$base64encoded_ciphertext."<br/>";  

  

$plaintext = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($base64encoded_ciphertext), MCRYPT_MODE_ECB);  

echo "plaintext: ".$plaintext."<br/>";  

  

$base64encoded_ciphertext =  "I3chV+E2XUHeLCcJAhBaJQ==";  

$plaintext = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($base64encoded_ciphertext), MCRYPT_MODE_ECB);  

echo "plaintext: ".trim($plaintext);  

?>   

 

2.oc代码

 

    NSString *key = @"a16byteslongkey!a16byteslongkey!";

    NSString *plaintext = @"iphone";

    NSString *ciphertext = [plaintext AES256EncryptWithKey: key];

    NSLog(@"ciphertext: %@", ciphertext);

    plaintext = [ciphertext AES256DecryptWithKey: key];

    NSLog(@"plaintext: %@", plaintext);

 

3.实现方法见附件

 

1
4
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics