OC Language write SHA1 encryption algorithm, can be found on the Internet (such as the following), but I have to say that some people are not responsible, not to remind you to import the necessary system header files. resulting in errors
+ (nsstring *) SHA1: ( NSString *) Inputstr {
constchar *cstr = [inputstr cstringusingencoding: nsutf8stringencoding];
nsdata *data = [nsdatadatawithbytes: CStr length : input. length ];
uint8_t digest[cc_sha1_digest_length];
cc_sha1(data. bytes , (unsignedint) data. length , digest);
nsmutablestring *outputstr = [nsmutablestring Stringwithcapacity:cc_sha1_digest_length *2];
for (int i=0; i<cc_sha1_digest_length ; i++) {
[outputstr appendformat:@ "%02x", Digest[i]];
}
return outputstr;
}
before using the SHA1 encryption algorithm, we need to #import <CommonCrypto/CommonDigest.h>
Hope that the vast number of blog enthusiasts, later can not write a little more careful, thank you!
In addition to SHA1, there are MD5, or their combination with Base64! This is often used, and of course there are very many better!
IOS---SHA1 encryption of a pit