コード例 #1
0
ファイル: Encryption.cs プロジェクト: skowronek/googlesyncmod
        public static string DecryptPassword(string email, string encryptedPassword)
        {
            try
            {
                using (RijndaelManaged rijndael = new RijndaelManaged())
                {
                    //RijndaelManaged rijndael = new RijndaelManaged();

                    rijndael.IV  = GetIV(email);
                    rijndael.Key = GetKey(email);

                    ICryptoTransform decryptor = rijndael.CreateDecryptor(rijndael.Key, rijndael.IV);

                    //Now decrypt the previously encrypted password using the decryptor obtained in the above step.
                    byte[] encrypted = HexEncoding.GetBytes(encryptedPassword);
                    using (MemoryStream msDecrypt = new MemoryStream(encrypted))
                    {
                        CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read);

                        //byte[] fromEncrypt = new byte[encrypted.Length];
                        byte[] fromEncrypt = ReadFully(csDecrypt);//(

                        //Read the data out of the crypto stream.
                        //csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);
                        //csDecrypt.Close();
                        //msDecrypt.Close();

                        //Convert the byte array back into a string.
                        string result = new ASCIIEncoding().GetString(fromEncrypt);
                        return(result);
                    }
                }
            }
            catch (Exception e)
            {
                throw new PasswordEncryptionException("Error decryption password", e);
            }
        }