Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I get different results from the Linux command "sha256sum" and the Pony stdlib "Digest" functions.
- Using the command line:
- echo "123456" | sha256sum
- e150a1ec81e8e93e1eae2c3a77e66ec6dbd6a3b460f89c1d08aecf422ee401a0 -
- Using the Pony program shown below:
- sha256 of '123456' is 8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92
- use "crypto"
- actor Main
- new create( env: Env ) =>
- let input = "123456"
- let hasher = Digest.sha256()
- try hasher.append( input ) end
- let binhash = hasher.final()
- // Convert the binary hash to a hex string. We know the length
- // will be twice as long so we can preallocate enough space.
- let hexhash = String( binhash.size()*2 )
- var i: USize = 0
- while i < binhash.size() do
- let byte = try binhash(i) else 0 end
- hexhash.push( _hexdigit((byte and 0xF0 ) >> 4))
- hexhash.push( _hexdigit( byte and 0x0F ))
- i = i + 1
- end
- env.out.print("sha256 of '"+input+"' is "+hexhash)
- fun ref _hexdigit( n: U8 ): U8 =>
- try "0123456789abcdef"(n.usize()) else '0' end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement