Windows Phone Security : Encrypt and Decrypt

Windows Phone Security : Encrypt and Decrypt

Rate This
  • Comments 0

Often times you may want to secure the user data. However, there is one native API to support

using System.Security.Cryptography;
using System.Text;
byte[] secretPassword; // to store it in a variable 
private void btnEncrypt_Click(object sender, RoutedEventArgs e)
    //Convert the text to byte[] 
    byte[] clearPassword = Encoding.UTF8.GetBytes(txtData.Text);
    secretPassword = ProtectedData.Protect(clearPassword, null);
    txtDecryptText.Text = "Encrypted...";
    txtData.Text = "";
private void btnDecrypt_Click(object sender, RoutedEventArgs e)
    byte[] protectedPassowrd = secretPassword;
    //Decrypt the text
    byte[] unprotectPassword = ProtectedData.Unprotect(protectedPassowrd, null);
    txtDecryptText.Text = Encoding.UTF8.GetString(unprotectPassword, 0, unprotectPassword.Length);
    txtDecryptText.Text = "Decrypted...";


Leave a Comment
  • Please add 8 and 5 and type the answer here:
  • Post