Example #1
0
        public static string GetAddressOfcompressed(BigInteger[] publicKey, bool show)
        {
            var publicKeyArray1 = HexToByteArray.BigIntegerTo32ByteArray(publicKey[0]);

            HexToByteArray.ChangeDirection(ref publicKeyArray1);
            // var publicKeyArray2 = HexToByteArray.BigIntegerTo32ByteArray(publicKey[1]);

            byte[] resultAdd;
            if (publicKey[1].IsEven)
            {
                resultAdd = Calculate.BiteSplitJoint(new byte[] { 0x02 }, publicKeyArray1);
            }
            else
            {
                resultAdd = Calculate.BiteSplitJoint(new byte[] { 0x03 }, publicKeyArray1);
            }

            if (show)
            {
                Console.WriteLine($"压缩公钥为{ Hex.BytesToHex(resultAdd)}");
            }
            //   Console.WriteLine($"压缩公钥为{ Calculate.Encode(resultAdd)}");

            var step3 = ripemd160.ComputeHash(sha256.ComputeHash(resultAdd));

            var step4 = Calculate.BiteSplitJoint(new byte[] { 0x00 }, step3);

            var step5 = sha256.ComputeHash(sha256.ComputeHash(step4));

            var step6 = Calculate.BiteSplitJoint(step4, new byte[] { step5[0], step5[1], step5[2], step5[3] });

            return(Calculate.Encode(step6));
        }
Example #2
0
        public static string GetAddressOfUncompressed(BigInteger[] publicKey)
        {
            var publicKeyArray1 = HexToByteArray.BigIntegerTo32ByteArray(publicKey[0]);

            HexToByteArray.ChangeDirection(ref publicKeyArray1);
            var publicKeyArray2 = HexToByteArray.BigIntegerTo32ByteArray(publicKey[1]);

            HexToByteArray.ChangeDirection(ref publicKeyArray2);
            //    var array = HexToByteArray.BigIntegerTo32ByteArray(privateKey);

            var resultAdd = Calculate.BiteSplitJoint(new byte[] { 0x04 }, publicKeyArray1);

            resultAdd = Calculate.BiteSplitJoint(resultAdd, publicKeyArray2);
            Console.WriteLine($"非压缩公钥为{ Hex.BytesToHex(resultAdd)}");


            var step3 = ripemd160.ComputeHash(sha256.ComputeHash(resultAdd));

            var step4 = Calculate.BiteSplitJoint(new byte[] { 0x00 }, step3);

            var step5 = sha256.ComputeHash(sha256.ComputeHash(step4));

            var step6 = Calculate.BiteSplitJoint(step4, new byte[] { step5[0], step5[1], step5[2], step5[3] });

            return(Calculate.Encode(step6));

            //SHA256 sha256 = new SHA256Managed();
            //byte[] hash1 = sha256.ComputeHash(resultAdd);

            //var pubKeyHash = Hash160.Hash(publicKey.EncodePoint(hash1));
            //byte[] hash2 = sha256.ComputeHash(hash1);

            //var result = new byte[CheckSumSizeInBytes];
            //Buffer.BlockCopy(hash2, 0, result, 0, result.Length);

            //byte[] chechHash = Calculate.GetCheckSum(resultAdd);
        }
Example #3
0
        public static void SecretFileF()
        {
            while (true)
            {
                Console.WriteLine($"输入助记词!");
                SHA256 sha256 = new SHA256Managed();
                byte[] hash   = sha256.ComputeHash(Encoding.UTF8.GetBytes(Console.ReadLine()));
                // var privateKey = HexToBigInteger.inputHex("e8d96a53e9c597e5a1e2ceaddd0b5ebe75588b26e71846b46a9b5f3666409355");

                //var inputSting = "e8d96a53e9c597e5a1e2ceaddd0b5ebe75588b26e71846b46a9b5f3666409355";
                //var inputSting = ;
                var privateKey = Bytes32.ConvetToBigInteger(hash);
                privateKey = privateKey % Secp256k1.q;
                var privateByte = hash;

                {
                    var resultAdd = Calculate.BiteSplitJoint(new byte[] { 0x80 }, privateByte);
                    resultAdd = Calculate.BiteSplitJoint(resultAdd, new byte[] { 0x01 });
                    byte[] chechHash = Calculate.GetCheckSum(resultAdd);
                    resultAdd = Calculate.BiteSplitJoint(resultAdd, chechHash);
                    var privateKey1 = Calculate.Encode(resultAdd);
                    Console.WriteLine($"您压缩后的私钥为{privateKey1}");
                }
                {
                    var    resultAdd = Calculate.BiteSplitJoint(new byte[] { 0x80 }, privateByte);
                    byte[] chechHash = Calculate.GetCheckSum(resultAdd);
                    resultAdd = Calculate.BiteSplitJoint(resultAdd, chechHash);
                    var privateKey1 = Calculate.Encode(resultAdd);
                    Console.WriteLine($"您压缩前的私钥为{privateKey1}");
                }
                var publicKey = Calculate.getPublicByPrivate(privateKey);
                if (publicKey != null)
                {
                    var walletOfcompressed = PublicKeyF.GetAddressOfcompressed(publicKey);
                    Console.WriteLine($"压缩钱包地址为:{walletOfcompressed}");
                    var walletOfUncompressed = PublicKeyF.GetAddressOfUncompressed(publicKey);
                    Console.WriteLine($"非压缩钱包地址为:{walletOfUncompressed}");
                }
                else
                {
                    Console.WriteLine($"您输入了零元!");
                }
                Console.WriteLine("E/Exit,退出当前");

                if (Console.ReadLine().ToUpper() == "E")
                {
                    break;
                }
            }


            //Console.WriteLine($"您的非私钥为80{HexToBigInteger.bigIntergetToHex(publicKey[0])}01");


            //var publicKeyName = getPublicKeyName(publicKey);
            //Console.WriteLine($"您的公钥16进制为{publicKeyName}");
            //if (publicKey != null)
            //    Console.WriteLine($"您的公钥10进制为:{publicKey[0]},{publicKey[1]}");


            //Random rm = new Random(DateTime.Now.GetHashCode());
            //for (var i = 1; i <= 256 * 256; i++)
            //{
            //    var M = getPublicByPrivate(new BigInteger(i));
            //}
            //   throw new NotImplementedException();
        }