Inheritance: GeneralDigest
Exemplo n.º 1
1
 public static string Md5(string input)
 {
     var data = System.Text.Encoding.UTF8.GetBytes(input);
     MD5Digest hash = new MD5Digest();
     hash.BlockUpdate(data, 0, data.Length);
     byte[] result = new byte[hash.GetDigestSize()];
     hash.DoFinal(result, 0);
     return Hex.ToHexString(result);
 }
Exemplo n.º 2
0
        public static String MD5(String toHashMD5)
        {
            MD5Digest digest = new MD5Digest();
            byte[] scratch = new byte[digest.GetDigestSize()];
            digest.BlockUpdate(UTF8Encoding.UTF8.GetBytes(toHashMD5), 0, UTF8Encoding.UTF8.GetByteCount(toHashMD5));
            digest.DoFinal(scratch, 0);

            string hex = BitConverter.ToString(scratch).ToLower();
            return hex.Replace("-", "");
        }
Exemplo n.º 3
0
		private void CopyIn(MD5Digest t)
		{
			CopyIn((GeneralDigest)t);
			H1 = t.H1;
			H2 = t.H2;
			H3 = t.H3;
			H4 = t.H4;
			Array.Copy(t.X, 0, X, 0, t.X.Length);
			xOff = t.xOff;
		}
Exemplo n.º 4
0
 private void CopyIn(MD5Digest t)
 {
     base.CopyIn(t);
     this.H1 = t.H1;
     this.H2 = t.H2;
     this.H3 = t.H3;
     this.H4 = t.H4;
     Array.Copy(t.X, 0, this.X, 0, t.X.Length);
     this.xOff = t.xOff;
 }
Exemplo n.º 5
0
 private void CopyIn(MD5Digest t)
 {
     CopyIn((GeneralDigest)t);
     H1 = t.H1;
     H2 = t.H2;
     H3 = t.H3;
     H4 = t.H4;
     global::System.Array.Copy((global::System.Array)t.X, 0, (global::System.Array)X, 0, t.X.Length);
     xOff = t.xOff;
 }
Exemplo n.º 6
0
        /**
        * Copy constructor.  This will copy the state of the provided
        * message digest.
        */
        public MD5Digest(MD5Digest t)
            : base(t)
        {
            H1 = t.H1;
            H2 = t.H2;
            H3 = t.H3;
            H4 = t.H4;

            Array.Copy(t.X, 0, X, 0, t.X.Length);
            xOff = t.xOff;
        }
		private void CopyIn(MD5Digest t)
		{
			base.CopyIn(t);
            H1 = t.H1;
            H2 = t.H2;
            H3 = t.H3;
            H4 = t.H4;

            Array.Copy(t.X, 0, X, 0, t.X.Length);
            xOff = t.xOff;
        }
Exemplo n.º 8
0
        /**
         * Copy constructor.  This will copy the state of the provided
         * message digest.
         */
        public MD5Digest(MD5Digest t)
            : base(t)
        {
            H1 = t.H1;
            H2 = t.H2;
            H3 = t.H3;
            H4 = t.H4;

            Array.Copy(t.X, 0, X, 0, t.X.Length);
            xOff = t.xOff;
        }
