Пример #1
0
        public void Calculate(Stream _stream)
        {
            if (chkKey.Checked)
            {
                if (!txtKey.IsValid)
                {
                    HashFields_Empty();
                    HashFields_ResetColour();
                    txtKey.BackColor = Color.Salmon;
                    return;
                }

                byte[] abyKey = txtKey.ByteArray;

                ComputeHash(txtMD5, new HMACMD5(abyKey), _stream);
                ComputeHash(txtRIPEMD160, new HMACRIPEMD160(abyKey), _stream);
                ComputeHash(txtSHA1, new HMACSHA1(abyKey), _stream);
                ComputeHash(txtSHA256, new HMACSHA256(abyKey), _stream);
                ComputeHash(txtSHA384, new HMACSHA384(abyKey), _stream);
                ComputeHash(txtSHA512, new HMACSHA512(abyKey), _stream);
            }
            else
            {
                ComputeHash(txtMD5, MD5.Create(), _stream);
                ComputeHash(txtRIPEMD160, RIPEMD160.Create(), _stream);
                ComputeHash(txtSHA1, SHA1.Create(), _stream);
                ComputeHash(txtSHA256, SHA256.Create(), _stream);
                ComputeHash(txtSHA384, SHA384.Create(), _stream);
                ComputeHash(txtSHA512, SHA512.Create(), _stream);
                ComputeHash(txtCRC32, new CRC32(), _stream);
            }

            TestMatcher();
        }
Пример #2
0
        public void RIPEMD160Empty()
        {
            var ripemd160 = RIPEMD160.Create();
            var result    = ripemd160.ComputeHash(string.Empty.ToByteArray());

            Assert.AreEqual("9c1185a5c5e9fc54612808977ee8f548b2258d31", result.ToHexString());
        }
Пример #3
0
        public void RIPEMD160LowerLetters()
        {
            var ripemd160 = RIPEMD160.Create();
            var result    = ripemd160.ComputeHash("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq".ToByteArray());

            Assert.AreEqual("12a053384a9c0c88e405a06c27dcf49ada62eb2b", result.ToHexString());
        }
