简体   繁体   中英

How to use key files in RSA Encryption using C#?

I Have given a file named publickey.key. It contains the following Text in it:

脰ゟ؍⨉䢆čā脃脰ʉ膁딀쭡ﶅꐏ눜鎈㨾뵕匆裖奖閈㞉椼ɕ㈭㶕儐臐篙輌䡕㾜㩚᝿a涨节鸝́붼낓蟰୧櫬瑇鋁슏ຐ궿䮹맥ӈ왶䤺ꚢ鑛靡⎞깳㌧꿛葧䋰��綧툻㳥핆ˣăĀ

I have some knowledge about RSA Encryption in c#.

It uses base-64 format for key, and some XML format for key file.

But I really don't know, What is that format and How to use the given 'publickey.key' file that contains the above text.

Please give me an idea on,

  1. How to encrypt some text using that publickey.key file?
  2. I have privatekey.key file too which has some text of similar kind shown above, How can I need to decrypt the encrypted file using that?

Your file does not contain text. I guess you opened it with notepad and notepad decided it looked like Unicode and tried to decode it using that.

Actually your file contains ASN.1 encoded data. The data was partially corrupted when written as text, so I cannot be sure what format it is, but it looks like a PKCS#8 structure with a PKCS#1 RSA public key inside. You can decode it using BouncyCastle ( Org.BouncyCastle.Security.PublicKeyFactory.CreateKey() ) or a similar library.

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