简体   繁体   English

使用先前生成的带有.net框架的RSA公钥/私钥

[英]Using a previously generated RSA public/private key with the .net framework

I have a pre-existing public/private key pair for RSA encryption which I need to use in .net . 我有一个预先存在的RSA加密公钥/私钥对,我需要在.net中使用。 All the examples I can find online demonstrate how to generate a new private/public pair and then encrypt/decrypt. 我在网上找到的所有示例都演示了如何生成新的私有/公共对,然后加密/解密。 ie. 即。 something like this: 这样的事情:

const int PROVIDER_RSA_FULL = 1;
const string CONTAINER_NAME = "SpiderContainer";
CspParameters cspParams;
cspParams = new CspParameters(PROVIDER_RSA_FULL);
cspParams.KeyContainerName = CONTAINER_NAME;
cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
cspParams.ProviderName = "Microsoft Strong Cryptographic Provider";
rsa = new RSACryptoServiceProvider(cspParams);
.....
rsa.encrypt(...)
rsa.decrypt(...)

As can be seen, there is no avenue for specifying a pre-existing public/private key. 可以看出,没有用于指定预先存在的公钥/私钥的途径。

Would anyone know how to accomplish what I am trying to do? 谁会知道如何完成我想要做的事情? Any help would be much appreciated. 任何帮助将非常感激。

Cheers Naren 干杯纳伦

To use an existing key, you can use the ImportParameters -method: 要使用现有密钥,可以使用ImportParameters -method:

RSAParameters parameters = new RSAParameters()
parameters.Modulus = // ...
parameters.Exponent = // ...
RSA rsa = new RSACryptoServiceProvider();
rsa.ImportParameters(parameters);
rsa.Encrypt(/*...*/);

You can add the private parameters, too, in order to use it for decrypting or signing. 您也可以添加私有参数,以便将其用于解密或签名。

In order to tell you how to get from your existing keydata to the parameters, we need to know exactly how they are encoded. 为了告诉您如何从现有的keydata到参数,我们需要确切知道它们是如何编码的。 Try showing us the strings (replace most of the private key with Xs if it is a real key). 尝试向我们展示字符串(如果它是真正的密钥,则用X替换大多数私钥)。

I realise this is a very old question but maybe someone still looks at this... 我意识到这是一个非常古老的问题,但也许有人仍然看着这个......

Nowadays you can retrieve/store your keys in XML format (which you possibly could back in the days too). 现在,您可以以XML格式检索/存储密钥(您可能也可以在以后的日子里找回)。

Example import: 示例导入:

this.RSAKey = RSA.FromXmlString(xmlString: myRSAXMLKey);

Example export: 示例导出:

this.RSAKey_XMLString = RSA.ToXmlString(includePrivateParameters: false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .NET Compact Framework 中的 RSA RSACryptoServiceProvider 使用来自完整 .NET 框架的公钥 - RSA RSACryptoServiceProvider in .NET Compact Framework using public key from full .NET Framework 如何使用公共 RSA 密钥加密数据? 并用私钥解密? - How to encrypt data using a public RSA key? And decrypt with the private key? 在.NET中将RSA公钥/私钥解密实现为Java / Spring - Implement RSA Public / Private key decryption in .NET to Java / Spring 在RSA C#中使用AsymmetricAlgorithm私钥和公钥 - Using AsymmetricAlgorithm Private and Public key with RSA C# 在 C# 中使用 RSA 公钥和私钥加密数据 - Encrypting Data using RSA Public and Private Key in C# 使用iOS生成的公钥进行C#RSA加密 - C# RSA Encryption using iOS generated Public Key 使用RSA公钥解密使用RSA私钥加密的字符串 - Using an RSA Public key to decrypt a string that was encrypted using an RSA private key 使用RSA公钥解密使用RSA私钥加密的字符串 - Using an RSA Public Key to decrypt a string that was encrypted using RSA Private Key Perl和.NET RSA一起工作? 从Perl公钥加密.NET? 从Perl加载私钥? - Perl & .NET RSA working together? Encrypting in .NET from Perl public key? Loading private key from Perl? .NET私钥Rsa加密 - .NET Private Key Rsa Encryption
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM