iOS的AES加解密

iOS的AES加解密,第1张

概述iOS的AES加解密

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

    //      //  VIEwController.m      //  test      //      //  Created by yons on 14-8-7.      //  copyright (c) 2014年 yons. All rights reserved.      //            #import "VIEwController.h"      #import "tableVIEwController.h"      #import "SecurityUtil.h"      #import "GTMBase64.h"            #define KEY @"ABCDEFGHIJKLMnop" //key可修改            @interface VIEwController ()      {          UIbutton *encryption;          UIbutton *decrypt;          UITextFIEld *content;                    UILabel *Before;          UILabel *after;          UILabel *key;      }            @end                        @implementation VIEwController            - (voID)vIEwDIDLoad      {          [super vIEwDIDLoad];          // Do any additional setup after loading the vIEw,typically from a nib.                    self.vIEw.backgroundcolor = [UIcolor whitecolor];                    content = [[UITextFIEld alloc] initWithFrame:CGRectMake(20,60,280,40)];          content.backgroundcolor = [UIcolor whitecolor];          [self setborder:content.layer];          content.placeholder = @" 请输入加密或解密的字符串";                   [self.vIEw addSubvIEw:content];                     encryption = [[UIbutton alloc] initWithFrame:CGRectMake(60,125,80,40)];          [encryption setTitle:@"加密" forState:UIControlStatenormal] ;          encryption.backgroundcolor = [UIcolor blackcolor];          [encryption addTarget:self action:@selector(Encryption) forControlEvents:UIControlEventtouchUpInsIDe];          [self.vIEw addSubvIEw:encryption];                     decrypt = [[UIbutton alloc] initWithFrame:CGRectMake(175,40)];          [decrypt setTitle:@"解密" forState:UIControlStatenormal] ;           decrypt.backgroundcolor = [UIcolor blackcolor];          [decrypt addTarget:self action:@selector(Decrypt) forControlEvents:UIControlEventtouchUpInsIDe];          [self.vIEw addSubvIEw:decrypt];                    key = [[UILabel alloc] initWithFrame:CGRectMake(20,190,290,20)];          Before = [[UILabel alloc] initWithFrame:CGRectMake(20,220,40)];          Before.lineBreakMode = YES;          Before.numberOflines = 0;                   after = [[UILabel alloc] initWithFrame:CGRectMake(20,270,40)];          after.lineBreakMode = YES;          after.numberOflines = 0;                    [key set@R_404_6837@:[UI@R_404_6837@ @R_404_6837@Withname:@"Arial" size:14]];          [Before set@R_404_6837@:[UI@R_404_6837@ @R_404_6837@Withname:@"Arial" size:14]];          [after set@R_404_6837@:[UI@R_404_6837@ @R_404_6837@Withname:@"Arial" size:14]];                    [self.vIEw addSubvIEw:key];          [self.vIEw addSubvIEw:Before];          [self.vIEw addSubvIEw:after];      }            // 加边框      - (voID) setborder: (CALayer*) layer      {          [layer setMasksToBounds:YES];          [layer setCornerRadius:5.0]; //设置矩圆角半径          [layer setborderWIDth:0.7];   //边框宽度          [layer setbordercolor:[[UIcolor lightGraycolor] CGcolor]];      }            //加密      - (voID) Encryption      {          if ([content.text isEqualToString:@""])          {              UIAlertVIEw *alert = [[UIAlertVIEw alloc] initWithTitle:@"温馨提示!" message:@"亲,你还没有输入任何内容!" delegate:self cancelbuttonTitle:@"确 定" otherbuttonTitles:nil,nil nil];              [alert show];          }          else          {              Nsstring *string = [SecurityUtil encryptAESData:content.text app_key:KEY];              key.text = [Nsstring stringWithFormat:@"加密key:%@",KEY];              Before.text = [Nsstring stringWithFormat:@"加密前:%@",content.text];              after.text = [Nsstring stringWithFormat:@"加密后:%@",string];                            NSLog(@"string:%@",string);          }               }            //解密      - (voID) Decrypt      {          if ([content.text isEqualToString:@""])          {              UIAlertVIEw *alert = [[UIAlertVIEw alloc] initWithTitle:@"温馨提示!" message:@"亲,你还没有输入任何内容!" delegate:self cancelbuttonTitle:@"确 定" otherbuttonTitles:nil,nil nil];              [alert show];          }          else          {              NSData *EncryptData = [GTMBase64 decodeString:content.text]; //解密前进行GTMBase64编码              Nsstring * string = [SecurityUtil decryptAESData:EncryptData app_key:KEY];                            key.text = [Nsstring stringWithFormat:@"解密key:%@",KEY];              Before.text = [Nsstring stringWithFormat:@"解密前:%@",content.text];                            if ([string isEqualToString:@""] | [string isEqualToString:nil]) {                  string = @"解密失败,亲,请输入加密后的字符串!";              }              after.text = [Nsstring stringWithFormat:@"解密后:%@",string);          }      }                  - (voID)dIDReceiveMemoryWarning      {          [super dIDReceiveMemoryWarning];          // dispose of any resources that can be recreated.      }            @end  

最后附上Demo的下载地址:AES加解密Demo(点击下载)

来自:http://blog.csdn.net/by3g123/article/details/44617201

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的iOS的AES加解密全部内容,希望文章能够帮你解决iOS的AES加解密所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1106956.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存