iOS加密

来源:互联网 发布:锋锦网络 编辑:程序博客网 时间:2024/05/21 13:57

加密:是以某种特殊的算法改变原有的信息数据,使得未授权的用户即使获得了已经加密的信息,但因不知道解密的方法,仍然无法了解信息的内容。

1.对称加密算法 安全性从低到高
DES , 3DES, AES

AES

 NSString *message = @"top secret message"; NSString *password = @"p4ssw0rd"; NSString *encryptedData = [AESCrypt encrypt:message password:password]; NSString *decryptedData = [AESCrypt decrypt:encryptedData password:password]; NSLog(@"加密:%@", encryptedData); NSLog(@"解密:%@", decryptedData);

3DES

ER3DESEncrypt *encryptCustomKey = [[ER3DESEncrypt alloc]initWithKey:password]; NSString *encryptString = [encryptCustomKey encryptString:message]; NSString *decryptString = [encryptCustomKey decryptString:encryptString]; NSLog(@"3DES 加密:%@", encryptString);

2.非对称加密算法RSA
用公钥加密私钥解密就是加密,用私钥加密公钥解密就是签名

(1)编译openssl,生成lib和inc
(2)利用openssl,生成private_key.pem public_key.pem
(3)用JSRSA 库加密,解密

https://github.com/jslim89/RSA-objc 获取JSRSA
https://github.com/x2on/OpenSSL-for-iPhone 编译openssl

乙方生成两把密钥(公钥和私钥)。公钥是公开的,私钥是保密的。
甲方获取乙方的公钥,然后用它对信息加密。
乙方得到加密后的信息,私钥解密。
私钥 openssl genrsa -out private_key.pem 512
公钥 openssl rsa -in private_key.pem -pubout -out public_key.pem

3.MD5
MD5将任意长度的字符串映射为128bit整数,通过128bit反推原始字符串是困难的。
在原始密码中混入一个新的字符串,然后再加密。

0 0
原创粉丝点击