Пример #4
0
        private void bgwRIPEMD160_DoWork(object sender, DoWorkEventArgs e)
        {
            string filePath = e.Argument.ToString();

            byte[] buffer;

            int bytesRead;

            long sizeOfFile, totalBytesToRead = 0;

            using (Stream fileStream = File.OpenRead(filePath))
            {
                sizeOfFile = fileStream.Length;

                using (HashAlgorithm ripemd160 = RIPEMD160.Create())
                {
                    do
                    {
                        buffer = new byte[4096];

                        bytesRead = fileStream.Read(buffer, 0, buffer.Length);

                        totalBytesToRead += bytesRead;

                        ripemd160.TransformBlock(buffer, 0, bytesRead, null, 0);

                        bgwRIPEMD160.ReportProgress((int)((double)totalBytesToRead / sizeOfFile * 100));
                    } while (bytesRead != 0);

                    ripemd160.TransformFinalBlock(buffer, 0, 0);

                    e.Result = MakeRIPEMD160HashString(ripemd160.Hash);
                }
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            //--INPUT STRING
            Console.Write("Input Text To encrypt : ");
            string input = Console.ReadLine();

            //--MD5 ALGORITHM
            MD5 mD5 = MD5.Create();

            PrintOutput(GetHashMethode(mD5, input), "MD5");
            //--RIPEMD160 ALGORIHM
            RIPEMD160 rIPEMD160 = RIPEMD160.Create();

            PrintOutput(GetHashMethode(rIPEMD160, input), "RIPEMD160");
            //--SHA1 ALGORITHM
            SHA1 sHA1 = SHA1.Create();

            PrintOutput(GetHashMethode(sHA1, input), "SHA1");
            //--SHA256 ALGHORITHM
            SHA256 sHA256 = SHA256.Create();

            PrintOutput(GetHashMethode(sHA256, input), "SHA256");
            //--SHA384 ALGORITHM
            SHA384 sHA384 = SHA384.Create();

            PrintOutput(GetHashMethode(sHA384, input), "SHA384");
            //--SHA512 ALGORITHM
            SHA512 sHA512 = SHA512.Create();

            PrintOutput(GetHashMethode(sHA512, input), "SHA512");
        }
Пример #6
0
        /// <summary>
        /// Creates a <see cref="HashAlgorithm"/> for the specified <paramref name="hashType"/>
        /// </summary>
        /// <param name="hashType">Type of the hash.</param>
        /// <returns></returns>
        public static HashAlgorithm CreateHashAlgorithm(HashType hashType)
        {
            switch (GetHashType(hashType))
            {
            case HashType.MD5:
                return(MD5.Create());

            case HashType.SHA1:
                return(SHA1.Create());

            case HashType.SHA256:
                return(SHA256.Create());

            case HashType.SHA512:
                return(SHA512.Create());

            case HashType.SHA384:
                return(SHA384.Create());

            case HashType.RipeMD160:
                return(RIPEMD160.Create());

            default:
                throw new ArgumentException("Invalid hashtype", "hashType");
            }
        }
Пример #7
0
 public void RIPEMD160_d(string testName, RIPEMD160 hash, byte[] input, byte[] result)
 {
     hash.TransformFinalBlock(input, 0, input.Length);
     AssertEquals(testName + ".d", result, hash.Hash);
     // required or next operation will still return old hash
     hash.Initialize();
 }
Пример #8
0
        public void TestHashOfTextInput()
        {
            var textTestVectors = new Dictionary <string, string>
            {
                { string.Empty, "9c1185a5c5e9fc54612808977ee8f548b2258d31" },
                { "a", "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe" },
                { "abc", "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc" },
                { "abcdefghijklmnopqrstuvwxyz", "f71c27109c692c1b56bbdceb5b9d2865b3708dbc" },
                { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "12a053384a9c0c88e405a06c27dcf49ada62eb2b" },
                { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "b0e20b6e3116640286ed3a87a5713079b21f5189" },
                { "The quick brown fox jumps over the lazy dog", "37f332f68db77bd9d7edd4969571ad671cf9dd3b" },
                { "The quick brown fox jumps over the lazy dog.", "fc850169b1f2ce72e3f8aa0aeb5ca87d6f8519c6" }
            };

            //test hex string overload.  RIPEMD160.Hash(string hexData)
            foreach (var testString in textTestVectors)
            {
                var hex       = Hex.AsciiToHex(testString.Key);
                var hashBytes = RIPEMD160.Hash(hex);
                Assert.AreEqual(testString.Value, hashBytes.ToHex());
            }

            //test byte array overload.  RIPEMD160.Hash(byte[] data)
            foreach (var testString in textTestVectors)
            {
                var bytes     = Encoding.UTF8.GetBytes(testString.Key);
                var hashBytes = RIPEMD160.Hash(bytes);
                Assert.AreEqual(testString.Value, hashBytes.ToHex());
            }
        }
Пример #9
0
            /// <summary>
            /// Transforms a file's bytes into an array of cryptographically strong data.
            /// </summary>
            /// <param name="path">The location of the file to hash.</param>
            /// <param name="hash">The algorithm to be used for hashing.</param>
            private byte[] GetFileHash(string path, HashType hash)
            {
                using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, (1024 * 1024)))
                {
                    switch (hash)
                    {
                    case HashType.MD5:
                        return(MD5.Create().ComputeHash(file));

                    case HashType.RIPEMD160:
                        return(RIPEMD160.Create().ComputeHash(file));

                    case HashType.SHA1:
                        return(SHA1.Create().ComputeHash(file));

                    case HashType.SHA256:
                        return(SHA256.Create().ComputeHash(file));

                    case HashType.SHA384:
                        return(SHA384.Create().ComputeHash(file));

                    case HashType.SHA512:
                        return(SHA512.Create().ComputeHash(file));

                    default:
                        return(null);
                    }
                }
            }
 public static byte[] Ripemd160(byte[] data)
 {
     using (RIPEMD160 hash = RIPEMD160.Create())
     {
         return(hash.ComputeHash(data));
     }
 }
