Re: Convert private data hash to string


Brett T Logan <brett.t.logan@...>
 

Ah, its hex, you need to use one of the functions on: https://golang.org/pkg/encoding/hex/ to decode it or you can use `fmt.Sprintf("%x", bytes)` to convert it to a raw string
 
Brett Logan
Software Engineer, IBM Blockchain
Phone: 1-984-242-6890
 
 
 

----- Original message -----
From: "Harris Niavis" <harniavis@...>
Sent by: fabric@...
To: David Enyeart <enyeart@...>
Cc: Brett T Logan <brett.t.logan@...>, fabric@...
Subject: [EXTERNAL] Re: [Hyperledger Fabric] Convert private data hash to string
Date: Tue, May 26, 2020 11:19 PM
 
Thanks for your replies!
 
Yes what I am trying to do is to verify that the on-chain hash matches the pre-image value. 
 
I am trying by just converting the value to string as Brett suggests, but I get a string with some unknown characters, like it is broken.
 
"147 141 21 229 178 55 109 221 21 1 25 145 174 255 249 181 206 109 138 135 215 1 190 31 167 101 233 126 69 157 219 182]
�� ��7m� ������m��� � �e�~E�۶
 
So I thought I was doing something wrong. Any suggestions on what is going wrong here?
 
Harris
 
 
 
On Mon, 25 May 2020 at 21:39, David Enyeart <enyeart@...> wrote:

A hash is a one way operation, so if you are trying to convert the hash back into the pre-image, it cannot be done (that's the whole point!). But you can verify that the on-chain hash matches some known pre-image value, by taking a sha256 hash of the value and comparing the two, either inside the chaincode, or on client side. Here's a sample of how to do the verification within chaincode:
https://github.com/hyperledger/fabric-samples/blob/master/chaincode/marbles_transfer/marbles_transfer.go#L261-L281


Dave Enyeart

"Brett T Logan" ---05/25/2020 06:15:25 PM---Byte slices in Go can be cast directly to strings `string(bytes)` Brett Logan

From: "Brett T Logan" <brett.t.logan@...>
To: harniavis@...
Cc: fabric@...
Date: 05/25/2020 06:15 PM
Subject: [EXTERNAL] Re: [Hyperledger Fabric] Convert private data hash to string
Sent by: fabric@...





Byte slices in Go can be cast directly to strings `string(bytes)`

Brett Logan
Software Engineer, IBM Blockchain
Phone: 1-984-242-6890
E-mail: brett.t.logan@...




----- Original message -----
From: "Harris Niavis" <harniavis@...>
Sent by: fabric@...
To: fabric@...
Cc:
Subject: [EXTERNAL] [Hyperledger Fabric] Convert private data hash to string
Date: Mon, May 25, 2020 6:09 PM


Hi all,

I am looking for a way to check the hash on the ledger, produced by the private data collection, I use the GetPrivateDataHash function in the chaincode, which returns the hash in bytes.

How can I umarshal and convert this to string? Do I need to know the bytes encoding structure?

Thanks,
Harris

--
Harris Niavis
Yale Institute of Network Science (YINS)
s: niavisharris
e: harniavis@...





 

 

 

 

 
 
--
Harris Niavis
Yale Institute of Network Science (YINS)
University of Thessaly (UTH)
Centre for Research and Technology Hellas (CERTH)
s: niavisharris
 

Join fabric@lists.hyperledger.org to automatically receive all group messages.