Beispiel #1
0
        public static KeyPair Generate(bool compressed)
        {
            var randomKey = Secp256K1Manager.GenerateRandomKey();
            var array1    = new byte[1].Concat(Ripemd160Manager.GetHash(Sha256Manager.GetHash(Secp256K1Manager.GetPublicKey(randomKey, compressed)))).ToArray();
            var pub       = Base58.Encode(array1.Concat(Sha256Manager.GetHash(Sha256Manager.GetHash(array1)).Take(4)).ToArray());

            byte[] array2;
            if (!compressed)
            {
                array2 = new byte[1]
                {
                    128
                }
            }
Beispiel #2
0
        public static byte[] GetHash(byte[] data)
        {
            var num1 = 72;
            var num2 = data.Length % 64;

            if (num2 > 56)
            {
                num1 = 128 - num2;
            }
            else if (num2 < 56)
            {
                num1 = 64 - num2;
            }
            var x = new uint[(data.Length + num1) / 4];

            Buffer.BlockCopy((Array)data, 0, (Array)x, 0, data.Length);
            x[data.Length / 4] |= (uint)(1 << 8 * (data.Length % 4) + 7);
            x[x.Length - 2]     = (uint)(data.Length << 3);
            x[x.Length - 1]     = (uint)data.Length >> 29;
            return(Ripemd160Manager.DoHash(x));
        }
Beispiel #3
0
        private static byte[] DoHash(uint[] x)
        {
            uint num1 = 1732584193;
            var  num2 = 4023233417;
            var  num3 = 2562383102;
            uint num4 = 271733878;
            var  num5 = 3285377520;

            for (var index1 = 0; index1 < x.Length / 16; ++index1)
            {
                var num6 = num1;
                var num7 = num1;
                var x1   = num2;
                var x2   = num2;
                var y1   = num3;
                var y2   = num3;
                var z1   = num4;
                var z2   = num4;
                var num8 = num5;
                var num9 = num5;
                for (var index2 = 0; index2 < 80; ++index2)
                {
                    var j1     = index2 / 16;
                    var num10  = Ripemd160Manager.R[index2];
                    var num11  = Ripemd160Manager.K[j1];
                    var num12  = x[index1 * 16 + (int)num10];
                    var shift1 = Ripemd160Manager.S[index2];
                    var num13  = (int)Ripemd160Manager.Rol(num6 + Ripemd160Manager.F(j1, x1, y1, z1) + num12 + num11, shift1) + (int)num8;
                    num6 = num8;
                    num8 = z1;
                    z1   = Ripemd160Manager.Rol(y1, (byte)10);
                    y1   = x1;
                    x1   = (uint)num13;
                    var j2     = 4 - j1;
                    var num14  = Ripemd160Manager.R1[index2];
                    var num15  = Ripemd160Manager.K1[j1];
                    var num16  = x[index1 * 16 + (int)num14];
                    var shift2 = Ripemd160Manager.S1[index2];
                    var num17  = (int)Ripemd160Manager.Rol(num7 + Ripemd160Manager.F(j2, x2, y2, z2) + num16 + num15, shift2) + (int)num9;
                    num7 = num9;
                    num9 = z2;
                    z2   = Ripemd160Manager.Rol(y2, (byte)10);
                    y2   = x2;
                    x2   = (uint)num17;
                }
                var num18 = (int)num2 + (int)y1 + (int)z2;
                num2 = num3 + z1 + num9;
                num3 = num4 + num8 + num7;
                num4 = num5 + num6 + x2;
                num5 = num1 + x1 + y2;
                num1 = (uint)num18;
            }
            var numArray = new byte[20];

            Buffer.BlockCopy((Array)BitConverter.GetBytes(num1), 0, (Array)numArray, 0, 4);
            Buffer.BlockCopy((Array)BitConverter.GetBytes(num2), 0, (Array)numArray, 4, 4);
            Buffer.BlockCopy((Array)BitConverter.GetBytes(num3), 0, (Array)numArray, 8, 4);
            Buffer.BlockCopy((Array)BitConverter.GetBytes(num4), 0, (Array)numArray, 12, 4);
            Buffer.BlockCopy((Array)BitConverter.GetBytes(num5), 0, (Array)numArray, 16, 4);
            return(numArray);
        }