[英]Encrypting Data with RSA in .NET
I have a DER
file with sha1RSA
as the Signature Algorithm
.我有一个以
sha1RSA
作为Signature Algorithm
的DER
文件。 I have to encrypt some data using it.我必须使用它来加密一些数据。
Can anyone tell me how do I load the DER
file and use the RSA
public key in it to encrypt my data in .NET?谁能告诉我如何加载
DER
文件并使用其中的RSA
公钥来加密 .NET 中的数据?
DER or Distinguished Encoding Rules is a method for encoding a data object, such as an X.509 certificate, to be digitally signed or to have its signature verified. DER 或可分辨编码规则是一种编码数据 object(例如 X.509 证书)以进行数字签名或验证其签名的方法。
The X.509 certificate only contains the public key. X.509 证书仅包含公钥。 You need the private key to decrypt!
您需要私钥才能解密!
Typically private keys are exchanged in.PFX files, which are password protected.通常,私钥在受密码保护的 .PFX 文件中交换。
-- EDIT -- - 编辑 -
Sorry I misread your question.对不起,我误读了你的问题。 Yes, you can encrypt with the public key of X.509 certificate.
是的,您可以使用 X.509 证书的公钥进行加密。 You can load the.der by using System.Security.Cryptography.X509Certificates.X509Certificate2.Import method.
您可以使用 System.Security.Cryptography.X509Certificates.X509Certificate2.Import 方法加载 .der。
Then convert the public and encrypt, something like:然后转换 public 并加密,类似于:
rsa = (RSACryptoServiceProvider) certificate.PublicKey.Key;
encryptedText = rsa.Encrypt(msg, true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.