Пример #11
0
        /// <summary>
        /// Creates the hash algorithm by the given name.
        /// </summary>
        /// <returns>The hash algorithm.</returns>
        /// <param name="name">Name of the has algorithm.</param>
        public static HashAlgorithm CreateHashAlgorithm(string name)
        {
            name = name.ToLower();
            if (name.Equals("sha1") || name.Equals("sha-1"))
            {
                return(SHA1.Create());
            }

            if (name.Equals("sha256") || name.Equals("sha-256"))
            {
                return(SHA256.Create());
            }

            if (name.Equals("sha384") || name.Equals("sha-384"))
            {
                return(SHA384.Create());
            }

            if (name.Equals("sha512") || name.Equals("sha-512"))
            {
                return(SHA512.Create());
            }

            if (name.Equals("md5"))
            {
                return(MD5.Create());
            }

            if (name.Equals("ripemd160") || name.Equals("ripemd"))
            {
                return(RIPEMD160.Create());
            }

            return(HashAlgorithm.Create());
        }
Пример #12
0
        private void btnGeraHashRIPEMD160_Click(object sender, EventArgs e)
        {
            txtHash.Text = "";
            var hash = new TrataHash(RIPEMD160.Create());

            txtHash.Text = hash.GerarHash(txtTexto.Text);
        }
Пример #13
0
        /// <summary>
        /// Get the <see cref="HashAlgorithm"/> associated to the <see cref="HashAlgorithmEnum"/>
        /// </summary>
        /// <param name="algorithm">Algorithm request</param>
        /// <returns></returns>
        static public HashAlgorithm GetAlgorithm(HashAlgorithmEnum algorithm)
        {
            switch (algorithm)
            {
            case HashAlgorithmEnum.MD5:
                return(MD5.Create());

            case HashAlgorithmEnum.SHA1:
                return(SHA1.Create());

            case HashAlgorithmEnum.SHA256:
                return(SHA256.Create());

            case HashAlgorithmEnum.SHA384:
                return(SHA384.Create());

            case HashAlgorithmEnum.SHA512:
                return(SHA512.Create());

            case HashAlgorithmEnum.RIPEMD160:
                return(RIPEMD160.Create());

            case HashAlgorithmEnum.KeyedHashAlgorithm:
                return(KeyedHashAlgorithm.Create());

            default:
                return(SHA256.Create());
            }
        }
Пример #14
0
        public void AddColumnInformationTestReverse()
        {
            OutputColumn          target        = new OutputColumn();
            IDTSBufferManager100  bufferManager = new BufferManagerTestImpl();
            IDTSOutput100         output        = new OutputTestImpl();
            IDTSInput100          input         = new InputTestImpl();
            IDTSOutputColumn100   outputColumn;
            IDTSCustomProperty100 customProperty;
            int outputColumnIndex = 0;

            outputColumn         = output.OutputColumnCollection.New();
            customProperty       = outputColumn.CustomPropertyCollection.New();
            customProperty.Name  = Utility.InputColumnLineagePropName;
            customProperty.Value = "#1,#2,#3,#4,#5,#6";
            customProperty       = outputColumn.CustomPropertyCollection.New();
            customProperty.Name  = Utility.HashTypePropName;
            customProperty.Value = MultipleHash.HashTypeEnumerator.RipeMD160;

            target.AddColumnInformation(bufferManager, output, input, outputColumnIndex);
            Assert.AreEqual(6, target.Count, "The number of items in the list");
            Assert.AreEqual(1, target[0], "The first input");
            Assert.AreEqual(2, target[1], "The second input");
            Assert.AreEqual(3, target[2], "The third input");
            Assert.AreEqual(4, target[3], "The forth input");
            Assert.AreEqual(5, target[4], "The fifth input");
            Assert.AreEqual(6, target[5], "The sixth input");
            Assert.AreEqual(MultipleHash.HashTypeEnumerator.RipeMD160, target.HashType, "Hash");
            Assert.AreEqual(RIPEMD160.Create().ToString(), target.HashObject.ToString(), "Hash Object");
        }
