コード例 #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;
 }