I’m trying to run the following command in an .ex file - openssl ec -in myprivatekey.pem -outform DER|tail -c +8|head -c 32|xxd -p -c 32, which I tried to translate to {_, 0} = System.cmd "openssl", [ "ec", "-in", private_key_file, "-outform", "DER|tail", "-c", "+8|head", "-c", "32|xxd", "-p", "-c", "32"], [stderr_to_stdout: true]
However, this line gives me the following error -
** (MatchError) no match of right hand side value: {"unknown option -c\nec [options] <infile >outfile\nwhere options are\n -inform arg input format - DER or PEM\n -outform arg output format - DER or PEM\n -in arg input file\n -passin arg input file pass phrase source\n -out arg output file\n -passout arg output file pass phrase source\n -engine e use engine e, possibly a hardware device.\n -des encrypt PEM output, instead of 'des' every other \n cipher supported by OpenSSL can be used\n -text print the key\n -noout don't print key out\n -param_out print the elliptic curve parameters\n -conv_form arg specifies the point conversion form \n possible values: compressed\n uncompressed (default)\n hybrid\n -param_enc arg specifies the way the ec parameters are encoded\n in the asn1 der encoding\n possible values: named_curve (default)\n explicit\n", 1}
What is the correct way to execute that particular openssl command?
So reformatted you get the following error back from openssl and an exitcode of 1:
unknown option -c
ec [options] <infile >outfile
where options are
-inform arg input format - DER or PEM
-outform arg output format - DER or PEM
-in arg input file
-passin arg input file pass phrase source
-out arg output file
-passout arg output file pass phrase source
-engine e use engine e, possibly a hardware device.
-des encrypt PEM output, instead of 'des' every other
cipher supported by OpenSSL can be used
-text print the key
-noout don't print key out
-param_out print the elliptic curve parameters
-conv_form arg specifies the point conversion form
possible values: compressed
uncompressed (default)
hybrid
-param_enc arg specifies the way the ec parameters are encoded
in the asn1 der encoding
possible values: named_curve (default)
explicit
This is because you are trying to do this in bash-syntax:
What you really want is to either use Port module to start separate instances of openssl, tail, head and xxd where you send the output of the former stage to as a message while receiving the outputs via messages. But this is quite some massive overhead.
I really think the easiest thing where to tail, head and xxd inside of elixir.