コード例 #1
0
        public static byte[] Hash(byte[] input)
        {
            DZen.Security.Cryptography.SHA3 sha3 = DZen.Security.Cryptography.SHA3.Create("sha3-256");
            sha3.UseKeccakPadding = true;
            byte[] hashBytes = sha3.ComputeHash(input);

            return(hashBytes);
        }
コード例 #2
0
        public static byte[] GetPubAddress(string privateKey)
        {
            //	ECKey ecKey = new ECKey();
            //	ECPrivateKeyParameters ecPrivateKeyParameters = ecKey._privateKey;
            //	byte[] bytes = ecPrivateKeyParameters.D.ToByteArray();
            ECKeyPair ecKeyPair = new ECKeyPair(privateKey);

            byte[] bytesPub64 = ecKeyPair.ECPublicKey.Q.GetEncoded().SubArray(1, 64);
            DZen.Security.Cryptography.SHA3 sha3 = DZen.Security.Cryptography.SHA3.Create("sha3-256");
            sha3.UseKeccakPadding = true;
            byte[] computeHash = sha3.ComputeHash(bytesPub64);

            //byte[] computeHash = Sha3.Sha3256().ComputeHash(bytesPub65,1,64);//.ComputeHash(bytes, 12, 20);
            computeHash.ToHexString2();

            byte[] computeHash20 = new byte[20];
            computeHash20 = computeHash.SubArray(11, 21);
            computeHash20.ToHexString2();

            computeHash20[0] = 65;
            byte[] address41 = computeHash20;

            //	byte[] hexStringToByteArray = StringHelper.HexStringToByteArray("415a523b449890854c8fc460ab602df9f31fe4293f");
            //	address41 = hexStringToByteArray;
            string hexString2 = address41.ToHexString2();

            byte[] SecondSHA           = Sha256.HashTwice(address41);
            byte[] checkSum            = SecondSHA.SubArray(0, 4);
            string SecondSHAhexString2 = SecondSHA.ToHexString2();

            byte[] address = new byte[address41.Length + 4];
            Array.Copy(address41, 0, address, 0, address41.Length);
            Array.Copy(checkSum, 0, address, 21, 4);

            string hexString = address.ToHexString2();
            string encode    = Base58.Encode(address);

            //415a523b449890854c8fc460ab602df9f31fe4293f
            return(address);
        }