oc 用DES加密+base64编码后 ,得到的字符串结尾有一小段乱码

oc 用DES加密+base64编码后 ,得到的字符串结尾有一小段乱码,而且很难复现,哪位大神懂,求助

base64是用GTMBase64,,DES加密方法如下:

  • (NSString *)encryptDESUseCBCModel:(NSString *)clearText key:(NSString *)key vi:(NSString *)vi
    {
    NSData *data = [clearText dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];

    unsigned char buffer[[data length]];
    memset(buffer, 0, sizeof(char));
    size_t numBytesEncrypted = 0;

    const void *vinitVec = (const void *) [vi UTF8String];

    CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
    kCCAlgorithmDES,
    kCCOptionPKCS7Padding /*| kCCOptionECBMode*/,
    [key UTF8String],
    kCCKeySizeDES,
    vinitVec,
    [data bytes],
    [data length],
    buffer,
    100000000,
    &numBytesEncrypted);

    NSString* plainText = nil;
    if (cryptStatus == kCCSuccess) {
    NSData *dataTemp = [NSData dataWithBytes:buffer length:(NSUInteger)numBytesEncrypted];
    plainText = [GTMBase64 stringByEncodingData:dataTemp];
    }else{
    TestLog(@"DES加密失败");
    }
    return plainText;
    }

NSString *jsonString = [parameters JSONString];
NSString *encodeJsonString = [EncryptUtil encryptDESUseCBCModel:jsonString key:kEncryptKey vi:kEncryptVi];

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问