Exemplo n.º 9
0
        public static byte[] CalculateAnswerBytes(string key1, string key2, ArraySegment<byte> challenge)
        {
            byte[] result1Bytes = ParseKey(key1);
            byte[] result2Bytes = ParseKey(key2);

            var rawAnswer = new byte[16];
            Array.Copy(result1Bytes, 0, rawAnswer, 0, 4);
            Array.Copy(result2Bytes, 0, rawAnswer, 4, 4);
            Array.Copy(challenge.Array, challenge.Offset, rawAnswer, 8, 8);

            #if PORTABLE

            IDigest hash = new MD5Digest();

            byte[] result = new byte[hash.GetDigestSize()];

            hash.BlockUpdate(rawAnswer, 0, rawAnswer.Length);

            hash.DoFinal(result, 0);

            return result;

            //// Convert the message string to binary data.
            //IBuffer buffUtf8Msg = CryptographicBuffer.CreateFromByteArray(rawAnswer);

            //// Create a HashAlgorithmProvider object.
            //HashAlgorithmProvider objAlgProv = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5);

            //// Demonstrate how to retrieve the name of the hashing algorithm.
            //String strAlgNameUsed = objAlgProv.AlgorithmName;

            //// Hash the message.
            //IBuffer buffHash = objAlgProv.HashData(buffUtf8Msg);

            //// Verify that the hash length equals the length specified for the algorithm.
            //if (buffHash.Length != objAlgProv.HashLength)
            //{
            //    throw new Exception("There was an error creating the hash");
            //}

            //// Convert the hash to a string (for display).
            //String strHashBase64 = CryptographicBuffer.EncodeToBase64String(buffHash);

            //byte[] resultArray = new byte[buffHash.Length];
            //CryptographicBuffer.CopyToByteArray(buffHash, out resultArray);

            //return resultArray;
            #else
            return MD5.Create().ComputeHash(rawAnswer);
            #endif
        }
Exemplo n.º 10
0
        public static string MD5Hash(this IFile file)
        {
            using (var fileStream = file.OpenAsync(FileAccess.Read).Result)
            {
                var data = fileStream.ReadFully();

                var md5 = new MD5Digest();
                var md5Hash = new byte[md5.GetDigestSize()];
                md5.BlockUpdate(data, 0, data.Length);
                md5.DoFinal(md5Hash, 0);
                md5.Reset();

                return BitConverter.ToString(md5Hash).Replace("-", "").ToLower();
            }
        }
Exemplo n.º 11
0
		public ITestResult Perform()
        {
            IDigest digest = new MD5Digest();
            byte[] resBuf = new byte[digest.GetDigestSize()];
            string resStr;

            //
            // test 1
            //
            digest.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec1.Equals(resStr))
            {
                return new SimpleTestResult(false,
                    "MD5 failing standard vector test 1"
                    + SimpleTest.NewLine
                    + "    expected: " + resVec1
                    + SimpleTest.NewLine
                    + "    got     : " + resStr);
            }

            //
            // test 2
            //
            byte[] bytes = Hex.Decode(testVec2);

            digest.BlockUpdate(bytes, 0, bytes.Length);

            digest.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec2.Equals(resStr))
            {
                return new SimpleTestResult(false,
                    "MD5 failing standard vector test 2"
                    + SimpleTest.NewLine
                    + "    expected: " + resVec2
                    + SimpleTest.NewLine
                    + "    got     : " + resStr);
            }

            //
            // test 3
            //
            bytes = Hex.Decode(testVec3);

            digest.BlockUpdate(bytes, 0, bytes.Length);

            digest.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec3.Equals(resStr))
            {
                return new SimpleTestResult(false,
                    "MD5 failing standard vector test 3"
                    + SimpleTest.NewLine
                    + "    expected: " + resVec3
                    + SimpleTest.NewLine
                    + "    got     : " + resStr);
            }

            //
            // test 4
            //
            bytes = Hex.Decode(testVec4);

            digest.BlockUpdate(bytes, 0, bytes.Length);

            digest.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec4.Equals(resStr))
            {
                return new SimpleTestResult(false,
                    "MD5 failing standard vector test 4"
                    + SimpleTest.NewLine
                    + "    expected: " + resVec4
                    + SimpleTest.NewLine
                    + "    got     : " + resStr);
            }

            //
            // test 5
            //
            bytes = Hex.Decode(testVec4);

            digest.BlockUpdate(bytes, 0, bytes.Length/2);

            // clone the IDigest
            IDigest d = new MD5Digest((MD5Digest)digest);

            digest.BlockUpdate(bytes, bytes.Length/2, bytes.Length - bytes.Length/2);
            digest.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec4.Equals(resStr))
            {
                return new SimpleTestResult(false,
                    "MD5 failing standard vector test 5"
                    + SimpleTest.NewLine
                    + "    expected: " + resVec4
                    + SimpleTest.NewLine
                    + "    got     : " + resStr);
            }

            d.BlockUpdate(bytes, bytes.Length/2, bytes.Length - bytes.Length/2);
            d.DoFinal(resBuf, 0);

            resStr = Hex.ToHexString(resBuf);
            if (!resVec4.Equals(resStr))
            {
                return new SimpleTestResult(false,
                    "MD5 failing standard vector test 5"
                    + SimpleTest.NewLine
                    + "    expected: " + resVec4
                    + SimpleTest.NewLine
                    + "    got     : " + resStr);
            }
            return new SimpleTestResult(true, Name + ": Okay");
        }
