zoukankan      html  css  js  c++  java
  • 使用3DES+Base64来加密传输iOS应用数据

    本文转载至 http://www.erblah.com/post/objective-c/shi-yong-3des-base64lai-jia-mi-chuan-shu-iosying-yong-shu-ju

    app与服务端进行数据传输有时需要加密,以免出现某知名新闻客户端密码只是md5一下就往服务器post的窘况...

    ios加密的情况有三种:1.https 2.对称加密 3.非对称加密,因为种种原因,在一个应用中用到了3DES对称加密(据说AES更好),感觉挺方便的。

    代码做了一些整理,提供了object和NSString+Category两种实现方式,同时附server端的加密和解密的代码(php实现),有需要的同学可以拿去用。
    Github地址:ER3DESEncryptAndServer

    使用说明

    ER3DESEncryptAndServer

    useage

    • use ER3DESEncrypt
    #import "ER3DESEncrypt.h"
    ...
    NSString *orig = @"erblah.com", *encryptString, *decryptString, *key = @"I love you.";
    
    //default key: abcd12345678901234567890
    ER3DESEncrypt *encryptDefaultKey = [[ER3DESEncrypt alloc] init];
    
    encryptString = [encryptDefaultKey encryptString:orig];
    decryptString = [encryptDefaultKey decryptString:encryptString];
    NSLog(@"key:%@
    %@ --- %@ --- %@",encryptDefaultKey.encryptKey, 
                                orig, encryptString, decryptString);
    
    
    //custom key
    ER3DESEncrypt *encryptCustomKey = [[ER3DESEncrypt alloc] initWithKey:key];
    
    encryptString = [encryptCustomKey encryptString:orig];
    decryptString = [encryptCustomKey decryptString:encryptString];
    NSLog(@"key:%@
    %@ --- %@ --- %@",encryptDefaultKey.encryptKey, 
                                    orig, encryptString, decryptString);
    
    • 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:%@
    %@ --- %@ --- %@", key, orig, encryptString, decryptString);
    
    • Server (php)

      ^_^ , open Crypt3Des.php ...

  • 相关阅读:
    The Triangle_DP
    LITTLE SHOP OF FLOWERS_DP
    K Best(最大化平均数)_二分搜索
    Number Game_状态压缩
    Stockbroker Grapevine_Floyd
    A very hard Aoshu problem
    AOE 网络
    AOV网
    最小生成树
    [POJ] 1562 Oil Deposits (DFS)
  • 原文地址:https://www.cnblogs.com/Camier-myNiuer/p/4192337.html
Copyright © 2011-2022 走看看