rsacryptoserviceprovider using x509 certificates c#(rsacryptoserviceprovider 使用 x509 证书 c#)
问题描述
我正在使用由 makecert 生成的证书,该证书具有私钥和公钥.Java 端使用此公钥加密数据,.net 将其解密.
i am using a certificate generated by makecert which has both private and public key. The java side uses this public key to encrypt the data and .net decrypts it back.
我正在尝试解密 Java 的加密 64 位编码字符串并获取错误数据.
I am trying to decrypt Java's encrypted 64 bit encoded string and getting bad data.
为了查看.Net 端是否一切正常,我首先尝试使用公钥加密,然后使用相同的证书使用私钥解密.我的代码如下所示.
To see if all is good on.Net end, I frist tried to encrypt with the public key and then decrypt with private using the same certificate. My code looks like this.
X509Certificate2 cert = GetCert(key, StoreName.My, StoreLocation.LocalMachine);
RSACryptoServiceProvider provider = (RSACryptoServiceProvider)cert.PrivateKey;
RSACryptoServiceProvider publicprovider = (RSACryptoServiceProvider)cert.PublicKey.Key;
if (cert.HasPrivateKey)
MessageBox.Show("Got private key");
byte[] encrypted = publicprovider.Encrypt(Encoding.UTF8.GetBytes(text), false);
byte[] decryptedBytes = provider.Decrypt(encrypted, false);
即使在这里我也遇到了错误.我错过了什么吗?
Even here I am getting the error. Am i Missing something?
证书看起来对公钥和私钥都有效.
The certificate looks valid with both public and private key.
推荐答案
我终于找到了问题所在.我没有把 makecert 的密钥定义为 RSA 加密密钥.
I finally found the problem. I wasn't putting the key to makecert to define it as RSA Crypto key.
这篇关于rsacryptoserviceprovider 使用 x509 证书 c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:rsacryptoserviceprovider 使用 x509 证书 c#


基础教程推荐
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- SSE 浮点算术是否可重现? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01