I need to encrypt string in my app using RSA key from file .key.
It contains something like this:
---BEGIN RSA PRIVAET KEY---
MIICHATIABBgQDi+.....OKh4=
---END RSA PRIVATE KEY---
So, I know that I can use RSACryptoServiceProvider class to encrypt my string, but how can I import key from .key file?
You can use the Bouncycastle C# crypto library, specifically the PEMReader class.
PEMReader.readObject()will read it in and return an AsymmetricCipherKeyPair containing the private and public keys. You can then use theDotNetUtilitiesclass to convert to .NET objects.