IOS --- sha1 Encryption
The sha1 encryption algorithm written in the OC language can be searched on the Internet at Will (as shown below), but I have to say that some people are not responsible and did not remind everyone to import necessary system header files, this leads to errors.
+ (NSString *) sha1 :( NSString *) inputStr {
Const char * cstr = [inputStr cStringUsingEncoding: NSUTF8StringEncoding];
NSData * data = [NSData dataWithBytes: cstr length: input. length];
Uint8_t digest [CC_SHA1_DIGEST_LENGTH];
CC_SHA1 (data. bytes, (unsigned int) data. length, digest );
NSMutableString * outputStr = [NSMutableString stringWithCapacity: CC_SHA1_DIGEST_LENGTH * 2];
For (int I = 0; I
[OutputStr appendFormat: @ % 02x, digest [I];
}
Return outputStr;
}
Before using the sha1 encryption algorithm, we need to # import
Hope that the majority of bloggers can write more carefully in the future. Thank you!
In addition to sha1, there are also md5, or their combination with base64! This is commonly used, and of course there are many better!