113 lines
4.3 KiB
Objective-C
Executable File
113 lines
4.3 KiB
Objective-C
Executable File
//
|
|
// MAIDESEncryptTool.m
|
|
// BellFramework
|
|
//
|
|
// Created by 罗兴志 on 2017/5/4.
|
|
// Copyright © 2017年 罗兴志. All rights reserved.
|
|
//
|
|
|
|
#import "MAIDESEncryptTool.h"
|
|
#import <CommonCrypto/CommonCrypto.h>
|
|
#import "Base64.h"
|
|
|
|
@implementation MAIDESEncryptTool : NSObject
|
|
|
|
const Byte iv[] = {1,2,3,4,5,6,7,8};
|
|
|
|
#pragma mark- 加密算法
|
|
+(NSString *) encryptUseDES:(NSString *)plainText key:(NSString *)key
|
|
{
|
|
NSString *ciphertext = nil;
|
|
NSData *textData = [plainText dataUsingEncoding:NSUTF8StringEncoding];
|
|
NSUInteger dataLength = [textData length];
|
|
unsigned char buffer[20000];
|
|
memset(buffer, 0, sizeof(char));
|
|
size_t numBytesEncrypted = 0;
|
|
CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, kCCAlgorithmDES,
|
|
kCCOptionPKCS7Padding|kCCOptionECBMode,
|
|
[key UTF8String], kCCKeySizeDES,
|
|
iv,
|
|
[textData bytes], dataLength,
|
|
buffer, 20000,
|
|
&numBytesEncrypted);
|
|
if (cryptStatus == kCCSuccess) {
|
|
NSData *data = [NSData dataWithBytes:buffer length:(NSUInteger)numBytesEncrypted];
|
|
ciphertext = [Base64 encode:data];
|
|
}
|
|
return ciphertext;
|
|
}
|
|
|
|
#pragma mark- 解密算法
|
|
+(NSString *)decryptUseDES:(NSString *)cipherText key:(NSString *)key
|
|
{
|
|
NSString *plaintext = nil;
|
|
NSData *cipherdata = [Base64 decode:cipherText];
|
|
unsigned char buffer[20000];
|
|
memset(buffer, 0, sizeof(char));
|
|
size_t numBytesDecrypted = 0;
|
|
// kCCOptionPKCS7Padding|kCCOptionECBMode 最主要在这步
|
|
CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmDES,
|
|
kCCOptionPKCS7Padding|kCCOptionECBMode,
|
|
[key UTF8String], kCCKeySizeDES,
|
|
iv,
|
|
[cipherdata bytes], [cipherdata length],
|
|
buffer, 20000,
|
|
&numBytesDecrypted);
|
|
if(cryptStatus == kCCSuccess) {
|
|
NSData *plaindata = [NSData dataWithBytes:buffer length:(NSUInteger)numBytesDecrypted];
|
|
plaintext = [[NSString alloc]initWithData:plaindata encoding:NSUTF8StringEncoding];
|
|
}
|
|
return plaintext;
|
|
}
|
|
+(NSString *)getCharmImageUrl:(NSString *)url{
|
|
NSString *getUrl = @"1";
|
|
if([url containsString:@"http"]){
|
|
NSArray *charmList = [url componentsSeparatedByString:@"charm_"];
|
|
if(charmList.count == 2){
|
|
NSString *charmUrl = charmList[1];
|
|
NSArray *curCharmList = [charmUrl componentsSeparatedByString:@"."];
|
|
if(curCharmList.count == 2){
|
|
return [NSString stringWithFormat:@"new_charm_%@",curCharmList.firstObject];
|
|
|
|
}
|
|
for (int i = 0;i < 110; i++) {
|
|
NSString *num = i < 9 ? [NSString stringWithFormat:@"0%d",i+1] : [NSString stringWithFormat:@"%d",i+1];
|
|
if([charmUrl containsString:num]){
|
|
getUrl = [NSString stringWithFormat:@"new_charm_%@",num];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
}else{
|
|
getUrl = [NSString stringWithFormat:@"new_charm_%@",url];
|
|
}
|
|
return getUrl;
|
|
}
|
|
+(NSString *)getWealthImageUrl:(NSString *)url{
|
|
NSString *getUrl = @"1";
|
|
if([url containsString:@"http"]){
|
|
NSArray *wealthList = [url componentsSeparatedByString:@"wealth_"];
|
|
if(wealthList.count == 2){
|
|
NSString *wealthUrl = wealthList[1];
|
|
NSArray *curWealthList = [wealthUrl componentsSeparatedByString:@"."];
|
|
if(curWealthList.count == 2){
|
|
return [NSString stringWithFormat:@"new_exper_%@",curWealthList.firstObject];;
|
|
}
|
|
for (int i = 0;i < 110; i++) {
|
|
NSString *num = i < 9 ? [NSString stringWithFormat:@"0%d",i+1] : [NSString stringWithFormat:@"%d",i+1];
|
|
if([wealthUrl containsString:num]){
|
|
getUrl = [NSString stringWithFormat:@"new_exper_%@",num];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
}else{
|
|
getUrl = [NSString stringWithFormat:@"new_exper_%@",url];
|
|
}
|
|
return getUrl;
|
|
}
|
|
@end
|
|
|