Exemple #1
0
 /// <summary>
 /// Gets a hex representation of this buffer.
 /// </summary>
 /// <returns>A string representing this buffer's contents in hexadecimal notation.</returns>
 public override string ToString()
 {
     return(DataFormatter.Format(UnderlyingBuffer, 0, Count));
 }
Exemple #2
0
 /// <summary>
 /// Gets a hex representation of this data.
 /// </summary>
 /// <returns>A string representing this buffer's contents in hexadecimal notation.</returns>
 public override string ToString()
 {
     return(DataFormatter.Format(this.UnderlyingBuffer, 0, this.Length));
 }
Exemple #3
0
 /// <summary>
 /// Gets a hex representation of this buffer.
 /// </summary>
 /// <returns>A string representing this buffer's contents in hexadecimal notation.</returns>
 public override string ToString()
 {
     return(DataFormatter.Format(m_data, 0, Length));
 }
Exemple #4
0
        private void CalculateM1(byte[] saltFromServer, byte[] issuedServerKey)
        {
            BigInteger local_B = new BigInteger(ReverseArray(issuedServerKey));

            //BigInteger local_B = new BigInteger(serverKey);

            // first calculate u.
            byte[]     u_sha = s_sha.ComputeHash(issuedServerKey);
            BigInteger u     = new BigInteger(u_sha, 4);

            if (verifier == null)
            {
                CalculateVerifier(saltFromServer);
            }

            // then we need to calculate S.
            BigInteger local_S = ((s_modulus + local_B - verifier) % s_modulus);

            local_S = local_S.ModPow((a + (u * x)), s_modulus);
            byte[] bytes_s = EnsureArrayLength(ReverseArray(local_S.GetBytes()), 32);
            //byte[] bytes_s = local_S.GetBytes();

            // now K.  yeah, this is weird.
            byte[] even_s = new byte[16];
            byte[] odds_s = new byte[16];
            for (int i = 0, j = 0; i < bytes_s.Length; i += 2, j++)
            {
                even_s[j] = bytes_s[i];
                odds_s[j] = bytes_s[i + 1];
            }
            byte[] even_hash = s_sha.ComputeHash(even_s);
            byte[] odds_hash = s_sha.ComputeHash(odds_s);
            byte[] local_k   = new byte[40];
            for (int i = 0; i < local_k.Length; i++)
            {
                if ((i & 1) == 0)
                {
                    local_k[i] = even_hash[i / 2];
                }
                else
                {
                    local_k[i] = odds_hash[i / 2];
                }
            }

            // finally, m1.
            BigInteger sha_g   = new BigInteger(s_sha.ComputeHash(ReverseArray(s_generator.GetBytes())));
            BigInteger sha_n   = new BigInteger(s_sha.ComputeHash(ReverseArray(s_modulus.GetBytes())));
            BigInteger g_xor_n = sha_g ^ sha_n;

            MemoryStream ms = new MemoryStream(40 + saltFromServer.Length + A.GetBytes().Length + issuedServerKey.Length + local_k.Length);
            BinaryWriter bw = new BinaryWriter(ms);

            bw.Write(g_xor_n.GetBytes());
            bw.Write(s_sha.ComputeHash(Encoding.ASCII.GetBytes(userName.ToUpper(CultureInfo.InvariantCulture))));
            bw.Write(saltFromServer);
            bw.Write(EnsureArrayLength(A.GetBytes(), 32));
#if DEBUG
            if (A.GetBytes().Length < 32)
            {
                DataFormatter.WriteToTrace(A.GetBytes(), "A length less than 32 bytes");
            }
#endif
            bw.Write(issuedServerKey);
            bw.Write(local_k);

            byte[] m1_data = ms.GetBuffer();
            ms.Close();
            byte[] m1_hash = s_sha.ComputeHash(m1_data);

            lock (this)
            {
                this.k = local_k;
                //this.salt = saltFromServer;
                //this.serverKey = issuedServerKey;
                //this.S = local_S;
                m1 = new BigInteger(m1_hash);
            }
        }