Steganografie/Encryption/BaseEncryption.cs
/// <summary>
/// Decrypts the input with a given password and converts it from Base64
/// </summary>
/// <param name="text"></param>
/// <param name="password"></param>
/// <returns></returns>
Decrypts the input with a given password and converts it from Base64
Decrypts the input with a given password and converts it from Base64
protected string DecryptText(byte[] input, ref string password)
        {
            string text = Encoding.UTF8.GetString(input);
            byte[] bytePassword = HashPassword(ref password);
            byte[] IV = GetIV(text.Substring(text.LastIndexOf("IV=") + 3)).ToArray();
            text = text.Remove(text.LastIndexOf("IV="));
            try
            {
                var ms = new MemoryStream(Convert.FromBase64String(text));
                var rmCrypto = new RijndaelManaged {KeySize = 128, Key = bytePassword, BlockSize = 256, IV = IV};
                using (var cryptStream = new CryptoStream(ms, rmCrypto.CreateDecryptor(rmCrypto.Key, rmCrypto.IV), CryptoStreamMode.Read))
                using (var sr = new StreamReader(cryptStream))
                {
                    return sr.ReadToEnd();
                }
            }
            catch (Exception e)
            {
                return text;
            }
        }
protected string DecryptText ( byte [ ] input , ref string password ) { string text = Encoding . UTF8 . GetString ( input ) ; byte [ ] bytePassword = HashPassword ( ref password ) ; byte [ ] IV = GetIV ( text . Substring ( text . LastIndexOf ( " " ) + 3 ) ) . ToArray ( ) ; text = text . Remove ( text . LastIndexOf ( " " ) ) ; try { var ms = new MemoryStream ( Convert . FromBase64String ( text ) ) ; var rmCrypto = new RijndaelManaged { KeySize = 128 , Key = bytePassword , BlockSize = 256 , IV = IV } ; using ( var cryptStream = new CryptoStream ( ms , rmCrypto . CreateDecryptor ( rmCrypto . Key , rmCrypto . IV ) , CryptoStreamMode . Read ) ) using ( var sr = new StreamReader ( cryptStream ) ) { return sr . ReadToEnd ( ) ; } } catch ( Exception e ) { return text ; } }
Decrypts the input with a given password and converts it from Base64
Decrypts the input with a given password and converts it from Base64
None
input
byte[]
string
ref
text
None
password
None