Commit 047ef592 by pierce

1、添加统计接口

2、添加字符串解码
parent 675b4f04
...@@ -225,7 +225,7 @@ ...@@ -225,7 +225,7 @@
NSArray *postDatas = [self.postJsonList copy]; NSArray *postDatas = [self.postJsonList copy];
[self.postJsonList removeAllObjects]; [self.postJsonList removeAllObjects];
[FUSHttpHelper postRequestJsonWithUrl:@"/stat/ios/json/data" [FUSHttpHelper postRequestBinaryWithUrl:@"/stat/ios/json/data"
params:@{@"json":postDatas.description} params:@{@"json":postDatas.description}
success:nil success:nil
failure:nil]; failure:nil];
......
...@@ -8,8 +8,20 @@ ...@@ -8,8 +8,20 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@interface FUSStringDecoderHelper : NSObject
/// 解码后的key
@property (nonatomic, copy) NSString *decodeKey;
/// 解码后的字符串缓存
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *decodeStrDict;
@end
@interface NSString (MD5) @interface NSString (MD5)
- (NSString *)fus_decodeAESStr;
/** /**
* 获取MD5字符串 * 获取MD5字符串
*/ */
...@@ -21,5 +33,4 @@ ...@@ -21,5 +33,4 @@
*/ */
+ (NSString *)md5String:(NSString *)str; + (NSString *)md5String:(NSString *)str;
@end @end
...@@ -8,9 +8,55 @@ ...@@ -8,9 +8,55 @@
#import "NSString+MD5.h" #import "NSString+MD5.h"
#import <CommonCrypto/CommonDigest.h> #import <CommonCrypto/CommonDigest.h>
#import <CommonCrypto/CommonCryptor.h>
#import "ObfuseTableBase64.h"
#import "NSString+Check.h"
@implementation FUSStringDecoderHelper
+ (instancetype)sharedInstance {
static id shared = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
shared = [[super alloc] init];
});
return shared;
}
- (instancetype)init
{
self = [super init];
if (self) {
_decodeStrDict = [NSMutableDictionary dictionary];
}
return self;
}
- (NSString *)decodeKey {
if (_decodeKey == nil) {
_decodeKey = [[ObfuseTableBase64 inst] decode:@"RnVzaUNsdWIxMjM0NTY3OA=="];
}
return _decodeKey;
}
@end
@implementation NSString (MD5) @implementation NSString (MD5)
- (NSString *)fus_decodeAESStr {
if ([NSString isNull:self]) {
return self;
}
if (FUSStringDecoderHelper.sharedInstance.decodeStrDict[self]) {
return FUSStringDecoderHelper.sharedInstance.decodeStrDict[self];
} else {
return [NSString aesDecrypt:self];
}
}
/** /**
* 获取MD5字符串 * 获取MD5字符串
...@@ -20,7 +66,6 @@ ...@@ -20,7 +66,6 @@
return [NSString md5String:self]; return [NSString md5String:self];
} }
/** /**
* 获取MD5字符串 * 获取MD5字符串
*/ */
...@@ -35,4 +80,32 @@ ...@@ -35,4 +80,32 @@
return [hash lowercaseString]; return [hash lowercaseString];
} }
+ (NSString *)aesDecrypt:(NSString *)secretStr {
if (!secretStr) {
return nil;
}
//先对加密的字符串进行base64解码
NSData * decodeData = [[NSData alloc] initWithBase64EncodedString:secretStr options:NSDataBase64DecodingIgnoreUnknownCharacters];
char keyPtr[kCCKeySizeAES256 + 1];
bzero(keyPtr, sizeof(keyPtr));
[FUSStringDecoderHelper.sharedInstance.decodeKey getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
NSUInteger dataLength = [decodeData length];
size_t bufferSize = dataLength + kCCBlockSizeAES128;
void * buffer = malloc(bufferSize);
size_t numBytesDecrypted = 0;
CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding | kCCOptionECBMode, keyPtr, kCCBlockSizeAES128, NULL, [decodeData bytes], dataLength, buffer, bufferSize, &numBytesDecrypted);
if (cryptStatus == kCCSuccess) {
NSData * data = [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted];
NSString * result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
return result;
} else {
free(buffer);
return secretStr;
}
}
@end @end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment