The RSACryptoServiceProvider object performs asymmetric encryption and decryption using the implementation of the RSA algorithm provided by the cryptographic service provider (CSP).
Questions tagged [rsacryptoserviceprovider]
216 questions
68
votes
7 answers
How to export non-exportable private key from store
I need to export private key from Windows store. What should I do if the key is marked as non-exportable? I know that it is possible, program jailbreak can export this key.
To export key I use Org.BouncyCastle.Security.DotNetUtilities.GetKeyPair()…

Gorf
- 815
- 1
- 8
- 12
35
votes
3 answers
Best way to initiate RSACryptoServiceProvider from x509Certificate2?
What is the best way to initate a new RSACryptoServiceProvider object from an X509Certificate2 I pulled out of a key store? The certificate is associated with both public (for encryption) and private (for decryption) keys.
I'm current using the…

Petey B
- 11,439
- 25
- 81
- 101
23
votes
8 answers
Error occurred while decoding OAEP padding
While decrypting text using RSACryptoServiceProvider.Decrypt, I am getting the error:
Error occurred while decoding OAEP padding.
Here's my code:
CspParameters cspParam = new CspParameters();
cspParam = new CspParameters();
cspParam.Flags =…

Meetu Choudhary
- 1,373
- 4
- 14
- 26
20
votes
3 answers
The RSA key container could not be opened
I've been developing an ASP.NET site on an older machine running XP home. I recently got a new Win 7 PC and moved all my project files across. When I try and run the project, I get this error message:
"Failed to decrypt using provider…

keyboardP
- 68,824
- 13
- 156
- 205
18
votes
3 answers
Correctly create RSACryptoServiceProvider from public key
I'm currently trying to create an RSACryptoServiceProvider object solely from a decoded PEM file. After several days of searching, I did manage to wrangle a working solution but it's not one that would be production ready.
In a nutshell, in order to…

DiskJunky
- 4,750
- 3
- 37
- 66
14
votes
2 answers
RSACryptoServiceProvider initialize with own public key and private key
I'm trying to initialize RSACryptoServiceProvider with my own public and private keys.
As far as I could research, the way to do this is to call the constructor with
RSACryptoServiceProvider RSAalg = new…

C0D3
- 6,440
- 8
- 43
- 67
13
votes
1 answer
Why is RSACryptoServiceProvider.Encrypt() output not stable?
Until today I was living under the impression that RSA encryption using RSA is deterministic. After all, how should signature verification work if it wasn't?
To my big suprise, .NETs RSACryptoServiceProvider does not have a stable output when…

Johannes Rudolph
- 35,298
- 14
- 114
- 172
12
votes
2 answers
Interoperability between RSACryptoServiceProvider and openSSL
I've used the .NET class RSACryptoServiceProvider to get a keypair:
using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
{
File.WriteAllText ("PublicKeyOnly.xml", rsa.ToXmlString (false));
File.WriteAllText ("PublicPrivate.xml",…

Hylke Bons
- 133
- 1
- 5
10
votes
4 answers
Object already exists in RSACryptoServiceProvider
I copied the source code from one application to another, both running on the same machine. I am also using the same string for containerName below in both applications.
What is preventing my new application from reading the key that was saved in…

makerofthings7
- 60,103
- 53
- 215
- 448
9
votes
2 answers
How to store a public key in a machine-level RSA key container
I'm having a problem using a machine level RSA key container when storing only the public key of a public/private key pair.
The following code creates a public/private pair and extracts the public key from that pair. The pair and the public key are…

Andrew Kimball
- 201
- 1
- 2
- 6
9
votes
1 answer
RSA Key Values and Modulus in Public/Private Keys
I am writing an application that used PKI to secure email, files etc.
Using the System.Cryptography namespace, I am generating a new key pair using RSACryptoServiceProvider.
The method is:
public static void GenerateKeys(int keySize, out string…

JDubya13
- 95
- 1
- 1
- 5
9
votes
3 answers
"Bad Key." exception when decrypting with RSACryptoServiceProvider (C#.NET)
I am trying to decrypt data that has been encrypted previously in RSA (don't worry, I'm supposed to be able to, I have the keys. Nothing illegal :).
However, I get a "Bad Key." error at the decryption line. I am sure this key is right, as I took it…

Lazlo
- 8,518
- 14
- 77
- 116
8
votes
2 answers
C# RSACryptoServiceProvider ToXmlString()/FromXmlString()
EDIT2:
Seems Convert.FromBase64String is my savior. Does anyone know if a comma would every be in such a string? I'm doing basic csv parsing. If it is I can always use quotes (but can quotes ever be in a string like this too I guess) but this is…

user441521
- 6,942
- 23
- 88
- 160
8
votes
2 answers
Attempt to set permissions on a KeyContainer in C# is having no effect
I'm using the following code in an attempt to programatically allow the NetworkService account to have access to a key:
var RSA = new RSACryptoServiceProvider(
new CspParameters() {
KeyContainerName = "MyEncryptionKey",
Flags =…

Jim T
- 12,336
- 5
- 29
- 43
8
votes
1 answer
RSA Encryption with non exportable key in HSM using C# / CSP
I'm trying to encrypt a symetric key with a RSA (Exchange Key in CSP) in C# using this piece of code (the RSA key CSP50C8C7CD is not exportable, and it's in HSM):
CspParameters csp_dnet = new CspParameters(1, "HSM especific CSP");
csp_dnet.Flags =…

Vasconcelos
- 91
- 6