iOS里加密字符串、图片、视频方法
2013-02-03 12:43
387 查看
iOS里加密字符串、图片、视频方法
1、使用GTMBase64编码解码字符串
2、编解码函数(可以编解码字符串、图片、视频:filePath换成相应的即可):
从模拟器和真机的Documents路径下读取文件,编码后写入文件;读出来解码
// 加密函数
-(void)func_encodeFile
{
//NSString *path = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/test.png"];
NSString *filePath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/iphone4.mov"];
//文件路径转换为NSData
NSData *imageDataOrigin = [NSData dataWithContentsOfFile:filePath];
// 对前1000位进行异或处理
unsigned char * cByte = (unsigned char*)[imageDataOrigin bytes];
for (int index = 0; (index < [imageDataOrigin length]) && (index < 1000);
index++, cByte++)
{
*cByte = (*cByte) ^ arrayForEncode[index];
}
//对NSData进行base64编码
NSData *imageDataEncode = [GTMBase64 encodeData:imageDataOrigin];
[imageDataEncode writeToFile:filePath atomically:YES];
}
// 解密函数
-(void)func_decodeFile
{
//NSString *filePath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/test.png"];
NSString *filePath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/iphone4.mov"];
// 读取被加密文件对应的数据
NSData *dataEncoded = [NSData dataWithContentsOfFile:filePath];
// 对NSData进行base64解码
NSData *dataDecode = [GTMBase64 decodeData:dataEncoded];
// 对前1000位进行异或处理
unsigned char * cByte = (unsigned char*)[dataDecode bytes];
for (int index = 0; (index < [dataDecode length]) && (index < 10);
index++, cByte++)
{
*cByte = (*cByte) ^ arrayForEncode[index];
}
[dataDecode writeToFile:filePath atomically:YES];
}
1、使用GTMBase64编码解码字符串
GTMDefines.h GTMBase64.h GTMBase64.m 你可以在这里找到这三个文件(GTMDefines.h在第二页,点击右上角的next按钮即可跳转到第二页)http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation/?r=87
2、编解码函数(可以编解码字符串、图片、视频:filePath换成相应的即可):
从模拟器和真机的Documents路径下读取文件,编码后写入文件;读出来解码
// 加密函数
-(void)func_encodeFile
{
//NSString *path = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/test.png"];
NSString *filePath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/iphone4.mov"];
//文件路径转换为NSData
NSData *imageDataOrigin = [NSData dataWithContentsOfFile:filePath];
// 对前1000位进行异或处理
unsigned char * cByte = (unsigned char*)[imageDataOrigin bytes];
for (int index = 0; (index < [imageDataOrigin length]) && (index < 1000);
index++, cByte++)
{
*cByte = (*cByte) ^ arrayForEncode[index];
}
//对NSData进行base64编码
NSData *imageDataEncode = [GTMBase64 encodeData:imageDataOrigin];
[imageDataEncode writeToFile:filePath atomically:YES];
}
// 解密函数
-(void)func_decodeFile
{
//NSString *filePath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/test.png"];
NSString *filePath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/iphone4.mov"];
// 读取被加密文件对应的数据
NSData *dataEncoded = [NSData dataWithContentsOfFile:filePath];
// 对NSData进行base64解码
NSData *dataDecode = [GTMBase64 decodeData:dataEncoded];
// 对前1000位进行异或处理
unsigned char * cByte = (unsigned char*)[dataDecode bytes];
for (int index = 0; (index < [dataDecode length]) && (index < 10);
index++, cByte++)
{
*cByte = (*cByte) ^ arrayForEncode[index];
}
[dataDecode writeToFile:filePath atomically:YES];
}
相关文章推荐
- iOS里加密字符串、图片、视频方法
- iOS里加密字符串、图片、视频方法
- iOS里加密字符串、图片、视频方法
- iO里加密字符串、图片、视频方法
- 一种简便的ios图片加密方法-对图片进行base64编码
- IOS获取视频每一帧的图片方法
- 一种简便的ios图片加密方法-对图片进行base64编码
- 一种简便的ios图片加密方法-对图片进行base64编码
- iOS图片转成视频方法
- IOS中替换一张图片背景颜色的方法
- IOS开发获取图片的方法
- ios中摄像头/相册获取图片,压缩图片,上传服务器方法总结
- iOS系统方法挑选图片
- iOS里常见的几种信息编码、加密方法简单总结
- iOS学习笔记-- 加载图片选择imageNamed 方法还是 imageWithContentsOfFile
- iOS截取视频缩略图的两种方法
- ios学习--MPMoviePlayerController播放视频的方法
- 移动端图片上传方法【更好的兼容安卓IOS和微信】 推荐
- iOS开发之字符串(NSString)的截取的几种方法
- iOS选取相册中iCloud云上图片和视频的处理