Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here you go. I found it somewhere on the internet. Works well for me.</p> <pre><code> /// &lt;summary&gt; /// Encrypts a given password and returns the encrypted data /// as a base64 string. /// &lt;/summary&gt; /// &lt;param name="plainText"&gt;An unencrypted string that needs /// to be secured.&lt;/param&gt; /// &lt;returns&gt;A base64 encoded string that represents the encrypted /// binary data. /// &lt;/returns&gt; /// &lt;remarks&gt;This solution is not really secure as we are /// keeping strings in memory. If runtime protection is essential, /// &lt;see cref="SecureString"/&gt; should be used.&lt;/remarks&gt; /// &lt;exception cref="ArgumentNullException"&gt;If &lt;paramref name="plainText"/&gt; /// is a null reference.&lt;/exception&gt; public string Encrypt(string plainText) { if (plainText == null) throw new ArgumentNullException("plainText"); //encrypt data var data = Encoding.Unicode.GetBytes(plainText); byte[] encrypted = ProtectedData.Protect(data, null, Scope); //return as base64 string return Convert.ToBase64String(encrypted); } /// &lt;summary&gt; /// Decrypts a given string. /// &lt;/summary&gt; /// &lt;param name="cipher"&gt;A base64 encoded string that was created /// through the &lt;see cref="Encrypt(string)"/&gt; or /// &lt;see cref="Encrypt(SecureString)"/&gt; extension methods.&lt;/param&gt; /// &lt;returns&gt;The decrypted string.&lt;/returns&gt; /// &lt;remarks&gt;Keep in mind that the decrypted string remains in memory /// and makes your application vulnerable per se. If runtime protection /// is essential, &lt;see cref="SecureString"/&gt; should be used.&lt;/remarks&gt; /// &lt;exception cref="ArgumentNullException"&gt;If &lt;paramref name="cipher"/&gt; /// is a null reference.&lt;/exception&gt; public string Decrypt(string cipher) { if (cipher == null) throw new ArgumentNullException("cipher"); //parse base64 string byte[] data = Convert.FromBase64String(cipher); //decrypt data byte[] decrypted = ProtectedData.Unprotect(data, null, Scope); return Encoding.Unicode.GetString(decrypted); } </code></pre>
    singulars
    1. This table or related slice is empty.
    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