Exemplo n.º 12
0
 public MD5Digest(MD5Digest t) : base(t)
 {
     this.CopyIn(t);
 }
Exemplo n.º 13
0
        internal override void ProcessBlock()
        {
            uint num  = this.H1;
            uint num2 = this.H2;
            uint num3 = this.H3;
            uint num4 = this.H4;

            num       = MD5Digest.RotateLeft(num + MD5Digest.F(num2, num3, num4) + this.X[0] + 3614090360u, MD5Digest.S11) + num2;
            num4      = MD5Digest.RotateLeft(num4 + MD5Digest.F(num, num2, num3) + this.X[1] + 3905402710u, MD5Digest.S12) + num;
            num3      = MD5Digest.RotateLeft(num3 + MD5Digest.F(num4, num, num2) + this.X[2] + 606105819u, MD5Digest.S13) + num4;
            num2      = MD5Digest.RotateLeft(num2 + MD5Digest.F(num3, num4, num) + this.X[3] + 3250441966u, MD5Digest.S14) + num3;
            num       = MD5Digest.RotateLeft(num + MD5Digest.F(num2, num3, num4) + this.X[4] + 4118548399u, MD5Digest.S11) + num2;
            num4      = MD5Digest.RotateLeft(num4 + MD5Digest.F(num, num2, num3) + this.X[5] + 1200080426u, MD5Digest.S12) + num;
            num3      = MD5Digest.RotateLeft(num3 + MD5Digest.F(num4, num, num2) + this.X[6] + 2821735955u, MD5Digest.S13) + num4;
            num2      = MD5Digest.RotateLeft(num2 + MD5Digest.F(num3, num4, num) + this.X[7] + 4249261313u, MD5Digest.S14) + num3;
            num       = MD5Digest.RotateLeft(num + MD5Digest.F(num2, num3, num4) + this.X[8] + 1770035416u, MD5Digest.S11) + num2;
            num4      = MD5Digest.RotateLeft(num4 + MD5Digest.F(num, num2, num3) + this.X[9] + 2336552879u, MD5Digest.S12) + num;
            num3      = MD5Digest.RotateLeft(num3 + MD5Digest.F(num4, num, num2) + this.X[10] + 4294925233u, MD5Digest.S13) + num4;
            num2      = MD5Digest.RotateLeft(num2 + MD5Digest.F(num3, num4, num) + this.X[11] + 2304563134u, MD5Digest.S14) + num3;
            num       = MD5Digest.RotateLeft(num + MD5Digest.F(num2, num3, num4) + this.X[12] + 1804603682u, MD5Digest.S11) + num2;
            num4      = MD5Digest.RotateLeft(num4 + MD5Digest.F(num, num2, num3) + this.X[13] + 4254626195u, MD5Digest.S12) + num;
            num3      = MD5Digest.RotateLeft(num3 + MD5Digest.F(num4, num, num2) + this.X[14] + 2792965006u, MD5Digest.S13) + num4;
            num2      = MD5Digest.RotateLeft(num2 + MD5Digest.F(num3, num4, num) + this.X[15] + 1236535329u, MD5Digest.S14) + num3;
            num       = MD5Digest.RotateLeft(num + MD5Digest.G(num2, num3, num4) + this.X[1] + 4129170786u, MD5Digest.S21) + num2;
            num4      = MD5Digest.RotateLeft(num4 + MD5Digest.G(num, num2, num3) + this.X[6] + 3225465664u, MD5Digest.S22) + num;
            num3      = MD5Digest.RotateLeft(num3 + MD5Digest.G(num4, num, num2) + this.X[11] + 643717713u, MD5Digest.S23) + num4;
            num2      = MD5Digest.RotateLeft(num2 + MD5Digest.G(num3, num4, num) + this.X[0] + 3921069994u, MD5Digest.S24) + num3;
            num       = MD5Digest.RotateLeft(num + MD5Digest.G(num2, num3, num4) + this.X[5] + 3593408605u, MD5Digest.S21) + num2;
            num4      = MD5Digest.RotateLeft(num4 + MD5Digest.G(num, num2, num3) + this.X[10] + 38016083u, MD5Digest.S22) + num;
            num3      = MD5Digest.RotateLeft(num3 + MD5Digest.G(num4, num, num2) + this.X[15] + 3634488961u, MD5Digest.S23) + num4;
            num2      = MD5Digest.RotateLeft(num2 + MD5Digest.G(num3, num4, num) + this.X[4] + 3889429448u, MD5Digest.S24) + num3;
            num       = MD5Digest.RotateLeft(num + MD5Digest.G(num2, num3, num4) + this.X[9] + 568446438u, MD5Digest.S21) + num2;
            num4      = MD5Digest.RotateLeft(num4 + MD5Digest.G(num, num2, num3) + this.X[14] + 3275163606u, MD5Digest.S22) + num;
            num3      = MD5Digest.RotateLeft(num3 + MD5Digest.G(num4, num, num2) + this.X[3] + 4107603335u, MD5Digest.S23) + num4;
            num2      = MD5Digest.RotateLeft(num2 + MD5Digest.G(num3, num4, num) + this.X[8] + 1163531501u, MD5Digest.S24) + num3;
            num       = MD5Digest.RotateLeft(num + MD5Digest.G(num2, num3, num4) + this.X[13] + 2850285829u, MD5Digest.S21) + num2;
            num4      = MD5Digest.RotateLeft(num4 + MD5Digest.G(num, num2, num3) + this.X[2] + 4243563512u, MD5Digest.S22) + num;
            num3      = MD5Digest.RotateLeft(num3 + MD5Digest.G(num4, num, num2) + this.X[7] + 1735328473u, MD5Digest.S23) + num4;
            num2      = MD5Digest.RotateLeft(num2 + MD5Digest.G(num3, num4, num) + this.X[12] + 2368359562u, MD5Digest.S24) + num3;
            num       = MD5Digest.RotateLeft(num + MD5Digest.H(num2, num3, num4) + this.X[5] + 4294588738u, MD5Digest.S31) + num2;
            num4      = MD5Digest.RotateLeft(num4 + MD5Digest.H(num, num2, num3) + this.X[8] + 2272392833u, MD5Digest.S32) + num;
            num3      = MD5Digest.RotateLeft(num3 + MD5Digest.H(num4, num, num2) + this.X[11] + 1839030562u, MD5Digest.S33) + num4;
            num2      = MD5Digest.RotateLeft(num2 + MD5Digest.H(num3, num4, num) + this.X[14] + 4259657740u, MD5Digest.S34) + num3;
            num       = MD5Digest.RotateLeft(num + MD5Digest.H(num2, num3, num4) + this.X[1] + 2763975236u, MD5Digest.S31) + num2;
            num4      = MD5Digest.RotateLeft(num4 + MD5Digest.H(num, num2, num3) + this.X[4] + 1272893353u, MD5Digest.S32) + num;
            num3      = MD5Digest.RotateLeft(num3 + MD5Digest.H(num4, num, num2) + this.X[7] + 4139469664u, MD5Digest.S33) + num4;
            num2      = MD5Digest.RotateLeft(num2 + MD5Digest.H(num3, num4, num) + this.X[10] + 3200236656u, MD5Digest.S34) + num3;
            num       = MD5Digest.RotateLeft(num + MD5Digest.H(num2, num3, num4) + this.X[13] + 681279174u, MD5Digest.S31) + num2;
            num4      = MD5Digest.RotateLeft(num4 + MD5Digest.H(num, num2, num3) + this.X[0] + 3936430074u, MD5Digest.S32) + num;
            num3      = MD5Digest.RotateLeft(num3 + MD5Digest.H(num4, num, num2) + this.X[3] + 3572445317u, MD5Digest.S33) + num4;
            num2      = MD5Digest.RotateLeft(num2 + MD5Digest.H(num3, num4, num) + this.X[6] + 76029189u, MD5Digest.S34) + num3;
            num       = MD5Digest.RotateLeft(num + MD5Digest.H(num2, num3, num4) + this.X[9] + 3654602809u, MD5Digest.S31) + num2;
            num4      = MD5Digest.RotateLeft(num4 + MD5Digest.H(num, num2, num3) + this.X[12] + 3873151461u, MD5Digest.S32) + num;
            num3      = MD5Digest.RotateLeft(num3 + MD5Digest.H(num4, num, num2) + this.X[15] + 530742520u, MD5Digest.S33) + num4;
            num2      = MD5Digest.RotateLeft(num2 + MD5Digest.H(num3, num4, num) + this.X[2] + 3299628645u, MD5Digest.S34) + num3;
            num       = MD5Digest.RotateLeft(num + MD5Digest.K(num2, num3, num4) + this.X[0] + 4096336452u, MD5Digest.S41) + num2;
            num4      = MD5Digest.RotateLeft(num4 + MD5Digest.K(num, num2, num3) + this.X[7] + 1126891415u, MD5Digest.S42) + num;
            num3      = MD5Digest.RotateLeft(num3 + MD5Digest.K(num4, num, num2) + this.X[14] + 2878612391u, MD5Digest.S43) + num4;
            num2      = MD5Digest.RotateLeft(num2 + MD5Digest.K(num3, num4, num) + this.X[5] + 4237533241u, MD5Digest.S44) + num3;
            num       = MD5Digest.RotateLeft(num + MD5Digest.K(num2, num3, num4) + this.X[12] + 1700485571u, MD5Digest.S41) + num2;
            num4      = MD5Digest.RotateLeft(num4 + MD5Digest.K(num, num2, num3) + this.X[3] + 2399980690u, MD5Digest.S42) + num;
            num3      = MD5Digest.RotateLeft(num3 + MD5Digest.K(num4, num, num2) + this.X[10] + 4293915773u, MD5Digest.S43) + num4;
            num2      = MD5Digest.RotateLeft(num2 + MD5Digest.K(num3, num4, num) + this.X[1] + 2240044497u, MD5Digest.S44) + num3;
            num       = MD5Digest.RotateLeft(num + MD5Digest.K(num2, num3, num4) + this.X[8] + 1873313359u, MD5Digest.S41) + num2;
            num4      = MD5Digest.RotateLeft(num4 + MD5Digest.K(num, num2, num3) + this.X[15] + 4264355552u, MD5Digest.S42) + num;
            num3      = MD5Digest.RotateLeft(num3 + MD5Digest.K(num4, num, num2) + this.X[6] + 2734768916u, MD5Digest.S43) + num4;
            num2      = MD5Digest.RotateLeft(num2 + MD5Digest.K(num3, num4, num) + this.X[13] + 1309151649u, MD5Digest.S44) + num3;
            num       = MD5Digest.RotateLeft(num + MD5Digest.K(num2, num3, num4) + this.X[4] + 4149444226u, MD5Digest.S41) + num2;
            num4      = MD5Digest.RotateLeft(num4 + MD5Digest.K(num, num2, num3) + this.X[11] + 3174756917u, MD5Digest.S42) + num;
            num3      = MD5Digest.RotateLeft(num3 + MD5Digest.K(num4, num, num2) + this.X[2] + 718787259u, MD5Digest.S43) + num4;
            num2      = MD5Digest.RotateLeft(num2 + MD5Digest.K(num3, num4, num) + this.X[9] + 3951481745u, MD5Digest.S44) + num3;
            this.H1  += num;
            this.H2  += num2;
            this.H3  += num3;
            this.H4  += num4;
            this.xOff = 0;
        }
