资源简介
objective-c实现authCode 解决php与ios通信加密的问题
代码片段和文件信息
#import “base64.h“
#import
#import
#if !__has_feature(objc_arc)
#error This library requires automatic reference counting
#endif
@implementation NSData (base64)
+ (NSData *)dataWithbase64EncodedString:(NSString *)string
{
const char lookup[] =
{
99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99
99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99
99 99 99 99 99 99 99 99 99 99 99 62 99 99 99 63
52 53 54 55 56 57 58 59 60 61 99 99 99 99 99 99
99 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
15 16 17 18 19 20 21 22 23 24 25 99 99 99 99 99
99 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50 51 99 99 99 99 99
};
NSData *inputData = [string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
long long inputLength = [inputData length];
const unsigned char *inputBytes = [inputData bytes];
long long maxOutputLength = (inputLength / 4 + 1) * 3;
NSMutableData *outputData = [NSMutableData dataWithLength:maxOutputLength];
unsigned char *outputBytes = (unsigned char *)[outputData mutableBytes];
int accumulator = 0;
long long outputLength = 0;
unsigned char accumulated[] = {0 0 0 0};
for (long long i = 0; i < inputLength; i++)
{
unsigned char decoded = lookup[inputBytes[i] & 0x7F];
if (decoded != 99)
{
accumulated[accumulator] = decoded;
if (accumulator == 3)
{
outputBytes[outputLength++] = (accumulated[0] << 2) | (accumulated[1] >> 4);
outputBytes[outputLength++] = (accumulated[1] << 4) | (accumulated[2] >> 2);
outputBytes[outputLength++] = (accumulated[2] << 6) | accumulated[3];
}
accumulator = (accumulator + 1) % 4;
}
}
//handle left-over data
if (accumulator > 0) outputBytes[outputLength] = (accumulated[0] << 2) | (accumulated[1] >> 4);
if (accumulator > 1) outputBytes[++outputLength] = (accumulated[1] << 4) | (accumulated[2] >> 2);
if (accumulator > 2) outputLength++;
//truncate data to match actual output length
outputData.length = outputLength;
return outputLength? outputData: nil;
}
- (NSString *)base64EncodedStringWithWrapWidth:(NSUInteger)wrapWidth
{
//ensure wrapWidth is a multiple of 4
wrapWidth = (wrapWidth / 4) * 4;
const char lookup[] = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/“;
long long inputLength = [self length];
const unsigned char *inputBytes = [self bytes];
long long maxOutputLength = (inputLength / 3 + 1) * 4;
maxOutputLength += wrapWidth? (maxOutputLength / wrapWidth) * 2: 0;
unsigned char *outputBytes = (unsigned char *)malloc(maxOutputLength);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-03-05 11:44 authCode\
文件 6148 2015-03-05 11:44 authCode\.DS_Store
目录 0 2015-03-05 11:49 __MACOSX\
目录 0 2015-03-05 11:49 __MACOSX\authCode\
文件 120 2015-03-05 11:44 __MACOSX\authCode\._.DS_Store
目录 0 2015-03-05 11:45 authCode\ios\
文件 6148 2015-03-05 11:48 authCode\ios\.DS_Store
目录 0 2015-03-05 11:49 __MACOSX\authCode\ios\
文件 120 2015-03-05 11:48 __MACOSX\authCode\ios\._.DS_Store
文件 549 2015-03-05 11:45 authCode\ios\ba
文件 171 2015-03-05 11:45 __MACOSX\authCode\ios\._ba
文件 9673 2015-03-05 11:45 authCode\ios\ba
文件 171 2015-03-05 11:45 __MACOSX\authCode\ios\._ba
文件 75 2015-03-05 11:48 authCode\ios\ViewController.h
文件 171 2015-03-05 11:48 __MACOSX\authCode\ios\._ViewController.h
文件 857 2015-03-05 11:48 authCode\ios\ViewController.m
文件 171 2015-03-05 11:48 __MACOSX\authCode\ios\._ViewController.m
目录 0 2015-03-05 11:44 authCode\php\
文件 6148 2015-03-05 11:44 authCode\php\.DS_Store
目录 0 2015-03-05 11:49 __MACOSX\authCode\php\
文件 120 2015-03-05 11:44 __MACOSX\authCode\php\._.DS_Store
文件 1713 2015-03-05 11:43 authCode\php\test.php
文件 171 2015-03-05 11:43 __MACOSX\authCode\php\._test.php
相关资源
- 校园疫情防控进出登记管理系统THIN
- 手写签名,PHP +js+html5
- 学籍管理系统(php源码+mysql数据库)
- 新闻管理系统(原生php源码)
- php图书管理系统源码(附数据库)
- php文章管理系统源码(附数据库)
- PHP图书馆管理系统(源码 数据库脚本
- PHP考试答题系统
- 基于PHP的学生管理系统(优雅版)
- PHP物品管理系统
- php新闻管理系统源码
- resetful框架
- PHP免杀大马-过D盾过安全狗WAF免杀ph
- 友邻B2B系统(PHPB2B) 5.0.2 UTF-8
- 新型冠状病毒肺炎疫情实时图PHP源码
- PHP调用企业微信API接口底层类库
- 基于PHP的统一检索系统的设计与实现
- PHP版本的网络打印机提交打印代码
- conefor操作(Manual_Conefor_26)
- php Goto解密
- PHP大转盘抽奖
- php模拟文件上传(socket_upload.php)
- php连接mysql实现界面crud(附数据库文
- php在线相册(附数据库脚本)
- PHP在线人数统计
- php+Ajax无刷新分页列表
- PHP失物招领
- php 随机生成颜色
- php-redis中文帮助手册.chm
- php远程控制脚本
评论
共有 条评论