我需要使用RSA 1.5算法加密字符串。我已经提供了一个私钥。但是,我不能为了我的生活找出如何将这个关键词添加到课程中。 RSAParameter stuct类似的关键需求是。然而,这需要一系列我没有给出的值,例如Modulus,Exponent,P,Q等等。我拥有的只是私钥。谁能帮忙?.NET私钥Rsa加密
回答
你应该知道的Bouncycastle C# library的。特别有两个非常有用的类:Org.BouncyCastle.OpenSsl.PemReader
,它将从openssl样式键转换为bouncycastle键对象,Org.BouncyCastle.Security.DotNetUtilities
将把bouncycastle键转换为.NET RSAParameters
对象。
这里是未经测试的代码一点点,说明如何使用它
using System;
using System.IO;
using System.Security.Cryptography;
using Org.BouncyCastle.OpenSsl;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Crypto.Parameters;
namespace RSAOpensslToDotNet
{
class Program
{
static void Main(string[] args)
{
StreamReader sr = new StreamReader("../../privatekey.pem");
PemReader pr = new PemReader(sr);
AsymmetricCipherKeyPair KeyPair = (AsymmetricCipherKeyPair)pr.ReadObject();
RSAParameters rsa = DotNetUtilities.ToRSAParameters((RsaPrivateCrtKeyParameters)KeyPair.Private);
}
}
}
谢谢!这正是我需要的。 – 2011-05-18 01:42:38
我一直在寻找很多地方正是这个......谢谢! – MattyP 2012-08-16 16:49:06
我需要用Java完成这件事。当我使用pr.readObject()时,它将返回PEMKeyPair并在将其转换为AsymmetricCipherKeyPair时引发异常。我无法弄清楚为什么我的生活。请帮忙! – c0d3Junk13 2013-04-04 22:12:40
我想这是你在寻找:
// Import ASymmetric RSA Key from a system file.
public static RSAParameters ImportRSAKey(String fileName)
{
// Create a stream to a the specified system file.
Stream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
// Extract/Deserialize the key from the file.
IFormatter soapFormatter = new SoapFormatter();
RSAParameters rsaParameter =
(RSAParameters) soapFormatter.Deserialize(fileStream);
// Close the file stream.
fileStream.Close();
return rsaParameter;
}
要生成一个新的密钥,你可以使用RSACryptoServiceProvider.ExportParameters方法。
请参阅以下内容:
- 1. RSA加密 - 用私钥
- 2. C#RSA加密与私钥
- 3. C#OpenSSL RSA私钥加密
- 4. 使用RSA公钥加密DSA私钥
- 5. Bouncycastle加密私钥PEM输出:RSA私钥与私钥
- 6. .net RSA - 更改私钥
- 7. .NET RSA加密:最小密钥大小?
- 8. RSA解密的私钥C++
- 9. 的Javascript RSA解密私钥
- 10. 使用RSA私钥解密
- 11. RSA私钥在广播加密
- 12. 在.NET中将RSA公钥/私钥解密实现为Java/Spring
- 13. AES密钥和iv来自RSA私钥
- 14. 使用RSA私钥创建密钥库
- 15. 用RSA公钥和私钥加密和解密一个SecretKey
- 16. 使用RSA公钥解密使用RSA私钥加密的字符串
- 17. 使用RSA公钥来解密使用RSA被加密的字符串私钥
- 18. RSA加密公钥?
- 19. 在加密++中加载PEM编码的私有RSA密钥
- 20. Java - 公钥 - 私钥加密 - 如何计算RSA中的私钥 - UNSOLVED
- 21. RSA加密,密钥存储
- 22. 雨云JOSE JWT加密与RSA,私钥和公钥
- 23. 使用RSA公钥和私钥在C#中加密数据
- 24. 在生成公钥/私钥之前关闭RSA加密force
- 25. Python加密,RSA公钥/私钥,大文件
- 26. 如何从.NET读取PEM RSA私钥
- 27. .Net RSA加密,Java RSA解密
- 28. 使用私钥解密文件(RSA)
- 29. 如何使用RSA私钥解密JWT
- 30. C#RSA使用私钥解密
什么你有明显的关键,你可能不希望为它供给逐字,但你可以形容它多一些? – Jodrell 2011-05-17 11:19:23
发布您尝试过的内容。我怀疑你根本不明白RSA的工作原理如何。我不知道你使用了哪些课程,所以我不能提供建议。阅读此:http://stackoverflow.com/questions/1181421/is-possible-to-encrypt-with-private-key-using-net-rsacryptoserviceprovider – 2011-05-17 11:25:04
我提供的密钥看起来像----- BEGIN RSA PRIVATE KEY ----- MIIadfdafCXdfawIBAAKBgQCIgynd6pvlCF = ----- END RSA PRIVATE KEY ----- ----- BEGIN PUBLIC KEY ----- jaz + wadfadIDAQAB ----- END PUBLIC KEY ----- 这是我拥有的全部.. – 2011-05-17 11:29:03