Exemple #1
0
        /// <summary>
        /// Computes the challenge hash from the challengeBytes and the password. The client has a matching function to create the same.
        /// </summary>
        /// <returns>The challenge hash.</returns>
        /// <param name="challengeBytes">Challenge bytes.</param>
        /// <param name="password">Password.</param>
        public static string ComputeChallengeHash(byte[] challengeBytes, string password)
        {
            // By-and-large the following is nearly verbatim from the InWorldz.Whip.Client.AuthResponse construcutor.

            //convert the password to ascii
            var encoding = new ASCIIEncoding();
            var asciiPW  = encoding.GetBytes(password ?? string.Empty);

            var authString = new AppendableByteArray(asciiPW.Length + challengeBytes.Length);

            authString.Append(asciiPW);
            authString.Append(challengeBytes);

            var sha           = new SHA1CryptoServiceProvider();
            var challengeHash = sha.ComputeHash(authString.data);

            return(InWorldz.Whip.Client.Util.HashToHex(challengeHash));
        }
Exemple #2
0
        private static byte[] GenerateAuthResponsePacket(byte[] challengeBytes, string password)
        {
            //convert the password to ascii
            var encoding = new System.Text.ASCIIEncoding();
            var asciiPW  = encoding.GetBytes(password);

            //add the two ranges together and compute the hash
            var authString = new AppendableByteArray(asciiPW.Length + challengeBytes.Length);

            authString.Append(asciiPW);
            authString.Append(challengeBytes);

            var sha = new SHA1CryptoServiceProvider();

            byte[] challengeHash = sha.ComputeHash(authString.data);

            //copy the results to the raw packet data
            var rawMessageData = new AppendableByteArray(RESPONSE_PACKET_MESSAGE_SIZE);

            rawMessageData.Append(RESPONSE_PACKET_IDENTIFIER);
            rawMessageData.Append(encoding.GetBytes(Util.HashToHex(challengeHash)));

            return(rawMessageData.data);
        }