简体   繁体   中英

(En|De)crypt data with static private/public key with RSA

I've seen many examples of how to use RSA in C# with random generated keys, but none with static keys. I need this is because my program client stores the public key (n, e) statically, and the server stores the private (d, n) and public keys statically too.

If I create a RSAParameters and store the Modulus=n and Exponent=e values and call ImportParameters , I can successfully encrypt data, but if I create a new RSAParameters and store the Modulus=n and D=d values, when I call the ImportParameters method, a System.Security.Cryptography.CryptographicException is thrown.

Is there a way to decrypt the data with only the D and N values?

Try to encode the values in a PKCS#1/PKCS#8 format. That way you can retrieve the keys back from any framework as well. The best way to do this is to use the Bouncy Castle framework. I've included some pointers to questions about importing/exporting keys to/from a C# application.

How to convert pkcs8 key file to DER format in #C?

Creating PKCS1 public key in Net Framework

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM