iOS中使用RNCryptor对资源文件加密

原文:http://blog.csdn.net/chenpolu/article/details/46277587

RNCryptor源码https://github.com/RNCryptor/RNCryptor。 
基于RNCryptor我做了一个小工具,用来对资源文件先进行加密。(CXYRNCryptorTool) 
截图

加密后文件看起来是这样的: 
res

接着就可以把这些文件导入我们的项目工程(就和以前导入图片一样)。 

最后,就是对这些资源进行解密: (下面代码对01.cxy资源解密)

 1 NSData *encryptedData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"01.cxy" ofType:nil]];
 2 
 3     NSError *error;
 4     NSData *decryptedData = [RNDecryptor decryptData:encryptedData
 5                                         withPassword:@"pwdcxy"
 6                                                error:&error];
 7     if (!error) {
 8         NSLog(@"======dencrypt success!=====");
 9         UIImage *image = [UIImage imageWithData:decryptedData];
10         _imageView.image = image;
11 
12     }

注意:解密密码一定要和加密时一致。

原文地址:https://www.cnblogs.com/qq744890760/p/5073151.html