Пример #15
0
        protected override void BeginProcessing()
        {
            base.BeginProcessing();
            switch (HashType.ToLower())
            {
            case "md5":
                Algorithm = MD5.Create();
                break;

            case "sha1":
                Algorithm = SHA1.Create();
                break;

            case "sha256":
                Algorithm = SHA256.Create();
                break;

            case "sha384":
                Algorithm = SHA384.Create();
                break;

            default:
            case "sha512":
                Algorithm = SHA512.Create();
                break;

            case "ripemd160":
                Algorithm = RIPEMD160.Create();
                break;
            }
        }
Пример #16
0
            /// <summary>
            /// Transforms a string into a cryptographically strong hash.
            /// </summary>
            /// <param name="input">The string to be transformed.</param>
            /// <param name="hash">The algorithm to used for hashing.</param>
            private byte[] GetHash(string input, HashType hash)
            {
                byte[] inputBytes = Encoding.ASCII.GetBytes(input);

                switch (hash)
                {
                case HashType.MD5:
                    return(MD5.Create().ComputeHash(inputBytes));

                case HashType.RIPEMD160:
                    return(RIPEMD160.Create().ComputeHash(inputBytes));

                case HashType.SHA1:
                    return(SHA1.Create().ComputeHash(inputBytes));

                case HashType.SHA256:
                    return(SHA256.Create().ComputeHash(inputBytes));

                case HashType.SHA384:
                    return(SHA384.Create().ComputeHash(inputBytes));

                case HashType.SHA512:
                    return(SHA512.Create().ComputeHash(inputBytes));

                default:
                    return(inputBytes);
                }
            }
Пример #17
0
        public void GenerateHash_RIPEMD160()
        {
            Hash h = new Hash(wellKnownAssembly);

            byte[] result = h.GenerateHash(RIPEMD160.Create());
            Assert.AreEqual("29-5A-21-11-BC-CA-1B-26-A2-46-F2-48-B4-61-96-1C-A5-2C-9A-9A", BitConverter.ToString(result));
        }
Пример #18
0
        static void Main(string[] args)
        {
            if (args == null || args.Count() != 1)
            {
                Console.WriteLine("USAGE: CreateFileHash 'Filename.mp3'");
            }
            else
            {
                if (File.Exists(args[0].ToString()))
                {
                    RIPEMD160 myRIPEMD160 = RIPEMD160Managed.Create();
                    byte[]    hashVal;
                    using (FileStream stream = File.Open(args[0].ToString(), FileMode.Open))
                    {
                        stream.Position = 0;
                        hashVal         = myRIPEMD160.ComputeHash(stream);
                        string hashValueString = CreateStringFromByteArray(hashVal);
                        Console.WriteLine("The hash for this file is: {0}", hashValueString);
                        Console.WriteLine("The hash length is {0}", hashValueString.Length);
                    }
                }
                else
                {
                    Console.WriteLine("File not found!");
                }

                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
            }
        }
