下面是我加密字符串的代码,

NSString *token = @"us=foo;pw=bar;pwAlg=false;";
NSString *key = @"testtest";

const void *vplainText;
size_t plainTextBufferSize;

plainTextBufferSize = [token length];
vplainText = (const void *) [token UTF8String];

CCCryptorStatus ccStatus;
uint8_t *bufferPtr = NULL;
size_t bufferPtrSize = 0;
size_t *movedBytes;

bufferPtrSize = (plainTextBufferSize + kCCBlockSize3DES) & ~(kCCBlockSize3DES - 1);
bufferPtr = malloc( bufferPtrSize * sizeof(uint8_t));
memset((void *)bufferPtr, 0x0, bufferPtrSize);
// memset((void *) iv, 0x0, (size_t) sizeof(iv));


NSString *initVec = @"init Vec";
const void *vkey = (const void *) [key UTF8String];
const void *vinitVec = (const void *) [initVec UTF8String];

ccStatus = CCCrypt(kCCEncrypt,
                   kCCAlgorithmDES,
                   kCCOptionECBMode,
                   vkey, //"123456789012345678901234", //key
                   kCCKeySizeDES,
                   NULL,// vinitVec, //"init Vec", //iv,
                   vplainText, //"Your Name", //plainText,
                   plainTextBufferSize,
                   (void *)bufferPtr,
                   bufferPtrSize,
                   movedBytes);

NSString *result;
NSData *myData = [NSData dataWithBytes:(const void *)bufferPtr length:(NSUInteger)movedBytes];
result = [myData base64Encoding];

 NSLog( @"Original String dddd: %@", result );

它在ccStatus=CCCrypt(kccencencrypt,
有人能帮忙提建议吗?

最佳答案

这是CCCrypt的最后一个参数。它试图输出一个值(这样你就知道它所写数据的大小)并给它一个指针。你需要给它一个size_t变量的地址。
试试这样的:

size_t movedBytes;
ccStatus = CCCrypt(kCCEncrypt,
                kCCAlgorithmDES,
                kCCOptionECBMode,
                vkey, //"123456789012345678901234", //key
                kCCKeySizeDES,
                NULL,// vinitVec, //"init Vec", //iv,
                vplainText, //"Your Name", //plainText,
                plainTextBufferSize,
                (void *)bufferPtr,
                bufferPtrSize,
                &movedBytes);

10-04 11:36