Problem:
When I log on as a user, the background API requires the MD5 encrypted student ID and the string that the request time is merged, so I found an encrypted framework on GitHub with the link: https: // github. (NIU) com/paulery2014/CocoaSecurity. I wrote a small Demo for your convenience.
Usage:
Download the CocoaSecurity framework to the local machine, import the four files of Base64 and CocoaSecurity, and then import the header file "CocoaSecurity. h" in the. m file to be called.
Various encryption methods:
// Signature algorithm (MD5, SHA1, HMAC)
// string MD5 encryption
CocoaSecurityResult *result_md5 = [CocoaSecurity md5:@"liuxiaofei_md5"];
// string SHA1 encryption
CocoaSecurityResult *result_sha1 = [CocoaSecurity sha1:@"liuxiaofei_sha1"];
// String SHA256 encryption
CocoaSecurityResult *result_sha256 = [CocoaSecurity sha256:@"liuxiaofei_sha256"];
// Print hash (md5, sha1, sha256) encrypted character difference
NSLog (@"MD5 encrypted string is hex:%@", result_md5.hex);
NSLog (@"MD5 encrypted string is hexLower:%@", result_md5.hexLower);
NSLog (@"MD5 encrypted string is base64:%@", result_md5.base64);
NSLog (@"SHA1 encrypted string is hex:%@", result_sha1.hex);
NSLog (@"SHA1 encrypted string is hexLower:%@", result_sha1.hexLower);
NSLog (@"SHA1 encrypted string is base64:%@", result_sha1.base64);
NSLog (@"SHA256 encrypted string is hex:%@", result_sha256.hex);
NSLog (@"SHA256 encrypted string is hexLower:%@", result_sha256.hexLower);
NSLog (@"SHA256 encrypted string is base64:%@", result_sha256.base64);
// Symmetric encryption algorithm (3DS, AES)
/*AES encryption:
*Advanced encryption standard
* is the next generation encryption algorithm standard, fast, high security level
* One implementation of the AES standard is the Rijndael algorithm
*/
CocoaSecurityResult *result_AES = [CocoaSecurity aesEncrypt:@"liuxiaofei" key:@"testKey"];
NSLog (@"AES encrypted string: %@", result_AES.hex);
NSLog (@"AES encrypted string: %@", result_AES.hexLower);
NSLog (@"AES encrypted string: %@", result_AES.base64);
// asymmetric encryption algorithm (small data volume)
// RSA....blablabla