this article reprinted to Http://www.erblah.com/post/objective-c/shi-yong-3des-base64lai-jia-mi-chuan-shu-iosying-yong-shu-ju app and server data transmission sometimes need to encrypt, in order to avoid a well-known news client password just MD5 a bit to the predicament of the post ...
There are three types of iOS encryption: 1.https 2. Symmetric encryption 3. Asymmetric encryption, for various reasons, the use of 3DES symmetric encryption in one application (said AES better), feel very convenient.
The code has done some tidying up, providing two implementations of object and Nsstring+category, along with the server-side encryption and decryption Code (PHP implementation), the needs of students can be used.
GitHub Address: Er3desencryptandserver
Instructions for use Er3desencryptandserveruseage
#import "ER3DESEncrypt.h"...NSString*Orig=@ "Erblah.com",*EncryptString,*Decryptstring,*Key=@ "I love you.";Default key:abcd12345678901234567890Er3desencrypt*Encryptdefaultkey=[[Er3desencryptAlloc]Init];EncryptString=[EncryptdefaultkeyEncryptString:Orig];Decryptstring=[EncryptdefaultkeyDecryptstring:EncryptString];NSLog(@ "key:%@\ n%@ --- %@ --- %@",Encryptdefaultkey.Encryptkey,Orig,EncryptString,Decryptstring);Custom keyEr3desencrypt*Encryptcustomkey=[[Er3desencryptAlloc]Initwithkey:Key; encryptstring = [encryptcustomkey encryptstring:orig]; decryptstring = [encryptcustomkey decryptString< Span class= "o" >:encryptstring]; Nslog (@ "Key:%@\n%@---%@---%@" , encryptdefaultkey. Encryptkeyorigencryptstringdecryptstring
- Use Category (nsstring+encrypt3desandbase64)
#import "Nsstring+encrypt3desandbase64.h"...NSString*Orig=@ "Erblah.com",*EncryptString,*Decryptstring,*key = @ "I Love you." encryptstring = [orig Encryptstringwithkey:key]; decryptstring = [encryptstring Decryptstringwithkey:key]; Nslog (@ "Key:%@\n%@---%@---%@" , keyorigencryptstringdecryptstring
Use 3des+base64 to encrypt the transfer of iOS app data