Note that there are some explanatory texts on larger screens.

plurals
  1. POIOS: Decrypting a message with public key received from webservice
    primarykey
    data
    text
    <p>I'm new to this topic so sorry if this is a stupid question :\</p> <p>I'm trying to decrypt a message with a given public key. Both the message and public key is given from the webservice. </p> <p>See the following code for how i currently do the decrypting:</p> <pre><code> for (NSValue *refVal in keyRefs) { SecKeyRef p_key = NULL; [refVal getValue:&amp;p_key]; if (p_key == NULL) continue; size_t dataLength = encryptedData.length; size_t outPutLength = MAX(dataLength, SecKeyGetBlockSize(p_key)); void *outPutBuf = malloc(outPutLength); if (outPutBuf) { // Error handling OSStatus status = SecKeyDecrypt(p_key, kSecPaddingNone, encryptedData.bytes, encryptedData.length, outPutBuf, &amp;outPutLength ); NSLog(@"decryption result code: %ld (size: %lu)", status, outPutLength); NSLog(@"FINAL decrypted text: %s", outPutBuf); if (status == errSecSuccess) { break; } } else { //Error handling } } </code></pre> <p>I get no errors, but the decrypted string is displayed like this (the correct output should be a JSON array): </p> <pre><code>decryption result code: 0 size:511) FINAL decrypted text: ˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇ </code></pre> <p>Is it because I use the "SecKeyDecrypt" with a "public key" instead of a "private key"? In that case, what should i instead use for decrypting?</p> <p>Thanks for any help regarding this!</p> <p>EDIT: I'm using code from: <a href="http://blog.flirble.org/2011/01/05/rsa-public-key-openssl-ios/" rel="nofollow">http://blog.flirble.org/2011/01/05/rsa-public-key-openssl-ios/</a> to use the public key i get from the server (this is where "keyRefs" from the code snippet comes from)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload