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
[CPP]View Plaincopy
- -(void) saveusernameandpwd: (NSString *) userName andpwd: (NSString *) pwd
- {
- Nsuserdefaults * settings = [Nsuserdefaults standarduserdefaults];
- [Settings removeobjectforkey:@"UserName"];
- [Settings removeobjectforkey:@"Password"];
- [Settings Setobject:username forkey:@"UserName"];
- PWD = [Aescrypt encrypt:pwd password:@"pwd"];
- [Settings setobject:pwd forkey:@"Password"];
- [Settings synchronize];
- }
[CPP]View Plaincopy
- -(NSString *) getpwd
- {
- Nsuserdefaults * settings = [Nsuserdefaults standarduserdefaults];
- NSString * temp = [Settings objectforkey:@"Password"];
- return [Aescrypt decrypt:temp password:@"pwd"];
- }
from the method name of the above two methods to know the method function, 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, save the user name and password is to place the user name and password in a local sandbox, Obtained when the encrypted file is read directly from the local, decrypted and the user data on the server to compare.
As the official sample usage, AES is very simple to use, first to add a header file #import "AESCrypt.h", using the example
[CPP]View Plaincopy
- nsstring *pwdkey = @ "Fresh air for Waves" ;
- NSString *password = @"hello123456";
- NSString *encryptedpwd = [Aescrypt encrypt:password Password:pwdkey];
- NSString *decryptedpwd = [Aescrypt decrypt:encryptedpwd Password:pwdkey];
- NSLog (@"Encrypted password:%@ after decryption password:%@", encryptedpwd,decryptedpwd);
Printing results: encrypted password:/ottra5qz5+xjhb809apla== after decryption password: hello123456
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;
[CPP]View Plaincopy
- + (NSString *) Encrypt: (NSString *) message password: (NSString *) password;
- + (NSString *) Decrypt: (NSString *) base64encodedstring Password: (NSString *) password;
iOS client learns AES encryption and decryption