Steganografie/Encryption/BaseEncryption.cs
/// <summary>
/// Encrypts the input text with a given password and converts it to Base64
/// </summary>
/// <returns></returns>
Encrypts the input text with a given password and converts it to Base64
Encrypts the input text with a given password and converts it to Base64
protected string EncryptText(ref string text, ref string password)
        {
            byte[] bytePassword = HashPassword(ref password);
            var newText = new StringBuilder();
            var ms = new MemoryStream();
            var rmCrypto = new RijndaelManaged {KeySize = 128, Key = bytePassword, BlockSize = 256};
            using (var cryptStream = new CryptoStream(ms,rmCrypto.CreateEncryptor(rmCrypto.Key, rmCrypto.IV), CryptoStreamMode.Write))
            using (var sw = new StreamWriter(cryptStream))
            {
                sw.Write(text);
            }
            newText.Append(Convert.ToBase64String(ms.ToArray()));
            newText.Append("IV=");
            foreach (var number in rmCrypto.IV)
            {
                newText.Append($"{number};");
            }
            return newText.ToString();
        }
protected string EncryptText ( ref string text , ref string password ) { byte [ ] bytePassword = HashPassword ( ref password ) ; var newText = new StringBuilder ( ) ; var ms = new MemoryStream ( ) ; var rmCrypto = new RijndaelManaged { KeySize = 128 , Key = bytePassword , BlockSize = 256 } ; using ( var cryptStream = new CryptoStream ( ms , rmCrypto . CreateEncryptor ( rmCrypto . Key , rmCrypto . IV ) , CryptoStreamMode . Write ) ) using ( var sw = new StreamWriter ( cryptStream ) ) { sw . Write ( text ) ; } newText . Append ( Convert . ToBase64String ( ms . ToArray ( ) ) ) ; newText . Append ( " " ) ; foreach ( var number in rmCrypto . IV ) { newText . Append ( $" { number } ; " ) ; } return newText . ToString ( ) ; }
Encrypts the input text with a given password and converts it to Base64
Encrypts the input text with a given password and converts it to Base64
None
string
ref