Skip to content Skip to sidebar Skip to footer

Openssl Sha1 Giving Different Results In The Terminal Vs In Python

I am trying to run an openssl command from a Python script, but am getting different sha1 values from the command executed in the script and the command executed directly in the te

Solution 1:

TL;DR: use /bin/echo

Explanation:

The python system command is likely using a default shell of /bin/sh which is usually linked to a POSIX compliant shell, while your terminal session is using your user's login shell which is likely bash. POSIX shell standard does not support the -n option to the echo builtin function. This mean you are literally calculating the digest of "-n abc". You can reproduce this is bash like so:

echo"-n abc" | openssl sha1
9d4fe92b8bdc894f5838fad83108bf3841b257fa

The binary executable is still available but will need to be called by the full path since the shell builtin will override it. Instead of echo, use /bin/echo.

Post a Comment for "Openssl Sha1 Giving Different Results In The Terminal Vs In Python"