示例#1
0
        private static string GetEncodedPassword()
        {
            byte[] encoded = DPAPI.Encrypt(DPAPI.KeyType.UserKey, Encoding.Unicode.GetBytes(password), null, null);
            string temp    = BitConverter.ToString(encoded).Replace("-", "");

            return(temp);
        }
示例#2
0
        static void OldMain(string[] args)
        {
            try
            {
                string text    = "Hello, world!";
                string entropy = null;
                string description;

                Console.WriteLine("Plaintext: {0}\r\n", text);

                // Call DPAPI to encrypt data with user-specific key.
                string encrypted = DPAPI.Encrypt(DPAPI.KeyType.UserKey,
                                                 text,
                                                 entropy,
                                                 "My Data");
                Console.WriteLine("Encrypted: {0}\r\n", encrypted);

                // Call DPAPI to decrypt data.
                string decrypted = DPAPI.Decrypt(encrypted,
                                                 entropy,
                                                 out description);
                Console.WriteLine("Decrypted: {0} <<<{1}>>>\r\n",
                                  decrypted, description);
            }
            catch (Exception ex)
            {
                while (ex != null)
                {
                    Console.WriteLine(ex.Message);
                    ex = ex.InnerException;
                }
            }
        }