Example #1
0
        /// <summary>
        /// Encrypts the given byte array using Rijndael / AES.
        /// The array is aligned on 16 bytes.
        /// </summary>
        /// <param name="aBytes">The array of bytes to be encrypted</param>
        /// <returns>Byte array that holds the encryped version of the aBytes parameter</returns>
        public byte[] Encrypt(byte[] aBytes)
        {
            Logger.LogTrace("Enter");
            // Reset the lenght of the string to exact blocks of 16 bytes
            var length = aBytes.Length;
            var add    = 0;

            if (length % 16 != 0)
            {
                add = 16 - (length % 16);
            }
            var bytes = new byte[add + length];

            Buffer.BlockCopy(aBytes, 0, bytes, 0, length);
            for (var i = 0; i < add; i++)
            {
                bytes[length + i] = 32;
            }

            Logger.LogDebug("Number of bytes added: " + add);

            _encrypted = QboxNextRijndael.Encrypt(bytes, Key, Iv, 256);

            Logger.LogTrace("Return");
            return(_encrypted);
        }
Example #2
0
 public string Decrypt(byte[] encryptedBytes)
 {
     _decrypted = QboxNextRijndael.Decrypt(encryptedBytes, Key, Iv, 256);
     if (_decrypted == null)
     {
         return(null);
     }
     return(Encoding.UTF8.GetString(_decrypted).Trim());
 }
Example #3
0
        /// <summary>
        /// Encrypts the given string using RijnDael / AES.
        /// The text is padded to a length of multiple of 16 bytes.
        /// </summary>
        /// <param name="aText">The string the must be encrypted</param>
        /// <returns>an array of bytes holding the encrypted version of the string aText</returns>
        public byte[] Encrypt(string aText)
        {
            // Reset the lenght of the string to exact blocks of 16 bytes
            int length = aText.Length;
            int add    = 0;

            if (length % 16 != 0)
            {
                add = 16 - (length % 16);
            }

            Logger.LogDebug("Number of bytes to add: " + add);

            string text = aText.PadRight(add + length, ' ');

            _decrypted = Encoding.UTF8.GetBytes(text);
            _encrypted = QboxNextRijndael.Encrypt(_decrypted, Key, Iv, 256);
            return(_encrypted);
        }
Example #4
0
 public QboxRijndael()
 {
     Key = QboxNextRijndael.StringToHex("00010203050607080A0B0C0D0F10111214151617191A1B1C1E1F202123242526");
     Iv  = QboxNextRijndael.StringToHex("00000000000000000000000000000000");
 }
Example #5
0
 public byte[] DecryptBytes(byte[] encryptedBytes)
 {
     return(QboxNextRijndael.Decrypt(encryptedBytes, Key, Iv, 256));
 }