title: How is encryption done without encoding the string to byte[]?
body: <p>I've been trying to understand encryption/decryption code of TripleDES for some days. And I have seen many codes in the google, and the code shown below is one of them. </p>
  
  <pre><code>static void Main(string[] args)
      {
  
          string original = "Here is some data to encrypt!";
          TripleDESCryptoServiceProvider myTripleDES = new TripleDESCryptoServiceProvider();
          byte[] encrypted = EncryptStringToBytes(original, myTripleDES.Key, myTripleDES.IV);
          string encrypt = Convert.ToBase64String(encrypted);
          string roundtrip = DecryptStringFromBytes(encrypted, myTripleDES.Key, myTripleDES.IV);
          Console.WriteLine("encryted:   {0}", encrypt);
          Console.WriteLine("Round Trip: {0}", roundtrip);
          Console.ReadLine();
      }
  
  
  
      static byte[] EncryptStringToBytes(string plainText, byte[] Key, byte[] IV)
      {
  
          byte[] encrypted; 
          using (TripleDESCryptoServiceProvider tdsAlg = new TripleDESCryptoServiceProvider())
          {
              tdsAlg.Key = Key;
              tdsAlg.IV = IV;
              ICryptoTransform encryptor = tdsAlg.CreateEncryptor(tdsAlg.Key, tdsAlg.IV);
              using (MemoryStream msEncrypt = new MemoryStream())
              {
                  using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
                  {
                      using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
                      {
                          swEncrypt.Write(plainText);
                      }
                      encrypted = msEncrypt.ToArray();
                  }
              }
          }
          return encrypted;
      }
  
  
      static string DecryptStringFromBytes(byte[] cipherText, byte[] Key, byte[] IV)
      { 
          string plaintext = null; 
          using (TripleDESCryptoServiceProvider tdsAlg = new TripleDESCryptoServiceProvider())
          {
              tdsAlg.Key = Key;
              tdsAlg.IV = IV;
              ICryptoTransform decryptor = tdsAlg.CreateDecryptor(tdsAlg.Key, tdsAlg.IV);
              using (MemoryStream msDecrypt = new MemoryStream(cipherText))
              {
                  using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
                  {
                      using (StreamReader srDecrypt = new StreamReader(csDecrypt))
                      {
                          plaintext = srDecrypt.ReadToEnd();
                      }
                  }
              }
  
          }
  
          return plaintext;
  
      } 
  </code></pre>
  
  <p>There is no error in the code. I works fine. But strangely I noticed that the plainText is never been encoded. There is no line like <code>Encoding.Unicode.GetBytes(plainText);</code> or <code>Encoding.UTF8.GetBytes(plainText);</code> or similar like that. So, my question is , how does (in the code) the plainText which is a string gets converted to the encrypted byte? Is there any work done inside the streams? If thats so then where and how? As far as I understood there is no such line in between the streams that converts the string to byte. So , How does the overall code is working without this basic transformation? </p>
  
  <p>Update: 
  Is this code really a valid code? </p>