Exemplo n.º 14
0
        public static byte[] HashMD5(string plainText)
        {
            // Create digest instance to compute our hash
            var hash = new MD5Digest();

            // Create a buffer large enough to store the computed hash
            var resultBytes = new byte[hash.GetDigestSize()];

            // Convert plain text string to bytes
            var plainBytes = Encoding.UTF8.GetBytes(plainText);

            // Process the bytes
            hash.BlockUpdate(plainBytes, 0, plainBytes.Length);

            // Process final output
            hash.DoFinal(resultBytes, 0);

            // Convert to string
            return resultBytes;
        }
Exemplo n.º 15
0
 /// <summary>
 /// Note:  Clears pool contents before returning
 /// </summary>
 private void CreateNewPRNG(byte[] pool)
 {
     if (pool == null)
     {
         throw new CryptographicException("Refusing to reseed with null pool");
     }
     try
     {
         if (pool.Length != PoolSize)
         {
             throw new CryptographicException("Refusing to reseed with invalid pool");
         }
         // Now, pool has been seeded, file operations are all completed, it's time to create my internal PRNG
         IDigest digest;
         switch (this.myRNGAlgorithm)
         {
             case PrngAlgorithm.MD5_128bit:
                 digest = new MD5Digest();
                 break;
             case PrngAlgorithm.RIPEMD128_128bit:
                 digest = new RipeMD128Digest();
                 break;
             case PrngAlgorithm.RIPEMD160_160bit:
                 digest = new RipeMD160Digest();
                 break;
             case PrngAlgorithm.RIPEMD256_256bit:
                 digest = new RipeMD256Digest();
                 break;
             case PrngAlgorithm.RIPEMD320_320bit:
                 digest = new RipeMD320Digest();
                 break;
             case PrngAlgorithm.SHA1_160bit:
                 digest = new Sha1Digest();
                 break;
             case PrngAlgorithm.SHA256_256bit:
                 digest = new Sha256Digest();
                 break;
             case PrngAlgorithm.SHA512_512bit:
                 digest = new Sha512Digest();
                 break;
             case PrngAlgorithm.Tiger_192bit:
                 digest = new TigerDigest();
                 break;
             case PrngAlgorithm.Whirlpool_512bit:
                 digest = new WhirlpoolDigest();
                 break;
             default:
                 throw new CryptographicException("Unknown prngAlgorithm specified: " + this.myRNGAlgorithm.ToString());
         }
         var drng = new DigestRandomGenerator(digest);
         drng.AddSeedMaterial(pool);
         this.myRNG = drng;
     }
     finally
     {
         Array.Clear(pool, 0, pool.Length);
     }
 }
