首页 > 解决方案 > 如何解密 Unicode 十六进制字符“”

问题描述

以下是我的解密代码:

    NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:@"someEncryptedString" 
    options:0];
    NSData *decryptedData = [self decryptData:decodedData];
    NSString *decryptedstring = [[NSString alloc]initWithData:decryptedData encoding:NSUTF8StringEncoding];
   //the text is base64 encoded one more time for ePub books,so decode it after decryption
   //this is to support HTML5 reader
  
   if (forePub) {
       NSData *doubleDecodedData = [[NSData alloc] initWithBase64EncodedString:decryptedstring 
      options:NSDataBase64DecodingIgnoreUnknownCharacters];
      decryptedstring = [[NSString alloc]initWithData:doubleDecodedData 
      encoding:NSUTF8StringEncoding];
   }
- (NSData *)decryptData:(NSData *)decodedData
{

    NSString *key = @"someKey";
    NSData *keyData = [key dataUsingEncoding:NSUTF8StringEncoding];
    
    CCCryptorRef cryptor = NULL;
    CCCryptorStatus status = kCCSuccess;
    
    uint8_t iv[kCCBlockSizeBlowfish];
    memset((void *) iv, 0x0, (size_t) sizeof(iv));
    
    
    status = CCCryptorCreate(kCCDecrypt, kCCAlgorithmBlowfish, kCCOptionECBMode, [keyData bytes], kCCKeySizeMinBlowfish, iv, &cryptor);
    
    if (status != kCCSuccess) {
        return nil;
    }
    
    size_t bufsize = CCCryptorGetOutputLength(cryptor, (size_t)[decodedData length],
                                              true);
    
    void * buf = malloc(bufsize * sizeof(uint8_t));
    
    size_t bufused = 0;
    size_t bytesTotal = 0;
    
    status = CCCryptorUpdate(cryptor, [decodedData bytes], (size_t)[decodedData length],
                             buf, bufsize, &bufused);
    
    if (status != kCCSuccess) {
        free(buf);
        CCCryptorRelease(cryptor);
        return nil;
    }
    
    bytesTotal += bufused;
    
    status = CCCryptorFinal(cryptor, buf + bufused, bufsize - bufused, &bufused);
    
    if (status != kCCSuccess) {
        free(buf);
        CCCryptorRelease(cryptor);
        return nil;
    }
    
    bytesTotal += bufused;
    CCCryptorRelease(cryptor);
    NSData *decryptedData = [NSData dataWithBytesNoCopy:buf length:bytesTotal];
    return decryptedData;
}

O/P如下所示:-

"Conditions 1 "

我希望正确转换这些 Unicode 十六进制字符。

标签: iosxcodeencryptionunicodeutf-8

解决方案


推荐阅读