Data encryption plays an important role in the software development process, and some companies may have their own internal design algorithms when encrypting, and in this regard do not want to waste too much effort to consider using third-party provided encryption algorithm, such as AES encryption algorithm, This article describes the open source Chinese iOS client using the ASE algorithm encryption password;
AES GitHub Https://github.com/Gurpartap/AESCrypt-ObjC
For a larger project we may not know where a class library or method is used, but the smart Xcode provides us with a global search function that we can search for in the whole project. For example, I don't know where AES is used, but if you use this class library It will definitely refer to its header file, we search for Aescrypt
Then in addition to the class library itself only the Config class contains AESCrpt.h, only two methods used, jump to config.m in the two methods
View Sourceprint?
01.
-(
void
)saveUserNameAndPwd:(NSString *)userName andPwd:(NSString *)pwd
02.
{
03.
NSUserDefaults * settings = [NSUserDefaults standardUserDefaults];
04.
[settings removeObjectForKey:@
"UserName"
];
05.
[settings removeObjectForKey:@
"Pass<a href="
http:
//www.it165.net/edu/ebg/" target="_blank" class="keylink">word</a>"];
06.
[settings setObject:userName forKey:@
"UserName"
];
07.
08.
pwd = [AESCrypt encrypt:pwd pass<a href=
"http://www.it165.net/edu/ebg/"
target=
"_blank"
class
=
"keylink"
>word</a>:@
"pwd"
];
09.
10.
[settings setObject:pwd forKey:@
"Password"
];
11.
[settings synchronize];
12.
}
From the method name of the above two methods to know the role of the method, one is to save the user name and password, the password using AES encryption, the other is to decrypt the password and then return this password, the user name and password is stored in a local sandbox only, get the time to read the encrypted file directly from the local, After decryption and user data on the server to compare (want to know the open source China iOS client user login process; www.it165.net
As the official sample usage, AES is very simple to use, first to add a header file #import "AESCrypt.h", using the example
View Sourceprint?
1.
NSString *pwdKey = @
"新风作浪"
;
2.
NSString *password = @
"duxinfeng123456"
;
3.
NSString *encryptedPWD = [AESCrypt encrypt:password password:pwdKey];
4.
NSString *decryptedPWD = [AESCrypt decrypt:encryptedPWD password:pwdKey];
5.
NSLog(@
"加密后密码:%@ 解密后密码: %@"
,encryptedPWD,decryptedPWD);
Printing results: Encrypted password:/ottra5qz5+xjhb809apla== after decryption password: duxinfeng123456
Cryptographic decryption method function prototype, the two parameters passed the first is the encrypted data, the second is the key to encrypt the data, the decryption time also need this key to decrypt the encrypted data
View Sourceprint?
1.
+ (NSString *)encrypt:(NSString *)message password:(NSString *)password;
2.
+ (NSString *)decrypt:(NSString *)base64EncodedString password:(NSString *)password;
Http://www.it165.net/pro/html/201305/5894.html
AES encryption for iOS client learning