Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to decrypt data signed by RSACryptoServiceProvider
    primarykey
    data
    text
    <p>I am starting to use encryption and decryption in my web service. I am using the <strong>RSACryptoServiceProvider</strong> and when using the <em>Encrypt</em> &amp; <em>Decrypt</em> methods, I have no problem.</p> <p>However, as soon as I try to use the <strong>SignData</strong> method with <em>new SHA1CryptoServiceProvider()</em> as encryption method, I am unable to recover the original data. I am only able to verify them. Is it really not possible to retrieve the signed data? If so, what is the purpose of the whole signing process? And is there another possibility how to encrypt data by a certain algorithm?</p> <p>EDIT: I am posting the code, which is just an altered example from <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider.decrypt.aspx" rel="nofollow">MSDN</a></p> <pre><code>static void Main() { try { //Create a UnicodeEncoder to convert between byte array and string. ASCIIEncoding ByteConverter = new ASCIIEncoding(); string dataString = "Data to Encrypt"; //Create byte arrays to hold original, encrypted, and decrypted data. byte[] dataToEncrypt = ByteConverter.GetBytes(dataString); byte[] encryptedData; byte[] signedData; byte[] decryptedData; byte[] unsignedData; var fileName = ConfigurationManager.AppSettings["certificate"]; var password = ConfigurationManager.AppSettings["password"]; var certificate = new X509Certificate2(fileName, password); //Create a new instance of the RSACryptoServiceProvider class // and automatically create a new key-pair. RSACryptoServiceProvider RSAalg = (RSACryptoServiceProvider)certificate.PrivateKey; //RSAPKCS1SignatureDeformatter def = (RSAPKCS1SignatureDeformatter)certificate.PrivateKey; //Display the origianl data to the console. Console.WriteLine("Original Data: {0}", dataString); //Encrypt the byte array and specify no OAEP padding. //OAEP padding is only available on Microsoft Windows XP or //later. encryptedData = RSAalg.Encrypt(dataToEncrypt, false); signedData = RSAalg.SignData(dataToEncrypt, new SHA1CryptoServiceProvider()); //Display the encrypted data to the console. Console.WriteLine("Encrypted Data: {0}", ByteConverter.GetString(encryptedData)); Console.WriteLine("Signed Data: {0}", ByteConverter.GetString(signedData)); //Pass the data to ENCRYPT and boolean flag specifying //no OAEP padding. decryptedData = RSAalg.Decrypt(encryptedData, false); //In the next line I get the error of wrong data unsignedData = RSAalg.Decrypt(signedData, false); //Display the decrypted plaintext to the console. Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData)); Console.WriteLine("Unsigned plaintext: {0}", ByteConverter.GetString(unsignedData)); } catch (CryptographicException e) { //Catch this exception in case the encryption did //not succeed. Console.WriteLine(e.Message); } Console.Read(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload