IOS游戏 与PHP服务器端的AES通讯加密

来源:互联网 发布:网络不通怎么解决 编辑:程序博客网 时间:2024/04/27 18:48

来源:http://www.mjplay.com.cn/ios-php-aes/

PHP 的AES加密解密

<?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);?>

 

objective-c加密解密

#import "NSString+AESCrypt.h"NSString *key = @"a16byteslongkey!a16byteslongkey!";NSString *plaintext = @"iphone";NSString *ciphertext = [plaintext AES256EncryptWithKey: key];NSLog(@"ciphertext: %@", ciphertext);plaintext = [ciphertext AES256DecryptWithKey: key];NSLog(@"plaintext: %@", plaintext);
0 0
原创粉丝点击