qq_28304511
qq_28304511
2016-07-27 06:49

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条回答