Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Stackoverflow Extension library got two nice little extensions to encrypt&amp;decrypt string with RSA. <a href="https://stackoverflow.com/questions/271398?sort=votes&amp;page=1#sort-top">Topic Here</a> Used a few times myself but haven't tested it really , but it IS in SO Extension library so i assume it is tested&amp;stable.</p> <p>Encrypt ;</p> <pre><code>public static string Encrypt(this string stringToEncrypt, string key) { if (string.IsNullOrEmpty(stringToEncrypt)) { throw new ArgumentException("An empty string value cannot be encrypted."); } if (string.IsNullOrEmpty(key)) { throw new ArgumentException("Cannot encrypt using an empty key. Please supply an encryption key."); } System.Security.Cryptography.CspParameters cspp = new System.Security.Cryptography.CspParameters(); cspp.KeyContainerName = key; System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider(cspp); rsa.PersistKeyInCsp = true; byte[] bytes = rsa.Encrypt(System.Text.UTF8Encoding.UTF8.GetBytes(stringToEncrypt), true); return BitConverter.ToString(bytes); } </code></pre> <p>Decrypt ; </p> <pre><code>public static string Decrypt(this string stringToDecrypt, string key) { string result = null; if (string.IsNullOrEmpty(stringToDecrypt)) { throw new ArgumentException("An empty string value cannot be encrypted."); } if (string.IsNullOrEmpty(key)) { throw new ArgumentException("Cannot decrypt using an empty key. Please supply a decryption key."); } try { System.Security.Cryptography.CspParameters cspp = new System.Security.Cryptography.CspParameters(); cspp.KeyContainerName = key; System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider(cspp); rsa.PersistKeyInCsp = true; string[] decryptArray = stringToDecrypt.Split(new string[] { "-" }, StringSplitOptions.None); byte[] decryptByteArray = Array.ConvertAll&lt;string, byte&gt;(decryptArray, (s =&gt; Convert.ToByte(byte.Parse(s, System.Globalization.NumberStyles.HexNumber)))); byte[] bytes = rsa.Decrypt(decryptByteArray, true); result = System.Text.UTF8Encoding.UTF8.GetString(bytes); } finally { // no need for further processing } return result; } </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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