문제

I have troubles with decrypting RSA public keys in Cocoa environment. I have encrypted hash, public key in public.pem with -----BEGIN PUBLIC KEY----- guards (generated by openssl)

NSData *encryptedData = base64dec(license);

NSString *publicKeyPath = [[NSBundle mainBundle] pathForResource:@"public" ofType:@"pem"];
NSData *publicKeyData = [NSData dataWithContentsOfFile:publicKeyPath];

SSCrypto *crypto = [[SSCrypto alloc] initWithPublicKey:publicKeyData];

[crypto setClearTextWithData:encryptedData];
[crypto verify];

NSString *verifiedKey = [crypto clearTextAsString];

But verifiedKey is always nil. Looks like SSCrypto can't convert NSData to NSString. How can I actually get data decrypted?


Ended up using this code (to eliminate base64 decoding step)

[crypto setCipherTextFromBase64String:license];
NSString *verifiedKey = [crypto clearTextAsString];

But verifiedKey is always an empty string. What does it mean? Input data seems to be correct.

올바른 솔루션이 없습니다

다른 팁

Since you are decrypting encrypted data, you should do setCipherText: instead of setClearTextWithData:

Also, calling verify without using its return value serves no purpose.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top