Below is my code for Decryption :
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 comes something like below:-
"Conditions 1 "
I want these Unicode Hex Character to be converted properly.