Before you can use the .NET Framework's cryptography tools to encrypt and decrypt strings (or files, arrays of bytes, or just about anything else), you need to perform some setup. The following method creates an ICryptoTransform object that you can use to encrypt or decrypt data:
// Prepare a cryptographic transformation for this password// and SymmetricAlgorithm.private static ICryptoTransform MakeCryptoTransform( string password, bool doEncryption, SymmetricAlgorithm cryptoProvider){ // Find a valid key size for this provider. int numKeyBits = FindKeySize(cryptoProvider); Console.WriteLine($"Key size: {numKeyBits} bits"); // Get the block size for this provider. int blockSizeBits = cryptoProvider.BlockSize; ...