ios - 如何解密 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 十六进制字符。
解决方案
推荐阅读
- amazon-sqs - 如何在 SNS 和 SQS 中处理“重新发送”电子邮件
- machine-learning - 主成分分析 - 是否删除特征?
- c++ - 读取 .txt 文件更节省内存 C++
- c - 如何以可移植的方式验证ANSI C的stdin缓冲区中是否有一些信息?
- python - python float dot to comma with 2 decimals
- c - 我应该如何在字符串值后使用整数的结构上进行 malloc?
- powerbi-desktop - PowerBI:“显示为表格”缺少行
- python-3.x - 如何从python中的大字符串一次读取n个字节
- git - 使用 TeamCity 10.0 和上传的密钥从 github 拉出问题
- java - 为什么 onDraw() 不能访问 myPaint?