Getting wrong result from SHA256 than what is expected

0 votes

I am trying to derive a bitcoin address from a known public key. When hashing the public key with CryptoJS.SHA256 I don't get the expected result

CryptoJS.SHA256("0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6").toString(CryptoJS.enc.Hex)

gets me:

32511e82d56dcea68eb774094e25bab0f8bdd9bc1eca1ceeda38c7a43aceddce

while i am trying to get:

600FFE422B4E00731A59557A5CCA46CC183944191006324A447BDB2D98D4B408

Please help

Sep 6, 2018 in Blockchain by slayer
• 29,370 points
1,673 views

1 answer to this question.

0 votes

It's just an encoding issue - don't try to hash the hex, hash the binary.

For example, here is the hash computation when you decode the hex into binary (using Haskell since I have it handy):

Prelude> import Crypto.Hash.SHA256
Prelude Crypto.Hash.SHA256> let str = "0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6"
Prelude Crypto.Hash.SHA256> Data.ByteString.Base16.encode $ hash $ fst $  Data.ByteString.Base16.decode $ Data.ByteString.Char8.pack str
"600ffe422b4e00731a59557a5cca46cc183944191006324a447bdb2d98d4b408"
answered Sep 6, 2018 by digger
• 26,740 points

Related Questions In Blockchain

0 votes
1 answer

Not getting correct result after SHA256

You have to: Hash with SHA-256 the public key: 0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6 Hash with RIPEMD-160 the ...READ MORE

answered Sep 11, 2018 in Blockchain by digger
• 26,740 points
897 views
+1 vote
1 answer

What is Ethereum Blockchain? Where is it being used?

Blockchain is a decentralized distributed database of immutable records, ...READ MORE

answered Apr 3, 2018 in Blockchain by Christine
• 15,790 points
1,158 views
+4 votes
3 answers

What type of database is blockchain?

Blockchain is a distributed database. what makes ...READ MORE

answered Mar 30, 2018 in Blockchain by Christine
• 15,790 points
1,322 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,923 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
45,219 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
886 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,428 views
+1 vote
1 answer

What is blockchain apart from bitcoin?

Blockchain is a decentralized database where the ...READ MORE

answered Jul 9, 2018 in Blockchain by digger
• 26,740 points
839 views
0 votes
1 answer

SHA256 does not give expected result.

You're hashing the string when you're supposed ...READ MORE

answered Aug 24, 2018 in Blockchain by digger
• 26,740 points
1,290 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP