objective-c 中文加密,再解密乱码
//加密
NSData *plain = [texUid.text dataUsingEncoding:NSUTF8StringEncoding];
NSData *eData = [plain AES256EncryptWithKey:key];
NSString *secretString = [eData base64EncodedString];
NSLog(@"encrypted string:%@",secretString);
//解密
NSString *enString = [NSString stringWithString:secretString];
NSData *cipher = [NSData dataFromBase64String:enString];
NSData *bDecrypt = [cipher AES256DecryptWithKey:key];
NSString *dateString = [[NSString alloc] initWithData:bDecrypt encoding:NSASCIIStringEncoding];
NSLog(@"decrypted string:%@",dateString); //解出来的中文是乱码,高人指点谢谢
[解决办法]
加密的数据使用的编码格式:NSUTF8StringEncoding
解密的数据使用的编码格式:NSASCIIStringEncoding