Reputation: 2017
I have a command cat hash.bin | openssl pkeyutl -sign -inkey privk.pem
which can get result correctly.
Now I want to do it with python subprocess
, I do it like this (where hash
is read from hash.bin)
cmd = ['openssl', 'pkeyutl', '-sign', '-inkey ', prvk]
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
out = p.communicate(input=hash)[0]
print(out)
But openssl failed.
I can't use -in
and -out
because my code can't access to hard drive..
Upvotes: 0
Views: 628
Reputation: 87084
The problem is caused by the stray space character following the inkey
command.
Try removing the space and it should work:
cmd = ['openssl', 'pkeyutl', '-sign', '-inkey', prvk]
The reason is that Popen()
is passing through the space character as part of the -inkey
option's token. openssl is deciding that there is not an option named -inkey
(with a space), so it exits. It is as if you were executing this from the command line:
cat hash.bin | openssl pkeyutl -sign '-inkey ' privk.pem
which fails.
Upvotes: 1