Beispiel #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);
        }
Beispiel #2
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);
        }