Using Oracle STANDARD_HASH, reproduce the hash in JAVA -
i'm using standard_hash('input','sha256') function within oracle populate records relative hash values.
this can reproduced connecting oracle doing:
select standard_hash('1234','sha256') dual
table x column 1, column 1-hashed 1234, sha512hashresult 1234, sha512hashresult 1234, sha512hashresult 1234, sha512hashresult
now whats question; have in java in order reproduce hash values produced standard_hash in oracle? have experience this?
note; reason there no seed on recommended oracle hash function. know default seed or how figure out?
background: want do? populate table within oracle oracle-default-tools , use java program receive input, hash , select correct record in table.
what don't want; people tell me how can achieve in different way, need way otherwise save time
you can standard libraries. use java.security.messagedigest algorithm sha-256
:
import java.nio.charset.standardcharsets; import java.security.messagedigest; import javax.xml.bind.datatypeconverter; ... string input = "1234"; byte[] hashbytes = messagedigest.getinstance("sha-256") .digest(input.getbytes(standardcharsets.utf_8)); string hash = datatypeconverter.printhexbinary(hashbytes); system.out.println(hash);
this prints 03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4
, same string standard_hash
return.
as discussed in how convert byte array hex string in java?, there faster ways convert byte[]
hex string, datatypeconverter.printhexbinary()
has benefit of being part of standard library, , should fine use cases.
Comments
Post a Comment