Note that there are some explanatory texts on larger screens.

plurals
  1. POEncrypting Data using RSA Public and Private Key in C#
    primarykey
    data
    text
    <p>I am trying to encrypt a message using RSA public key and decrypt it using my private key. It encrypted the message, but I was not able to decrypt it. The message was still encrypt after the final process. When I exported the private key, it also included the public keys. I tried to remove the public key leaving, but it would not work. Here are the private and public keys</p> <pre><code>//This is the public key private const string public_key = "&lt;RSAKeyValue&gt;&lt;Modulus&gt;uznzVPilsR1rWPkpq6m6IALaafDnVZTDDcnEyBD3A/PBx2JZTKM0DTgiTDDwCEmQBNBpPILcIBdtg3aSUgicair+2ksYrVFT+uiy0Zy1nU6qoJ+SsapLKrpCa1zHpV4LMO/pFo4Foqzw0C1FNe56FXo1xj77GPgeYl0MHUVtAUc=&lt;/Modulus&gt;&lt;Exponent&gt;AQAB&lt;/Exponent&gt;&lt;/RSAKeyValue&gt;"; //This is the private and public key. private const String private_key = "&lt;RSAKeyValue&gt;&lt;Modulus&gt;uznzVPilsR1rWPkpq6m6IALaafDnVZTDDcnEyBD3A/PBx2JZTKM0DTgiTDDwCEmQBNBpPILcIBdtg3aSUgicair+2ksYrVFT+uiy0Zy1nU6qoJ+SsapLKrpCa1zHpV4LMO/pFo4Foqzw0C1FNe56FXo1xj77GPgeYl0MHUVtAUc=&lt;/Modulus&gt;&lt;Exponent&gt;AQAB&lt;/Exponent&gt;&lt;P&gt;+jPKs9JxpCSzNY+YNanz49Eo/A6RaU1DZWoFm/bawffZOompeL1jzpUlJUIrKVZJkNFvlxE90uXVwjxWBLv9BD==&lt;/P&gt;&lt;Q&gt;v5CVWKZ5Wo7W0QyoEOQS/OD8tkKS9DjzZnbnuo6lhcMaxsBrCWLstac1Xm2oFNtZgLtrPGbPfCNC5Su4Rz/P5w==&lt;/Q&gt;&lt;DP&gt;ZnyikmgobqEt20m3gnvcUDxT+nOJMsYYTklQhONoFj4M+EJ9bdy+Lle/gHSLM4KJ3c08VXgVh/bnSYnnfkb20Q==&lt;/DP&gt;&lt;DQ&gt;sSYGRfWk0W64Dpfyr7QKLxnr+Kv186zawU2CG44gWWNEVrnIAeUeWxnmi41CWw9BZH9sum2kv/pnuT/F6PWEzw==&lt;/DQ&gt;&lt;InverseQ&gt;XpWZQKXa1IXhF4FX3XRXVZGnIQP8YJFJlSiYx6YcdZF24Hg3+Et6CZ2/rowMFYVy+o999Y5HDC+4Qa1yWvW1vA==&lt;/InverseQ&gt;&lt;D&gt;Kkfb+8RrJqROKbma/3lE3xXNNQ7CL0F5CxQVrGcN8DxL9orvVdyjlJiopiwnCLgUHgIywceLjnO854Q/Zucq6ysm2ZRq36dpGLOao9eg+Qe8pYYO70oOkEe1HJCtP1Laq+f3YK7vCq7GkgvKAI9uzOd1vjQv7tIwTIADK19ObgE=&lt;/D&gt;&lt;/RSAKeyValue&gt;"; //Encrypting the text using the public key private RSACryptoServiceProvider cipher = null; cipher = new RSACryptoServiceProvider(); cipher.FromXmlString(public_key); byte[] data = Encoding.UTF8.GetBytes(txtUnencrypt.Text); byte[] cipherText = cipher.Encrypt(data, false); lblUnencryptMessage.Text = Convert.ToBase64String(cipherText); // decryptText(); //Trying to decrypt the text using the private key cipher = new RSACryptoServiceProvider(); cipher.FromXmlString(private_key); byte[] ciphterText = Convert.FromBase64String(lblUnencryptMessage.Text); byte[] plainText = cipher.Decrypt(ciphterText, false); lblDecript.Text = Convert.ToBase64String(plainText); </code></pre> <p>What am I missing here? </p> <p><strong>Updated at 11:37 AM</strong></p> <p>For example, I encrypted the word "Testing", the encrypted text was kkqs+UGHNI7/3cKhQvSnJrKzNeCBQX9xHX2VrlyMvnwtszJAoFuViBZlfwmpVhqddnVUrlaqqkD7971E8L3wWltfGetK9nIljeo0GeietLYljoY0Gy3gatU++JPrqajAKxpIB75tvVlKXuYIs0qE3XWZu9bj0zAa4BVT2MhVNQM="</p> <p>The decrypted text was dGVzdGluZw==</p>
    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.
 

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