1

Does anyone knows how the dgst function of the Openssl library manage the input value? I mean, it considers the input value as ASCII characters or in any other charset encoding?
I'm trying to input hexadecimal values but can't find how to do this:

$echo -n "FFFF" | openssl dgst -sha256

The result is different from the obtained by other ways (e.g. Java's MessageDigest) with the hexadecimal number '0xFFFF' as input.

CarlosRos
  • 389
  • 6
  • 15
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. Also see [Where do I post questions about Dev Ops?](http://meta.stackexchange.com/q/134306). – jww Dec 18 '15 at 06:04

1 Answers1

0

Normally dgst takes ASCII input, to get hash of 0xFFFF try:

printf "\xFF\xFF" | openssl dgst -sha256

The result should be: ca2fd00fa001190744c15c317643ab092e7048ce086a243e2be9437c898de1bb

Leśny Rumcajs
  • 2,259
  • 2
  • 17
  • 33
  • That's correct. Now I must figure out how to convert large hex numbers into that format. – CarlosRos Dec 17 '15 at 12:50
  • For example using one of the many answers from here: https://stackoverflow.com/questions/1604765/linux-shell-scripting-hex-string-to-bytes . You'll probably want to write a bash script to even further simplify your sha256 digest usage. – Leśny Rumcajs Dec 17 '15 at 13:15