php ios通用的AES加密方法
发布日期:2021-09-10 06:26:21 浏览次数:3 分类:技术文章

本文共 1866 字,大约阅读时间需要 6 分钟。

从下载AES库

在不同平台进行AES加密,并使用Base64进行编码,结果有可能不同,但解密之后会一样,所以不要因为在2个平台加密结果不一样而认为自己错了。。。

 

php加密解密: 

"; $plaintext = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($base64encoded_ciphertext), MCRYPT_MODE_ECB);echo "plaintext: ".$plaintext."
"; $base64encoded_ciphertext = "I3chV+E2XUHeLCcJAhBaJQ==";$plaintext = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($base64encoded_ciphertext), MCRYPT_MODE_ECB);echo "plaintext: ".trim($plaintext);?>

 

iphone加密解密

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

 

Demo:

php 代码:

"; //$plaintext = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($base64encoded_ciphertext), MCRYPT_MODE_ECB);//echo "plaintext: ".$plaintext."
";?>

 

 
iphone 代码:
-(NSString *)md5:(NSString *)str {     const char *cStr = [str UTF8String];     unsigned char result[32];     CC_MD5( cStr, strlen(cStr), result );     return [NSString stringWithFormat:             @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",            result[0], result[1], result[2], result[3],             result[4], result[5], result[6], result[7],             result[8], result[9], result[10], result[11],             result[12], result[13], result[14], result[15]             ]; } #import "NSString+AESCrypt.h" NSString *strKey = @"test_AES_key";NSData *chipherData = [NSData dataWithContentsOfURL: [NSURL URLWithString: @"http://192.168.157.1/index_aes.php"]];    NSString *chipherText = [[NSString alloc] initWithData: chipherData encoding: NSUTF8StringEncoding];NSString *plainText = [chipherText AES256DecryptWithKey: [self md5: strKey]];NSLog(@"plainText: %@", plainText);

 

转载地址:https://blog.csdn.net/weixin_34377065/article/details/85530615 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:分享:玩Linux笔记(2) —— 神奇的curl工具
下一篇:(译)如何优化cocos2d程序的内存使用和程序大小:第一部分

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年04月23日 16时03分11秒