RijndaelManaged rijndael = new RijndaelManaged(); rijndael.GenerateIV();
string textToEncrypt = "This is a secret message."; byte[] key = Encoding.ASCII.GetBytes("MySecretKey123456"); byte[] iv = new byte[16]; using (RijndaelManaged rijndael = new RijndaelManaged()) { rijndael.Key = key; rijndael.IV = iv; ICryptoTransform encryptor = rijndael.CreateEncryptor(rijndael.Key, rijndael.IV); byte[] encrypted = null; using (MemoryStream ms = new MemoryStream()) { using (CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write)) { using (StreamWriter sw = new StreamWriter(cs)) { sw.Write(textToEncrypt); } encrypted = ms.ToArray(); } } }In this example, a string is encrypted using a specific key value and IV. The RijndaelManaged class is used to set the key and IV values and create an encryptor object. The string is then passed through a series of streams to encrypt it using the Rijndael algorithm. The package library for the Rijndael algorithm in C# is the System.Security.Cryptography library, which provides classes for implementing cryptography in C# applications.