How to import an RSA key from a KEY file

I need to encrypt a string in my application using the RSA key from a .key file. It contains something like this:

---BEGIN RSA PRIVAET KEY--- MIICHATIABBgQDi+.....OKh4= ---END RSA PRIVATE KEY--- 

So, I know that I can use the RSACryptoServiceProvider class to encrypt my string, but how can I import a key from a .key file?

+4
source share
1 answer

You can use the Bouncycastle C # cryptographic library, in particular the PEMReader class. PEMReader.readObject() will read it and return an AsymmetricCipherKeyPair containing the private and public keys. You can then use the DotNetUtilities class to convert to .NET objects.

+2
source

Source: https://habr.com/ru/post/1387732/


All Articles