.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

RSACryptoServiceProvider.SignData(), ImportParameters

Posted By:      Posted Date: October 28, 2010    Points: 0   Category :.NET Framework


Can anyone post a code on how to Signdata() or Decrypt() with only knowing n,d and e created using oppenssl. Microsoft's RSA implementation demands providing P, Q as well but its not known to me :(

Also, OpenSSL implementations of the corresponding function works without provinding them. I need to replicate the same in my C# application.


View Complete Post

More Related Resource Links

RSACryptoServiceProvider + smart card with X509 certificate = Bad Key.

Hello! I'm trying the interop with Java. The task: create  SHA1withRSA signature of the document hash with .NET CLR. The singer key is an X509 certificate from external CA, and this signer certificate is on the smart card. 1. First solution: the .NET CLR SignedCms class passes the document hash to the Windows CryptoApi (and to the smart card), and the result is a PKCS#7 message with the signature. This solution works well with smart card, but the requirement is only the "SHA1withRSA" signature of document hash, the PKCS#7  message will be created at Java side. 2. Second attempt, create only "SHA1withRSA" signature:             // choosing certificate from smart card             X509Certificate2 card = GetCertificate();             // this fails when certificate is on the smart card:             RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)card.PrivateKey;             // only the signed hash needed             byte[] signedHashValue1 = rsa.SignData(documentHash, new SHA1Managed()); The problem: the car

need to use same key every time with RSACryptoServiceProvider

Hello, How can i ensure the same key is used every time with RSACryptoServiceProvider?

bad data exception when using importparameters

I am using the following code to generate rsa parameters Encoding encoding = new ASCIIEncoding(); RSAParameters rsaparams = new RSAParameters() { Exponent = encoding.GetBytes("AQAB"), Modulus = encoding.GetBytes("s/OiYpx0QLPHjU63yYF0fy6Jjr2vcvaMSNJs+je1HCyQNEFqe5mI8gyN8snArYyns/IWX7AXlK9i9IQia5OTLfv3LOQDbqxv5eRUdbIwDglQOrV0y7yBHeLRTcZGqCX0XvQourAlVw/ia+drQj2MAFpHBo/hFSeGP9Q1ZDBiib0="), D = encoding.GetBytes("BCg6tiB7JwuALqmE4WjWMiH3F48WQIelkgEad2VWD8KPykVAmn5fhYf4t4UlqFy5exS6o5dD1DGBDbkHuoh8O+fB3E+BvauAhBGB/dLskw9moNz6mOs0SlgRHd/5IfddRHmGc6r7W9UKSfKUB50pa5QLIk9YUHXmFdmNxuCVuME="), DP = encoding.GetBytes("M1xo6vaF4cn/1mBVRD8MDVw9PMvRLREKtjmUjEXZPao7XqQCC2hwcBJk6ZehQDkpzSIRTBKJkrlK6h3PqORKaQ=="), DQ = encoding.GetBytes("eWv30XTdBGFLpsFnPgaOhyAgLUosqEp43hjkFEYzBUn5GTnrYzqlI1AjP/gRDC1IXVSqH3DYIkRis3mwXPr6aQ=="), InverseQ = encoding.GetBytes("Jk5LwkdR3OATU++9UUO0c3/iejfphqnFAKM1G7PeWvhff7afFgmGi5+HsgYKS3GQsOh0+tpmb9jGvRctkrmadg=="), P = encoding.GetBytes("7DawsQ1YW2dBb1l+qbz11tRkVaz3Nouei46C9imP4+S2QHJpse7lBqBDw26bbgZJxO3TxdzRflhF6KidWW2uZQ=="), Q = encoding.GetBytes("wwZ58FTqe0ZDZWoAAkuHzL7AdYPft3dvDEbcNr/EpPA8WfBH9T8ZtFsDzxu7POqz9/nF0Ky1lyn17EoVPE7seQ==") }; I keep getting "bad data" errors when calling rsa.Import

Exception when initializing private key from xml string (RSACryptoServiceProvider using FromXmlStrin

Hi, I'm trying to create a private key using the following code segment   System.Security.Cryptography.AsymmetricAlgorithm key = new System.Security.Cryptography.RSACryptoServiceProvider();string privateKeyXml = File.ReadAllText(fullPathPrivateKey);key.FromXmlString(privateKeyXml);   It does work with .NET Framework 3.5 SP1 on Windows XP, but when I try to run it on .NET Framework 4.0 on Windows 7 I get the following exception ((System.Security.Cryptography.RSACryptoServiceProvider)(key)).CspKeyContainerInfo.Exportable' threw an exception of type 'System.Security.Cryptography.CryptographicException', with message "Key does not exist". Full stack trace is shown below: System.Security.Cryptography.CryptographicException: Key does not exist. at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) at System.Security.Cryptography.Utils._GetProviderParameter(SafeProvHandle hProv, Int32 keyNumber, UInt32 paramID) at System.Security.Cryptography.CspKeyContainerInfo.get_Exportable() Does anyone have a clue to why this doesn't work on .NET 4.0? Regards, Simon

Importing the public key of asymmetric key object into RSACryptoServiceProvider


I want to use the public key provided by creating SQL asymmetric key Object
in my VB.Net,After searching the Internet i reached the
Using SQL Server 2005 Public Keys in VB.Net thread.
Now the question is How can I use the public key in RSACryptoServiceProvider   ?


RSACryptoServiceProvider "Key does not exist" error



I'm using RSA encryption in my application and I have generated two xml files containing my public and private keys. I'm not sure if I'm using the RSACryptoServiceProvider in the correct way so any pointers to me being stupid are appreciated.

I encrypt the data using the code below.

RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
byte[] encrypted = rsa.Encrypt(data, false);

I then decrypt the code using this code

RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
byte[] decrypted = rsa.Decrypt(data, false);

but this fails with the error "key does not exist". They are definitely the correct keys but I am obviously doing something wrong.



Object already exists with RSACryptoServiceProvider



After beating my head against the wall for half a day I finally figured out why I am getting an exception "Object already exists." when trying to instantiated an RSACryptoServiceProvider.


Here was my C# code from .NET 1.1 which worked fine under my ASPNET windows user account:

CspParameters csp = new CspParameters();

csp.KeyContainerName = "MySecretKeyContainer";

svrRSA = new RSACryptoServiceProvider(csp);


When I ran this same code in .NET 2.0 also under my ASPNet windows user account.

I got the following exception and stack trace:


Object already exists.


Stack Trace:
   at System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr)
   at System.Security.Cryptography.Utils._CreateCSP(CspParameters param, Boolean randomKeyContainer, SafeProvHandle& hProv)
   at System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)

How Can i use the key file Generated by RSACryptoServiceProvider to encrypt with php?


I need to be able to encrypt data in PHP using a public key generate by .NET(RSACryptoServiceProvider).  I will then decrypt the data later in C# using the private key.


Code Snippet

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend