I would like to generate private key in java, save it as a 64 base encoded string in some file and then encrypt some phrase in C# using this saved file. I know to generate keys in java and encode it with 64 base. My question is how do I use this key in C#? This is a java code prototype to save private key into text file:
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4);
keyGen.initialize(spec);
KeyPair keyPair = keyGen.generateKeyPair();
PrivateKey privateKey = keyPair.getPrivate();
writeToFile("privateKey", Base64.encode(keyPair.getPrivate().getEncoded()));
I would like to implement following function in C# but can't find how to create RSAParameters or RSACryptoServiceProvider from private key
public static string DecryptData(string privateKey64Base, string data64Base)
{
// create using privateKey64Base
// create RSACryptoServiceProvider rsa using RSAParameters above
// byte[] encryptedData = rsa.Encrypt(Convert.FromBase64String(data64Base);
}