Пример #19
0
        public static string GetHash(this string input, HashType hashType)
        {
            byte[] inputBytes = input.ToByteArray();

            switch (hashType)
            {
            case HashType.HMAC: return(Convert.ToBase64String(HMAC.Create().ComputeHash(inputBytes)));

            case HashType.HMACMD5: return(Convert.ToBase64String(HMAC.Create().ComputeHash(inputBytes)));

            case HashType.HMACSHA1: return(Convert.ToBase64String(HMAC.Create().ComputeHash(inputBytes)));

            case HashType.HMACSHA256: return(Convert.ToBase64String(HMAC.Create().ComputeHash(inputBytes)));

            case HashType.HMACSHA384: return(Convert.ToBase64String(HMAC.Create().ComputeHash(inputBytes)));

            case HashType.HMACSHA512: return(Convert.ToBase64String(HMAC.Create().ComputeHash(inputBytes)));

            case HashType.MACTripleDES: return(Convert.ToBase64String(KeyedHashAlgorithm.Create().ComputeHash(inputBytes)));

            case HashType.MD5: return(Convert.ToBase64String(MD5.Create().ComputeHash(inputBytes)));

            case HashType.RIPEMD160: return(Convert.ToBase64String(RIPEMD160.Create().ComputeHash(inputBytes)));

            case HashType.SHA1: return(Convert.ToBase64String(SHA1.Create().ComputeHash(inputBytes)));

            case HashType.SHA256: return(Convert.ToBase64String(SHA256.Create().ComputeHash(inputBytes)));

            case HashType.SHA384: return(Convert.ToBase64String(SHA384.Create().ComputeHash(inputBytes)));

            case HashType.SHA512: return(Convert.ToBase64String(SHA512.Create().ComputeHash(inputBytes)));

            default: return(Convert.ToBase64String(inputBytes));
            }
        }
Пример #20
0
        public static byte[] getHash(string password)
        {
            var r   = RIPEMD160.Create();
            var bfr = password.GetBytes().Concat(Salt).ToArray();

            return(r.ComputeHash(bfr));
        }
Пример #21
0
        static PublicKey FromStringOrThrow(string publicKey, string addressPrefix = null)
        {
            if (addressPrefix.IsNull())
            {
                addressPrefix = ChainConfig.AddressPrefix;
            }
            var prefix = publicKey.Substring(0, addressPrefix.Length);

            Assert.Equal(
                addressPrefix, prefix,
                string.Format("Expecting key to begin with {0}, instead got {1}", addressPrefix, prefix)
                );

            publicKey = publicKey.Substring(addressPrefix.Length);
            var buffer = Base58.Decode(publicKey);

            var checksum = buffer.Slice(buffer.Length - 4);

            buffer = buffer.Slice(0, buffer.Length - 4);

            var newChecksum = RIPEMD160.Create().HashAndDispose(buffer);

            newChecksum = newChecksum.Slice(0, 4);

            var isEqual = checksum.DeepEqual(newChecksum);               // invalid checksum

            if (!isEqual)
            {
                throw new InvalidOperationException("Checksum did not match");
            }
            return(FromBuffer(buffer));
        }
Пример #22
0
        /// <summary>
        /// Computes the Hash160 of the public key upon demand.
        /// </summary>
        protected override byte[] ComputeHash160()
        {
            byte[]    shaofpubkey = Util.ComputeSha256(PublicKeyBytes);
            RIPEMD160 rip         = System.Security.Cryptography.RIPEMD160.Create();

            return(rip.ComputeHash(shaofpubkey));
        }
Пример #23
0
        public static HashAlgorithm GetHashAlgorithmByType(DigestType dgType)
        {
            HashAlgorithm ha = null;

            switch (dgType)
            {
            case DigestType.MD5:
                ha = MD5.Create();
                break;

            case DigestType.SHA1:
                ha = SHA1.Create();
                break;

            case DigestType.SHA256:
                ha = SHA256.Create();
                break;

            case DigestType.SHA384:
                ha = SHA384.Create();
                break;

            case DigestType.SHA512:
                ha = SHA512.Create();
                break;

            case DigestType.RIPEMD160:
                ha = RIPEMD160.Create();
                break;
            }
            return(ha);
        }
Пример #24
0
        public Wallet(byte[] publicKey)
        {
            // Step 1: Allocate payload list
            var payload = new List <byte>();

            // Step 2: Append version
            //payload.Add(version);
            payload.AddRange(WalletVersion);

            // Step 3: Create ripmd160(sha256(publicKey)) hash
            var pub256Key = SHA256.Create().ComputeHash(publicKey);
            var ripmd160  = RIPEMD160.Create().ComputeHash(pub256Key);

            // Step 4: append hash to payload
            payload.AddRange(ripmd160);

            // Step 5: compute checksum of current payload
            var checksum = Checksum(payload.ToArray());

            // Step 6: append computed checksum to payload
            payload.AddRange(checksum);

            var address = payload.ToArray();

            // Step 7: convert payload bytes to base58 format
            Base58Address = Base58.Bitcoin.Encode(address);
        }
