BASE64 uses commonly used URL ciphertext encoding to pass longer identity information in an HTTP environment. The adoption of BASE64 encoding is not only shorter but also unreadable.
The following address is the encrypted Thunderbolt dedicated download address, using the code.
such as thunder://qufodhrwoi8vd3d3lmjhawr1lmnvbs9pbwcvc3nsbtffbg9nby5nawzawg==
The method of encrypting and decrypting using BASE64 in iOS is also very simple and can be realized directly with Google-toolbox-for-mac GTMBase64.h.
The corresponding address of the GOOGLE-TOOLBOX-FOR-MAC is as follows:
http://code.google.com/p/google-toolbox-for-mac/
You can find a lot of the help you need, but here we only use the following 3 files
GTMDefines.h
GTMBase64.h
Gtmbase64.m
Download Address
http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation/?r=87
The use of the following methods:
Encryption:
The code is as follows |
Copy Code |
[[NSString Alloc] initwithdata:[gtmbase64 Encodedata:datatoencode] Encoding:nsutf8stringencoding];
|
Decrypt:
The code is as follows |
Copy Code |
[[NSString Alloc] initwithdata:[gtmbase64 Decodestring:datatodecode] Encoding:nsutf8stringencoding]; |
Combine the previous MD5 and SHA1 results to use:
The code is as follows |
Copy Code |
-(NSString *) sha1_base64 { const char *CSTR = [self cstringusingencoding:nsutf8stringencoding]; NSData *data = [NSData datawithbytes:cstr length:self.length];
uint8_t Digest[cc_sha1_digest_length];
CC_SHA1 (Data.bytes, Data.length, Digest);
NSData * base64 = [[NSData alloc]initwithbytes:digest length:cc_sha1_digest_length]; Base64 = [GTMBase64 encodedata:base64];
NSString * output = [[NSString alloc] initwithdata:base64 encoding:nsutf8stringencoding]; return output; }
-(NSString *) md5_base64 { const char *CSTR = [self utf8string]; unsigned char digest[cc_md5_digest_length]; CC_MD5 (CStr, strlen (CStr), Digest);
NSData * base64 = [[NSData alloc]initwithbytes:digest length:cc_md5_digest_length]; Base64 = [GTMBase64 encodedata:base64];
NSString * output = [[NSString alloc] initwithdata:base64 encoding:nsutf8stringencoding]; return output; } |