You want to work with the digests, not the hex strings.
Here's some Ruby:
require 'digest'
d = Digest::SHA2.new 256
d2 = Digest::SHA2.new 256
d << 'hello'
d.to_s
d2 << d.digest
d2.to_s
This will be the output from irb:
1.9.3p194 :001 > require 'digest'
=> true
1.9.3p194 :003 > d = Digest::SHA2.new 256
=> #<Digest::SHA2:256 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855>
1.9.3p194 :004 > d2 = Digest::SHA2.new 256
=> #<Digest::SHA2:256 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855>
1.9.3p194 :005 > d << 'hello'
=> #<Digest::SHA2:256 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824>
1.9.3p194 :006 > d.to_s
=> "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
1.9.3p194 :007 > d2 << d.digest
=> #<Digest::SHA2:256 9595c9df90075148eb06860365df33584b75bff782a510c6cd4883a419833d50>
1.9.3p194 :008 > d2.to_s
=> "9595c9df90075148eb06860365df33584b75bff782a510c6cd4883a419833d50"
Here's the same thing in Python:
import hashlib
d = hashlib.sha256(b"hello")
d2 = hashlib.sha256()
d.hexdigest()
d2.update(d.digest())
d2.hexdigest()
And the output from within a Python shell:
>>> d = hashlib.sha256(b"hello")
>>> d2 = hashlib.sha256()
>>> d.hexdigest()
'2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'
>>> d2.update(d.digest())
>>> d2.hexdigest()
'9595c9df90075148eb06860365df33584b75bff782a510c6cd4883a419833d50'
3Just semantics, but to avoid a common misunderstanding: sha256 does hashing, not encoding. Encoding is something entirely different. For one it implies it can be decoded, whereas hashing is strictly a one-way (and destructive) operation. – RocketNuts – 2016-02-29T18:48:51.723