icon · iStig/JavaScriptCoreDemo@9bca737 · GitHub
Skip to content

Commit 9bca737

Browse files
iStigiStig
authored andcommitted
icon
1 parent 1e136f8 commit 9bca737

296 files changed

Lines changed: 58772 additions & 113 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Alipay/Util/DataSigner.h

Lines changed: 25 additions & 0 deletions

Alipay/Util/DataSigner.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// DataSigner.m
3+
// AlixPayDemo
4+
//
5+
// Created by Jing Wen on 8/2/11.
6+
// Copyright 2011 alipay.com. All rights reserved.
7+
//
8+
9+
#import "DataSigner.h"
10+
#import "RSADataSigner.h"
11+
#import "MD5DataSigner.h"
12+
13+
id<DataSigner> CreateRSADataSigner(NSString *privateKey) {
14+
15+
return [[RSADataSigner alloc] initWithPrivateKey:privateKey];
16+
17+
}

Alipay/Util/DataVerifier.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// DataVerifier.h
3+
// AlixPayDemo
4+
//
5+
// Created by Jing Wen on 8/2/11.
6+
// Copyright 2011 alipay.com. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
12+
@protocol DataVerifier
13+
14+
- (NSString *)algorithmName;
15+
- (BOOL)verifyString:(NSString *)string withSign:(NSString *)signString;
16+
17+
@end
18+
19+
id<DataVerifier> CreateRSADataVerifier(NSString *publicKey);
20+

Alipay/Util/DataVerifier.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// DataVerifier.m
3+
// AlixPayDemo
4+
//
5+
// Created by Jing Wen on 8/2/11.
6+
// Copyright 2011 alipay.com. All rights reserved.
7+
//
8+
9+
#import "DataVerifier.h"
10+
11+
12+
#import "RSADataVerifier.h"
13+
14+
id<DataVerifier> CreateRSADataVerifier(NSString *publicKey) {
15+
16+
return [[RSADataVerifier alloc] initWithPublicKey:publicKey];
17+
18+
}

Alipay/Util/MD5DataSigner.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// MD5DataSigner.h
3+
// SafepayService
4+
//
5+
// Created by wenbi on 11-4-11.
6+
// Copyright 2011 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "DataSigner.h"
11+
12+
@interface MD5DataSigner : NSObject <DataSigner> {
13+
}
14+
15+
@end

Alipay/Util/MD5DataSigner.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// MD5DataSigner.m
3+
// SafepayService
4+
//
5+
// Created by wenbi on 11-4-11.
6+
// Copyright 2011 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import "MD5DataSigner.h"
10+
11+
12+
@implementation MD5DataSigner
13+
14+
- (NSString *)algorithmName {
15+
return @"MD5";
16+
}
17+
18+
- (NSString *)signString:(NSString *)string {
19+
return @"";
20+
}
21+
22+
@end

