Title: How to generate the hash of public key in Bitcoin Post by: PrettyGirl741963 on February 24, 2020, 08:14:35 AM I'm trying to hash the public key with SHA256 and then ripemed160 and get the hash. but it gives the error "System.ArgumentOutOfRangeException: 'Index and length must refer to a location within the string. Parameter name: length'" I think it's because of the odd number of characters of the public key.
Public key: 2b4632d08485ff1df2db55b9dafd23347d1c47a457072a1e87be26896549a8737 Hash should be: 93ce48570b55c42c2af816aeaba06cfee1224fae Code: Imports System.Security.Cryptography what I want to achieve is : bitcoin Public key --> SHA256 --> RIPEMD160 = final hash Title: Re: How to generate the hash of public key in Bitcoin Post by: pooya87 on February 24, 2020, 08:26:19 AM Quote Code: Dim public_key as String = "2b4632d08485ff1df2db55b9dafd23347d1c47a457072a1e87be26896549a8737" your "public_key" variable is a hexadecimal string not a Unicode string and that means your initial byte array that you hash is the wrong value. you already have a function called "HexStringToByteArray", i'm not sure if it is a correct conversion but if it is then use that instead of "System.Text.Encoding.Unicode.GetBytes" Title: Re: How to generate the hash of public key in Bitcoin Post by: PrettyGirl741963 on February 24, 2020, 08:53:09 AM Public keys are not hexadecimal, this is an actual bitcoin public address :
Quote mwZVuA4D5TSSymdXZza4S1YhZFnH2fcaeG see it's not a hexadecimal Title: Re: How to generate the hash of public key in Bitcoin Post by: pooya87 on February 24, 2020, 09:16:18 AM Public keys are not hexadecimal, this is an actual bitcoin public address : Quote mwZVuA4D5TSSymdXZza4S1YhZFnH2fcaeG see it's not a hexadecimal there is a difference between "public key" and an "address" or if you like public address. public key is an x,y coordinate of a point located on the elliptic curve while address is a base58 encoding of hash of the public key. what you posted here is a testnet address and it is using base58 encoding. (you still should use Unicode to decode this) however public keys are usually presented in base-16 or hexadecimal format. additionally in your code the variable called public_key is indeed a public key and is indeed using hexadecimal encoding. Title: Re: How to generate the hash of public key in Bitcoin Post by: PrettyGirl741963 on February 24, 2020, 10:06:09 AM Public keys are not hexadecimal, this is an actual bitcoin public address : Quote mwZVuA4D5TSSymdXZza4S1YhZFnH2fcaeG see it's not a hexadecimal there is a difference between "public key" and an "address" or if you like public address. public key is an x,y coordinate of a point located on the elliptic curve while address is a base58 encoding of hash of the public key. what you posted here is a testnet address and it is using base58 encoding. (you still should use Unicode to decode this) however public keys are usually presented in base-16 or hexadecimal format. additionally in your code the variable called public_key is indeed a public key and is indeed using hexadecimal encoding. Thank you for the explanation I didn't know that, but I changed the code to convert it to byte array from hex string. then it gives me this error. I think it's because of the odd number of characters of the public key Quote System.ArgumentOutOfRangeException: 'Index and length must refer to a location within the string. Parameter name: length' Title: Re: How to generate the hash of public key in Bitcoin Post by: PrettyGirl741963 on February 25, 2020, 05:02:28 AM updated with code, now gets an error
|