Question

I got a problem like title indicates. In the app,first I generate a random number and post it to server.Server uses its own RSA private key to encrypt the random number and return the encrypt number back to me.I have the server's RSA public key kept in my local as Base64 string.The problem is how to use the server's RSA public key(all I have is a Base64 string.no PEM or DER type file) to decrypt the cipher back from server. Need U help!

Was it helpful?

Solution

how to use RSA public key decrypt cipher in iOS

The public key is used for encryption, not decryption. More correctly, "decrypting with the public key" is not a valid cryptographic operation.


In the app,first I generate a random number and post it to server.Server uses its own RSA private key to encrypt the random number and return the encrypt number back to me.I have the server's RSA public key kept in my local as Base64 string.

You realize anyone can probably decrypt the secret. The public key in {n,e}, and most libraries pick a well known e (its probably 3, 17 or 65537).


The problem is how to use the server's RSA public key (all I have is a Base64 string. No PEM or DER type file) to decrypt the cipher back from server.

It sounds like you are looking for a Probabilistic Signature Scheme with Recovery (PSSR). That way, you can extract the message from the signature after verifying the message is authentic.

If not, you should probably use a well established protocol like IPSec or SSL/TLS to set up a secure channel and tunnel your traffic through it. Its usually a good idea to use something that's well established; and its usually a bad idea to design your own protocols.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top