Exemplo n.º 16
0
        public void run()
        {
            AsymmetricCipherKeyPair aKeyPair = _keyGen.GenerateKeyPair();
            IBasicAgreement aKeyAgreeBasic = AgreementUtilities.GetBasicAgreement("ECDH");
            aKeyAgreeBasic.Init(aKeyPair.Private);
            byte[] pubEnc = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(aKeyPair.Public).GetDerEncoded();

            IPAddress ip=IPAddress.Parse("192.168.1.117");
            IPEndPoint ipe = new IPEndPoint(ip, 8899);
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.Connect(ipe);
            //byte[] bs = Encoding.ASCII.GetBytes("Windows Test");
            socket.Send(pubEnc, pubEnc.Length, 0);

            byte[] recvBytes = new byte[1024];
            int bytes=socket.Receive(recvBytes, recvBytes.Length, 0);

            socket.Close();

            byte[] bPub = new byte[bytes];
            for (int i = 0; i < bytes; i++)
            {
                bPub[i] = recvBytes[i];
            }
            ECPublicKeyParameters pubKey = (ECPublicKeyParameters)PublicKeyFactory.CreateKey(bPub);
            BigInteger k = aKeyAgreeBasic.CalculateAgreement(pubKey);
            byte[] keyBytes = k.ToByteArray();
            //Console.WriteLine(keybytes.Length);
            if (keyBytes.Length > 24)
            {
                byte[] fixedKeybytes = new byte[24];
                for (int i = 0; i < 24; i++)
                {
                    fixedKeybytes[i] = keyBytes[i + keyBytes.Length - 24];
                }
                keyBytes = fixedKeybytes;
            }
            Console.WriteLine(Hex.ToHexString(keyBytes));

            IDigest digest = new MD5Digest();
            digest.BlockUpdate(keyBytes, 0, keyBytes.Length);
            byte[] idBytes = new byte[digest.GetDigestSize()];
            digest.DoFinal(idBytes, 0);
            _id = Hex.ToHexString(idBytes);
            Console.WriteLine(_id);
            _trivium = new Trivium();
            _trivium.setKIV(keyBytes);
            _trivium.initProcess();
        }
        /**
        * Copy constructor.  This will copy the state of the provided
        * message digest.
        */
        public MD5Digest(MD5Digest t)
            : base(t)
		{
			CopyIn(t);
		}
