質問

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