
- Removed YuMi/Library/ (138 MB, not tracked) - Removed YuMi/Resources/ (23 MB, not tracked) - Removed old version assets (566 files, not tracked) - Excluded Pods/, xcuserdata/ and other build artifacts - Clean repository optimized for company server deployment
64 lines
2.4 KiB
Objective-C
64 lines
2.4 KiB
Objective-C
//
|
|
// DESEncrypt.m
|
|
// YMhatFramework
|
|
//
|
|
// Created by chenran on 2017/5/4.
|
|
// Copyright © 2017年 chenran. All rights reserved.
|
|
//
|
|
|
|
#import "DESEncrypt.h"
|
|
#import <CommonCrypto/CommonCrypto.h>
|
|
#import "Base64.h"
|
|
|
|
@implementation DESEncrypt : 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[200000];
|
|
memset(buffer, 0, sizeof(char));
|
|
size_t numBytesEncrypted = 0;
|
|
CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, kCCAlgorithmDES,
|
|
kCCOptionPKCS7Padding|kCCOptionECBMode,
|
|
[key UTF8String], kCCKeySizeDES,
|
|
iv,
|
|
[textData bytes], dataLength,
|
|
buffer, 200000,
|
|
&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[200000];
|
|
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, 200000,
|
|
&numBytesDecrypted);
|
|
if(cryptStatus == kCCSuccess) {
|
|
NSData *plaindata = [NSData dataWithBytes:buffer length:(NSUInteger)numBytesDecrypted];
|
|
plaintext = [[NSString alloc]initWithData:plaindata encoding:NSUTF8StringEncoding];
|
|
}
|
|
return plaintext;
|
|
}
|
|
@end
|
|
|