Exemplo n.º 18
0
        public static byte[] HashMd5(byte[] data)
        {
            var hashAlgoritm = new MD5Digest();

            return Hash(data, hashAlgoritm);
        }
Exemplo n.º 19
0
		internal CombinedHash(CombinedHash t)
		{
			this.md5 = new MD5Digest(t.md5);
			this.sha1 = new Sha1Digest(t.sha1);
		}
Exemplo n.º 20
0
        public override void Reset(IMemoable other)
        {
            MD5Digest t = (MD5Digest)other;

            this.CopyIn(t);
        }
Exemplo n.º 21
0
        public override void Reset(IMemoable other)
        {
            MD5Digest d = (MD5Digest)other;

            CopyIn(d);
        }
Exemplo n.º 22
0
 public MD5Digest(MD5Digest t) : base(t)
 {
     this.X = new uint[0x10];
     this.CopyIn(t);
 }
Exemplo n.º 23
0
 /**
  * Copy constructor.  This will copy the state of the provided
  * message digest.
  */
 public MD5Digest(MD5Digest t)
     : base(t)
 {
     CopyIn(t);
 }
Exemplo n.º 24
0
		private IDigest GetDigest(THashAlgorithm hashAlgorithm)
		{
			IDigest result = null;
			switch (hashAlgorithm)
			{
				case THashAlgorithm.None:
					result = new NullDigest();
					break;
				case THashAlgorithm.MD5:
					result = new MD5Digest();
					break;
				case THashAlgorithm.SHA1:
					result = new Sha1Digest();
					break;
				case THashAlgorithm.SHA224:
					result = new Sha224Digest();
					break;
				case THashAlgorithm.SHA256:
					result = new Sha256Digest();
					break;
				case THashAlgorithm.SHA384:
					result = new Sha384Digest();
					break;
				case THashAlgorithm.SHA512:
					result = new Sha512Digest();
					break;
				default:
					break;
			}
			return result;
		}
