title: How to Encrypt a n byte string with a n byte encryption result using Rijndael encryption C#
body: <p>I'm having a issue. This Encrypts my name perfectly. My name comes in as 4 long so the name might come in as "John" but then it Encrypts it as abcasdlkj123908=! (something like that) is there a way I can have it encrypt something instead like w124 that is the same length of the initial variable string it encrpyted? Also what if the name comes in as Darryl and is 6 long ? I need to deal with that too</p>
  
  <pre><code>public string EncryptAName(string someName)
      {
          Rijndael rinj = new RijndaelManaged();
          string encryptionKey = "HERPDERP";
          rinj.Mode = CipherMode.CBC;
          rinj.Padding = PaddingMode.PKCS7;
          rinj.KeySize = 0x80;    // Decimal: 128
          rinj.BlockSize = 0x80;
          byte[] passwordBytes = Encoding.UTF8.GetBytes(encryptionKey);
          byte[] encryptionKeyBytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
          int passwordBytesLength = passwordBytes.Length;
  
          if (passwordBytesLength &gt; encryptionKeyBytes.Length)
          {
              passwordBytesLength = encryptionKeyBytes.Length;
          }
  
          Array.Copy(passwordBytes, encryptionKeyBytes, passwordBytesLength);
  
          rinj.Key = encryptionKeyBytes;
          rinj.IV = encryptionKeyBytes;
  
          ICryptoTransform ict = rinj.CreateEncryptor();
          byte[] someNameByte = Encoding.UTF8.GetBytes(someName);
          someName = Convert.ToBase64String(ict.TransformFinalBlock(someNameByte, 0, someNameByte.Length));
  
          return someName;
      }
  </code></pre>