how to use RSA public key decrypt cipher in iOS [closed]

北战南征 提交于 2019-12-25 06:15:15

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/21772403/how-to-use-rsa-public-key-decrypt-cipher-in-ios

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!