标签:
+(NSString *) encryptUseDES:(NSString *)plainText key:(NSString *)key
{
//testByte是关键点
NSData *data1 = [key dataUsingEncoding:NSUTF8StringEncoding];
Byte *testByte = (Byte *)[data1 bytes];
NSString *ciphertext = nil;
NSData *textData = [plainText dataUsingEncoding:NSUTF8StringEncoding];
NSUInteger dataLength = [textData length];
unsigned char buffer[1024];
memset(buffer, 0, sizeof(char));
size_t numBytesEncrypted = 0;
CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, kCCAlgorithmDES,
kCCOptionPKCS7Padding,
[key UTF8String], kCCKeySizeDES,
testByte,
[textData bytes], dataLength,
buffer, 1024,
&numBytesEncrypted);
if (cryptStatus == kCCSuccess) {
NSData *data = [NSData dataWithBytes:buffer length:(NSUInteger)numBytesEncrypted];
ciphertext = [Base64 encode:data];
NSLog(@"-------------%@",ciphertext);
}
return ciphertext;
}
首先建一个NSObject DesCodeFunc类,写上面的工厂方法 然后在需要调用的地方写 下面的字符串即可 注意后面key需要客户给
[DesCodeFunc encryptUseDES:tfield2cart.text key:@"Markor02"]
标签:
原文地址:http://www.cnblogs.com/huangzs/p/4554349.html