iOS AES加密 PHP解密_PHP_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > PHP > iOS AES加密 PHP解密

iOS AES加密 PHP解密

 2013/7/10 2:36:13  siruoxian  程序员俱乐部  我要评论(0)
  • 摘要: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
  • 标签:PHP iOS

?

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.实现方法见附件

?

  • AESCrypt.zip (6 KB)
  • 下载次数: 1
发表评论
用户名: 匿名