Exemplo n.º 25
0
		internal CombinedHash()
		{
			this.md5 = new MD5Digest();
			this.sha1 = new Sha1Digest();
		}
Exemplo n.º 26
0
		/// <summary>
		/// Return the md5 hash of the byte array.
		/// </summary>
		/// <param name="data">Data to be hashed.</param>
		public static string MD5(byte[] data)
		{
			MD5Digest digest = new MD5Digest();
			return Encode(data, digest);
		}
Exemplo n.º 27
0
        public static byte[] Digest(byte[] data, String algo)
        {
            if (algo == null)
            {
                throw new ArgumentNullException("El algoritmo de huella digital no puede ser nulo");
            }
            if (data == null)
            {
                throw new ArgumentNullException("Los datos no pueden ser nulos");
            }

            switch (algo)
            {
                /**
                 * ALGORITMOS DE HASING
                 */
                case AOSignConstants.SIGN_ALGORITHM_SHA1:
                    {
                        Sha1Digest dig = new Sha1Digest();
                        dig.BlockUpdate(data, 0, data.Length);
                        byte[] result = new byte[dig.GetDigestSize()];
                        dig.DoFinal(result, 0);
                        return result;
                    }

                case AOSignConstants.SIGN_ALGORITHM_SHA256:
                    {
                        Sha256Digest dig = new Sha256Digest();
                        dig.BlockUpdate(data, 0, data.Length);
                        byte[] result = new byte[dig.GetDigestSize()];
                        dig.DoFinal(result, 0);
                        return result;
                    }

                case AOSignConstants.SIGN_ALGORITHM_SHA384:
                    {
                        Sha384Digest dig = new Sha384Digest();
                        dig.BlockUpdate(data, 0, data.Length);
                        byte[] result = new byte[dig.GetDigestSize()];
                        dig.DoFinal(result, 0);
                        return result;
                    }

                case AOSignConstants.SIGN_ALGORITHM_SHA512:
                    {
                        Sha512Digest dig = new Sha512Digest();
                        dig.BlockUpdate(data, 0, data.Length);
                        byte[] result = new byte[dig.GetDigestSize()];
                        dig.DoFinal(result, 0);
                        return result;
                    }

                case AOSignConstants.SIGN_ALGORITHM_RIPEMD160:
                    {
                        RipeMD160Digest dig = new RipeMD160Digest();
                        dig.BlockUpdate(data, 0, data.Length);
                        byte[] result = new byte[dig.GetDigestSize()];
                        dig.DoFinal(result, 0);
                        return result;
                    }
                case AOSignConstants.SIGN_ALGORITHM_MD5:
                    {
                        MD5Digest dig = new MD5Digest();
                        dig.BlockUpdate(data, 0, data.Length);
                        byte[] result = new byte[dig.GetDigestSize()];
                        dig.DoFinal(result, 0);
                        return result;
                    }

                case AOSignConstants.SIGN_ALGORITHM_MD2:
                    {
                        MD2Digest dig = new MD2Digest();
                        dig.BlockUpdate(data, 0, data.Length);
                        byte[] result = new byte[dig.GetDigestSize()];
                        dig.DoFinal(result, 0);
                        return result;
                    }

                default:
                    // You can use the default case.
                    throw new ArgumentNullException("El algoritmo no es reconocido");
            }

            throw new ArgumentNullException("Algoritmo de hash no soportado: " + algo);
        }
Exemplo n.º 28
0
		/// <summary>
		/// Return the md5 hash of the stream.
		/// </summary>
		/// <param name="instream">Data to be hashed.</param>
		public static string MD5(Stream instream)
		{
			MD5Digest digest = new MD5Digest();
			return Encode(instream, digest);
		}