Alipay/Util/NSDataEx.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// NSDataEx.h
3+
// iX3.0
4+
//
5+
// Created by Feng Huajun on 09-4-16.
6+
// Copyright 2009 Infothinker. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
12+
@interface NSData (NSDataBase64Additions)
13+
+ (NSData *) dataWithBase64EncodedString:(NSString *) string;
14+
- (id) initWithBase64EncodedString:(NSString *) string;
15+
16+
- (NSString *) base64Encoding;
17+
- (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength;
18+
//- (NSString*) urlEncodedString;
19+
20+
@end

Alipay/Util/NSDataEx.m

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
//
2+
// NSDataEx.m
3+
// iX3.0
4+
//
5+
// Created by Feng Huajun on 09-4-16.
6+
// Copyright 2009 Infothinker. All rights reserved.
7+
//
8+
9+
#import "NSDataEx.h"
10+
11+
static char encodingTable[64] = {
12+
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
13+
'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
14+
'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
15+
'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' };
16+
17+
@implementation NSData (NSDataBase64Additions)
18+
19+
+ (NSData *) dataWithBase64EncodedString:(NSString *) string {
20+
NSData *result = [[NSData alloc] initWithBase64EncodedString:string];
21+
return result;
22+
}
23+
24+
- (id) initWithBase64EncodedString:(NSString *) string {
25+
NSMutableData *mutableData = nil;
26+
27+
if( string ) {
28+
unsigned long ixtext = 0;
29+
unsigned long lentext = 0;
30+
unsigned char ch = 0;
31+
unsigned char inbuf[4], outbuf[3];
32+
short i = 0, ixinbuf = 0;
33+
BOOL flignore = NO;
34+
BOOL flendtext = NO;
35+
NSData *base64Data = nil;
36+
const unsigned char *base64Bytes = nil;
37+
38+
// Convert the string to ASCII data.
39+
base64Data = [string dataUsingEncoding:NSASCIIStringEncoding];
40+
base64Bytes = [base64Data bytes];
41+
mutableData = [NSMutableData dataWithCapacity:[base64Data length]];
42+
lentext = [base64Data length];
43+
44+
while( YES ) {
45+
if( ixtext >= lentext ) break;
46+
ch = base64Bytes[ixtext++];
47+
flignore = NO;
48+
49+
if( ( ch >= 'A' ) && ( ch <= 'Z' ) ) ch = ch - 'A';
50+
else if( ( ch >= 'a' ) && ( ch <= 'z' ) ) ch = ch - 'a' + 26;
51+
else if( ( ch >= '0' ) && ( ch <= '9' ) ) ch = ch - '0' + 52;
52+
else if( ch == '+' ) ch = 62;
53+
else if( ch == '=' ) flendtext = YES;
54+
else if( ch == '/' ) ch = 63;
55+
else flignore = YES;
56+
57+
if( ! flignore ) {
58+
short ctcharsinbuf = 3;
59+
BOOL flbreak = NO;
60+
61+
if( flendtext ) {
62+
if( ! ixinbuf ) break;
63+
if( ( ixinbuf == 1 ) || ( ixinbuf == 2 ) ) ctcharsinbuf = 1;
64+
else ctcharsinbuf = 2;
65+
ixinbuf = 3;
66+
flbreak = YES;
67+
}
68+
69+
inbuf [ixinbuf++] = ch;
70+
71+
if( ixinbuf == 4 ) {
72+
ixinbuf = 0;
73+
outbuf [0] = ( inbuf[0] << 2 ) | ( ( inbuf[1] & 0x30) >> 4 );
74+
outbuf [1] = ( ( inbuf[1] & 0x0F ) << 4 ) | ( ( inbuf[2] & 0x3C ) >> 2 );
75+
outbuf [2] = ( ( inbuf[2] & 0x03 ) << 6 ) | ( inbuf[3] & 0x3F );
76+
77+
for( i = 0; i < ctcharsinbuf; i++ )
78+
[mutableData appendBytes:&outbuf[i] length:1];
79+
}
80+
81+
if( flbreak ) break;
82+
}
83+
}
84+
}
85+
86+
self = [self initWithData:mutableData];
87+
return self;
88+
}
89+
90+
#pragma mark -
91+
92+
- (NSString *) base64Encoding {
93+
return [self base64EncodingWithLineLength:0];
94+
}
95+
96+
- (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength {
97+
const unsigned char *bytes = [self bytes];
98+
NSMutableString *result = [NSMutableString stringWithCapacity:[self length]];
99+
unsigned long ixtext = 0;
100+
unsigned long lentext = [self length];
101+
long ctremaining = 0;
102+
unsigned char inbuf[3], outbuf[4];
103+
short i = 0;
104+
short charsonline = 0, ctcopy = 0;
105+
unsigned long ix = 0;
106+
107+
while( YES ) {
108+
ctremaining = lentext - ixtext;
109+
if( ctremaining <= 0 ) break;
110+
111+
for( i = 0; i < 3; i++ ) {
112+
ix = ixtext + i;
113+
if( ix < lentext ) inbuf[i] = bytes[ix];
114+
else inbuf [i] = 0;
115+
}
116+
117+
outbuf [0] = (inbuf [0] & 0xFC) >> 2;
118+
outbuf [1] = ((inbuf [0] & 0x03) << 4) | ((inbuf [1] & 0xF0) >> 4);
119+
outbuf [2] = ((inbuf [1] & 0x0F) << 2) | ((inbuf [2] & 0xC0) >> 6);
120+
outbuf [3] = inbuf [2] & 0x3F;
121+
ctcopy = 4;
122+
123+
switch( ctremaining ) {
124+
case 1:
125+
ctcopy = 2;
126+
break;
127+
case 2:
128+
ctcopy = 3;
129+
break;
130+
}
131+
132+
for( i = 0; i < ctcopy; i++ )
133+
[result appendFormat:@"%c", encodingTable[outbuf[i]]];
134+
135+
for( i = ctcopy; i < 4; i++ )
136+
[result appendFormat:@"%c",'='];
137+
138+
ixtext += 3;
139+
charsonline += 4;
140+
141+
if( lineLength > 0 ) {
142+
if (charsonline >= lineLength) {
143+
charsonline = 0;
144+
[result appendString:@"\n"];
145+
}
146+
}
147+
}
148+
149+
return result;
150+
}
151+
152+
153+
154+
//- (NSString*) urlEncodedString
155+
//{
156+
// char *hex = "0123456789ABCDEF";
157+
// unsigned char* data = (unsigned char*)[self bytes];
158+
// int len = [self length];
159+
// //NSLog(@"len = %d", len);
160+
// NSMutableString* s = [NSMutableString string];
161+
// for(int i = 0;i<len;i++){
162+
// unsigned char c = data[i];
163+
// if( ('a' <= c && c <= 'z')
164+
// || ('A' <= c && c <= 'Z')
165+
// || ('0' <= c && c <= '9') ){
166+
// NSString* ts = [[NSString alloc] initWithCString:(char *)&c length:1];
167+
//
168+
// [s appendString:ts];
169+
// [ts release];
170+
// } else {
171+
// [s appendString:@"%"];
172+
// char ts1 = hex[c >> 4];
173+
// // NSLog(@"ts = %c", ts1);
174+
// NSString* ts = [[NSString alloc] initWithCString:&ts1 length:1];
175+
// [s appendString:ts];
176+
// [ts release];
177+
// char ts2 = hex[c & 15];
178+
// ts = [[NSString alloc] initWithCString:&ts2 length:1];
179+
// [s appendString:ts];
180+
// [ts release];
181+
//
182+
// }
183+
// }
184+
// return s;
185+
//}
186+
187+
@end

Alipay/Util/RSADataSigner.h

Lines changed: 18 additions & 0 deletions

0 commit comments

Comments
 (0)