Exemplo n.º 1
0
        public string InternalsToString()
        {
            string str1 = string.Format("SRP {0} Internals:\n", IsServer ? "server" : "client") +
                          string.Format("G      = {0}\n", Generator.ToHexString()) +
                          string.Format("K      = {0}\n", Multiplier.ToHexString()) +
                          string.Format("N      = {0}\n", Modulus.ToHexString()) +
                          string.Format("I      = '{0}'\n", Credentials) +
                          string.Format("Hash(I)= {0}\n",
                                        Hash((HashUtilities.HashDataBroker)Credentials).ToHexString()) +
                          string.Format("X      = {0}\n", CredentialsHash.ToHexString()) +
                          string.Format("V      = {0}\n", Verifier.ToHexString());

            if (m_salt != null)
            {
                str1 += string.Format("Salt   = {0}\n", Salt.ToHexString());
            }
            if (null != m_publicEphemeralValueA && null != m_publicEphemeralValueB)
            {
                str1 = str1 + string.Format("u      = {0}\n", ScramblingParameter.ToHexString()) +
                       string.Format("h(A)   = {0}\n",
                                     Hash((HashUtilities.HashDataBroker)PublicEphemeralValueA)
                                     .ToHexString()) + string.Format("h(B)   = {0}\n",
                                                                     Hash((HashUtilities.HashDataBroker)PublicEphemeralValueB.GetBytes())
                                                                     .ToHexString());
            }
            if (!IsServer || PublicEphemeralValueA != null)
            {
                str1 += string.Format("A      = {0}\n", PublicEphemeralValueA.ToHexString());
            }
            if (IsServer || PublicEphemeralValueB != null)
            {
                string     str2        = str1 + string.Format("B      = {0}\n", PublicEphemeralValueB.ToHexString());
                BigInteger bigInteger1 = Multiplier * Generator.ModPow(CredentialsHash, Modulus);
                string     str3        = str2 + string.Format("kg^x   = {0}\n", bigInteger1.ToHexString());
                BigInteger bigInteger2 = PublicEphemeralValueB - bigInteger1 % Modulus;
                if (bigInteger2 < 0)
                {
                    bigInteger2 += Modulus;
                }
                str1 = str3 + string.Format("B-kg^x = {0}\n", bigInteger2.ToHexString());
            }

            string str4;

            try
            {
                str4 = str1 + string.Format("S.key  = {0}\n", SessionKey.ToHexString());
            }
            catch
            {
                str4 = str1 + "S.key  = empty\n";
            }

            return(str4);
        }
Exemplo n.º 2
0
        public string InternalsToString()
        {
            string type = IsServer ? "server" : "client";
            string str  = string.Format("SRP {0} Internals:\n", type);

            str += string.Format("G      = {0}\n", Generator.ToHexString());
            str += string.Format("K      = {0}\n", Multiplier.ToHexString());
            str += string.Format("N      = {0}\n", Modulus.ToHexString());

            str += string.Format("I      = '{0}'\n", Credentials);
            str += string.Format("Hash(I)= {0}\n", Hash(Credentials).ToHexString());
            str += string.Format("X      = {0}\n", CredentialsHash.ToHexString());
            str += string.Format("V      = {0}\n", Verifier.ToHexString());
            if (m_salt != null)
            {
                str += string.Format("Salt   = {0}\n", Salt.ToHexString());
            }
            if (null != m_publicEphemeralValueA && null != m_publicEphemeralValueB)
            {
                str += string.Format("u      = {0}\n", ScramblingParameter.ToHexString());
                str += string.Format("h(A)   = {0}\n", Hash(PublicEphemeralValueA).ToHexString());
                str += string.Format("h(B)   = {0}\n", Hash(PublicEphemeralValueB.GetBytes()).ToHexString());
            }

            if (IsServer == false || PublicEphemeralValueA != null)
            {
                str += string.Format("A      = {0}\n", PublicEphemeralValueA.ToHexString());
            }
            if (IsServer || PublicEphemeralValueB != null)
            {
                str += string.Format("B      = {0}\n", PublicEphemeralValueB.ToHexString());
                BigInteger tmp = Multiplier * Generator.ModPow(CredentialsHash, Modulus);
                str += string.Format("kg^x   = {0}\n", tmp.ToHexString());
                tmp  = PublicEphemeralValueB - tmp % Modulus;
                if (tmp < 0)
                {
                    tmp += Modulus;
                }
                str += string.Format("B-kg^x = {0}\n", tmp.ToHexString());
            }

            try
            {
                str += string.Format("S.key  = {0}\n", SessionKey.ToHexString());
            }
            catch
            {
                str += "S.key  = empty\n";
            }

            return(str);
        }