I am trying to set up simple RSA encryption on the server side of a small piece of information that needs to be decrypted on the client side. As a proof of concept, I wrote a few lines to ensure that the public and private keys can be downloaded from xml. However, I try my best to do even the simplest things on my machine:
byte[] bytes = Encoding.UTF8.GetBytes("Some text"); bool fOAEP = true; // seeding a public and private key RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); var publicKey = rsa.ToXmlString(false); var privateKey = rsa.ToXmlString(true); //server side RSACryptoServiceProvider rsaServer = new RSACryptoServiceProvider(); rsaServer.FromXmlString(privateKey); var encrypted = rsaServer.Encrypt(bytes, fOAEP); //client side RSACryptoServiceProvider rsaClient = new RSACryptoServiceProvider(); rsaClient.FromXmlString(publicKey); var decrypted = rsaClient.Decrypt(encrypted, fOAEP);
The last Decrypt call throws a CryptographicException with the message "Error decoding OAEP add-on." I must be missing something completely obvious here. Do I need to tune rsa instances more, or maybe the initial rsa sample instance?
c # rsacryptoserviceprovider
soren.enemaerke
source share