예제 #1
0
        public static string Decrypt(CipherPair cp)
        {
            byte[] plaintext = ProtectedData.Unprotect(cp.Cipher, cp.IV, DataProtectionScope.CurrentUser);
            string val       = System.Text.Encoding.Unicode.GetString(plaintext);

            return(val);
        }
예제 #2
0
        public static CipherPair Encrypt(string text)
        {
            // Data to protect. Convert a string to a byte[] using Encoding.UTF8.GetBytes().
            byte[] plaintext = System.Text.Encoding.Unicode.GetBytes(text);

            // Generate additional entropy (will be used as the Initialization vector)
            byte[] entropy = CryptoHelper.GenerateRandomByteArray(20);

            byte[] ciphertext = ProtectedData.Protect(plaintext, entropy,
                DataProtectionScope.CurrentUser);

            CipherPair cp = new CipherPair(ciphertext, entropy);
            return cp;
        }
예제 #3
0
        public static CipherPair Encrypt(string text)
        {
            // Data to protect. Convert a string to a byte[] using Encoding.UTF8.GetBytes().
            byte[] plaintext = System.Text.Encoding.Unicode.GetBytes(text);

            // Generate additional entropy (will be used as the Initialization vector)
            byte[] entropy = CryptoHelper.GenerateRandomByteArray(20);

            byte[] ciphertext = ProtectedData.Protect(plaintext, entropy,
                                                      DataProtectionScope.CurrentUser);

            CipherPair cp = new CipherPair(ciphertext, entropy);

            return(cp);
        }
예제 #4
0
 public static string Decrypt(CipherPair cp)
 {
     byte[] plaintext = ProtectedData.Unprotect(cp.Cipher, cp.IV, DataProtectionScope.CurrentUser);
     string val = System.Text.Encoding.Unicode.GetString(plaintext);
     return val;
 }