The C# BouncyCastle contains a class called Org.BouncyCastle.Utilities.IO.Pem.PemReader that seem to take the RSA public key file in PEM format. I looked at this link: how can i convert pem public key to rsa public key with bouncycastle in c#?
But it seemed to be using non-existent method on PemReader called ReadObject. So I wrote following code instead.
var pemReader = new PemReader(File.OpenText(@"...rsa public key file path ..."));
var pemObject = pemReader.ReadPemObject();
var rsaPublicKeyBytes = pemObject.Content;
Once I get the RSA public bytes, I am not sure how to proceed further. I want to be able to do following:
var rsaCipher = new RsaEngine();
var oaepEncoding = new OaepEncoding(rsaCipher, new Sha256Digest());
var publicKey = new RsaKeyParameters(...);
oaepEncoding.Init(true, publicKey);
var actualEncryptedBytes = oaepEncoding.ProcessBlock(plainBytes, 0, plainBytes.Length);
I guess I am not sure about how to construct RsaKeyParameters with RSA public bytes. Can someone point me in the right direction? Or am I totally going the wrong way here?