title: How to create Aes 256bit Encryption with key in C# Windows Phone application?
body: <p>I'm trying to create Aes 256bit Encryption with key in login screen. I need a large encrypted string as i'm using 256bit But it result in small encrypted string.I have checked many samples But all are for Windows desktop application not for windows Phone application. Please help regarding this.</p>
  
  <p>This is my code</p>
  
  <pre><code>namespace SampleEncription
  {
      public partial class MainPage : PhoneApplicationPage
      {
          public MainPage()
          {
              InitializeComponent();
              byte[] encryptedPassword;
  
              // Create a new instance of the RijndaelManaged
              // class.  This generates a new key and initialization
              // vector (IV).
              using (var algorithm = new AesManaged())
              {
                  algorithm.KeySize = 256;
                  algorithm.BlockSize = 128;
  
                  // Encrypt the string to an array of bytes.
                  encryptedPassword = Cryptology.EncryptStringToBytes("Password", algorithm.Key, algorithm.IV);
  
                  //string chars = encryptedPassword.Aggregate(string.Empty, (current, b) =&gt; current + b.ToString());
  
                  string chars = System.Convert.ToBase64String(encryptedPassword);
  
                  Debug.WriteLine(chars);
              }
          }
  
      }
  }
  </code></pre>
  
  <p>one another class named cryptology:</p>
  
  <pre><code>namespace SampleEncription
  {
      class Cryptology
      {
          private const string Salt = "603deb1015ca71be2b73aef0857d7781";
          private const int SizeOfBuffer = 1024 * 8;
  
          internal static byte[] EncryptStringToBytes(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");
              }
  
              byte[] encrypted;
              // Create an RijndaelManaged object
              // with the specified key and IV.
              using (var rijAlg = new AesManaged())
              {
                  rijAlg.Key = key;
                  rijAlg.IV = iv;
  
                  // Create a decrytor to perform the stream transform.
                  ICryptoTransform encryptor = rijAlg.CreateEncryptor(rijAlg.Key, rijAlg.IV);
  
                  // Create the streams used for encryption.
                  using (var msEncrypt = new MemoryStream())
                  {
                      using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
                      {
                          using (var swEncrypt = new StreamWriter(csEncrypt))
                          {
                              //Write all data to the stream.
                              swEncrypt.Write(plainText);
                          }
                          encrypted = msEncrypt.ToArray();
                      }
                  }
              }
  
  
              // Return the encrypted bytes from the memory stream.
              return encrypted;
  
          }
      }
  }
  </code></pre>