Api.Encryption.StringCipher.Decrypt C# (CSharp) Метод

Decrypt() публичный статический Метод

public static Decrypt ( string cipherText, string passPhrase ) : string
cipherText string
passPhrase string
Результат string
        public static string Decrypt(string cipherText, string passPhrase)
        {
            byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
            using (PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, null))
            {
                byte[] keyBytes = password.GetBytes(keysize / 8);
                using (RijndaelManaged symmetricKey = new RijndaelManaged())
                {
                    symmetricKey.Mode = CipherMode.CBC;
                    using (ICryptoTransform decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes))
                    {
                        using (MemoryStream memoryStream = new MemoryStream(cipherTextBytes))
                        {
                            using (CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
                            {
                                byte[] plainTextBytes = new byte[cipherTextBytes.Length];
                                int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
                                return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
                            }
                        }
                    }
                }
            }
        }
    }

Usage Example

Пример #1
0
        public static AuthorizationViewModel DecryptAuthorization(AuthorizationViewModel auth)
        {
            if (auth.GuId != null)
            {
                auth.GuId = StringCipher.Decrypt(auth.GuId, EncryptKey);
            }

            return(auth);
        }
All Usage Examples Of Api.Encryption.StringCipher::Decrypt
StringCipher