Note that there are some explanatory texts on larger screens.

plurals
  1. POHow many characters to create a byte array for my AES method?
    text
    copied!<p>I am using the AES methods here: <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged.aspx</a></p> <p>I want to have a string value that I will convert to byte array and pass it to the AES encrypt method. How many characters should the string be to produce the correct byte array size that the method expects?</p> <pre><code>static byte[] encryptStringToBytes_AES(string plainText, byte[] Key, byte[] IV) { // Check arguments. if (plainText == null || plainText.Length &lt;= 0) throw new ArgumentNullException("plainText"); if (Key == null || Key.Length &lt;= 0) throw new ArgumentNullException("Key"); if (IV == null || IV.Length &lt;= 0) throw new ArgumentNullException("Key"); // Declare the stream used to encrypt to an in memory // array of bytes. MemoryStream msEncrypt = null; // Declare the RijndaelManaged object // used to encrypt the data. RijndaelManaged aesAlg = null; try { // Create a RijndaelManaged object // with the specified key and IV. aesAlg = new RijndaelManaged(); aesAlg.Key = Key; aesAlg.IV = IV; // Create a decrytor to perform the stream transform. ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV); // Create the streams used for encryption. msEncrypt = new MemoryStream(); using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) { using (StreamWriter swEncrypt = new StreamWriter(csEncrypt)) { //Write all data to the stream. swEncrypt.Write(plainText); } } } finally { // Clear the RijndaelManaged object. if (aesAlg != null) aesAlg.Clear(); } // Return the encrypted bytes from the memory stream. return msEncrypt.ToArray(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload