I would like to sign a file using a dsa key and openssl. The DGST(1) man page says the following:
file...
file or files to digest. If no files are specified then standard input is used.
For me this means that the following two terminal commands should give the same results, which they do not. I piped the output through od because the result is binary.
specify the file on command line
openssl dgst -dss1 -sign private_key.pem test_archive.zip | od -x 0000000 2c30 1402 e30d 9073 0059 0de7 f03e 8fd2 0000020 874b 5252 b025 8f44 1402 ed26 2f55 7fa4 0000040 f474 0426 1d44 787c ecd6 5059 921b 0000056piping the file into the openssl command
openssl dgst -dss1 -sign private_key.pem < test_archive.zip | od -x 0000000 2c30 1402 2444 c3a5 f498 7bb8 3dfe 715d 0000020 e179 c5ad c0a5 2b16 1402 173b 692b 9d71 0000040 3970 c497 9994 9cbc 4cfd d642 62df 0000056
As you can see both outputs are not the same, although the file which should be signed is the same in both cases.
Why is this the case? Am I missing something obvious here?
Edit
I am using OpenSSL version 0.9.8y 5 Feb 2013 on FreeBSD and version 0.9.8r 8 Feb 2011 on Mac OS X 10.7.5 and observing the effect on both.
Edit 2 - How to generate a key for testing
small shell script for generating appropriate keys
#!/bin/bash
openssl=/usr/bin/openssl
${openssl} dsaparam 1024 < /dev/urandom > dsaparam.pem
${openssl} gendsa dsaparam.pem -out private_key.pem
${openssl} dsa -in private_key.pem -pubout -out public_key.pem
rm dsaparam.pem
I also ran a test on a CentOS 6 Linux system using OpenSSL version 1.0.0-fips which shows the same strange behavior.
Edit 3 - More Versions Tested
Also the freshly compiled OpenSSL version 1.0.1e 11 Feb 2013 shows this behavior.