Example #1
0
        public static Byte[] CRAM_MD5(String Token, String Login, String Password)
        {
            var HMAC_MD5 = new HMACMD5(Password.ToUTF8Bytes());
            var digest   = HMAC_MD5.ComputeHash(Token.ToUTF8Bytes());

            // result := login[space]digest
            return Login.ToUTF8Bytes().
                   Concat(new Byte[1] { 0x20 }).
                   Concat(digest.ToHexString().ToUTF8Bytes()).
                   ToArray();
        }
Example #2
0
 public TCPClientRequest Send(String Request)
 {
     var _Request = Request.ToUTF8Bytes();
     TCPStream.Write(_Request, 0, _Request.Length);
     return this;
 }
Example #3
0
 /// <summary>
 /// The HTTP content/body.
 /// </summary>
 /// <param name="String">The HTTP content/body.</param>
 public HTTPRequestBuilder SetContent(String String)
 {
     this.Content = String.ToUTF8Bytes();
     return this;
 }
Example #4
0
 /// <summary>
 /// Writes some UTF-8 text to the underlying stream.
 /// </summary>
 /// <param name="UTF8Text">Some UTF-8 text.</param>
 public void WriteToResponseStream(String UTF8Text)
 {
     WriteToResponseStream(UTF8Text.ToUTF8Bytes());
 }
Example #5
0
        public static Byte[] CRAM_MD5_(String Token, String Login, String Password)
        {
            var token       = Token.   ToUTF8Bytes();
            var password    = Password.ToUTF8Bytes();
            var ipad        = new Byte[64];
            var opad        = new Byte[64];
            var startIndex  = 0;
            var length      = token.Length;

            // see also: http://tools.ietf.org/html/rfc2195 - 2. Challenge-Response Authentication Mechanism (CRAM)
            //           http://tools.ietf.org/html/rfc2104 - 2. Definition of HMAC

            #region Copy the password into inner/outer padding and XOR it accordingly

            if (password.Length > ipad.Length)
            {
                var HashedPassword = new MD5CryptoServiceProvider().ComputeHash(password);
                Array.Copy(HashedPassword, ipad, HashedPassword.Length);
                Array.Copy(HashedPassword, opad, HashedPassword.Length);
            }
            else
            {
                Array.Copy(password, ipad, password.Length);
                Array.Copy(password, opad, password.Length);
            }

            for (var i = 0; i < ipad.Length; i++) {
                ipad[i] ^= 0x36;
                opad[i] ^= 0x5c;
            }

            #endregion

            #region Calculate the inner padding

            byte[] digest;

            using (var MD5 = new MD5CryptoServiceProvider())
            {
                MD5.TransformBlock     (ipad, 0, ipad.Length, null, 0);
                MD5.TransformFinalBlock(token, startIndex, length);
                digest = MD5.Hash;
            }

            #endregion

            #region Calculate the outer padding

            // oPAD (will use iPAD digest!)
            using (var MD5 = new MD5CryptoServiceProvider())
            {
                MD5.TransformBlock     (opad, 0, opad.Length, null, 0);
                MD5.TransformFinalBlock(digest, 0, digest.Length);
                digest = MD5.Hash;
            }

            #endregion

            // result := login[space]digest
            return Login.ToUTF8Bytes().
                   Concat(new Byte[1] { 0x20 }).
                   Concat(digest.ToHexString().ToUTF8Bytes()).
                   ToArray();
        }