Пример #25
0
 private static byte[] ComputeRipeMdHash(byte[] data)
 {
     using (RIPEMD160 ripemd160 = RIPEMD160Managed.Create())
     {
         return(ripemd160.ComputeHash(data));
     }
 }
Пример #26
0
 // :$$$.контрольнаясумма
 public static byte[] MD160(byte[] toHash)
 {
     using (RIPEMD160 myRIPEMD160 = RIPEMD160Managed.Create())
     {
         return(myRIPEMD160.ComputeHash(toHash));
     }
 }
Пример #27
0
        public void RIPEMD160abc()
        {
            var ripemd160 = RIPEMD160.Create();
            var result    = ripemd160.ComputeHash("abc".ToByteArray());

            Assert.AreEqual("8eb208f7e05d987a9b044a8e98c6b087f15a0bfc", result.ToHexString());
        }
Пример #28
0
        private string GetHash(SupportedHashAlgorithims hashType, string filePath)
        {
            switch (hashType)
            {
            case SupportedHashAlgorithims.MESSAGEDIGEST5:
                return(MakeHashString(MD5.Create().ComputeHash(new FileStream(filePath, FileMode.Open))));

            case SupportedHashAlgorithims.SECUREHASHALGORITHIM1:
                return(MakeHashString(SHA1.Create().ComputeHash(new FileStream(filePath, FileMode.Open))));

            case SupportedHashAlgorithims.SECUREHASHALGORITHIM256:
                return(MakeHashString(SHA256.Create().ComputeHash(new FileStream(filePath, FileMode.Open))));

            case SupportedHashAlgorithims.SECUREHASHALGORITHIM384:
                return(MakeHashString(SHA384.Create().ComputeHash(new FileStream(filePath, FileMode.Open))));

            case SupportedHashAlgorithims.SECUREHASHALGORITHIM512:
                return(MakeHashString(SHA512.Create().ComputeHash(new FileStream(filePath, FileMode.Open))));

                // TODO: Why do we need to do this?
#if !NETCOREAPP
            case SupportedHashAlgorithims.RACEINTEGRITYPRIMITIVESEVALUATIONMESSAGEDIGEST:
                return(MakeHashString(RIPEMD160.Create().ComputeHash(new FileStream(filePath, FileMode.Open))));
#endif
            default:
                return("");
            }
        }
Пример #29
0
        public void RIPEMD160FullAlphabet()
        {
            var ripemd160 = RIPEMD160.Create();
            var result    = ripemd160.ComputeHash("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".ToByteArray());

            Assert.AreEqual("b0e20b6e3116640286ed3a87a5713079b21f5189", result.ToHexString());
        }
Пример #30
0
        public void TestP2SH_P2PKH()
        {
            //Create p2pkh
            CryptoRSA rsa = new CryptoRSA(key, true);

            Interpreter.Initialize();

            //Create address
            byte[] pubkeyhash;

            using (var rid = RIPEMD160.Create())
                using (var sha = SHA256.Create())
                    pubkeyhash = rid.ComputeHash(sha.ComputeHash(key.publicKey));

            LockingScript   ls = new LockingScript(BASE58.Encode(pubkeyhash));
            UnlockingScript us = new UnlockingScript(rsa.Sign(transaction.Hash()), key.publicKey);

            //Create p2sh and insert p2pkh in it
            LockingScript   ls1 = new LockingScript(ls);
            UnlockingScript us1 = new UnlockingScript(ls, us);

            us1.InsertScript(ls1);

            Assert.AreEqual(EXECUTION_RESULT.SUCCESS, us1.Run(transaction), "Execution of P2SH script failed");
        }