openssl-ec-and-ecparam

1、openssl ec: 
[vagrant@vm-node1:btc]$ openssl ec -help 
Usage: ec [options]

General options:
 -help               Display this summary
 -engine val         Use engine, possibly a hardware device

Input options:
 -in val             Input file
 -inform format      Input format (DER/PEM/P12/ENGINE)
 -pubin              Expect a public key in input file
 -passin val         Input file pass phrase source
 -check              check key consistency
 -*                  Any supported cipher
 -param_enc val      Specifies the way the ec parameters are encoded
 -conv_form val      Specifies the point conversion form

Output options:
 -out outfile        Output file
 -outform PEM|DER    Output format - DER or PEM
 -noout              Don't print key out
 -text               Print the key
 -param_out          Print the elliptic curve parameters
 -pubout             Output public key, not private
 -no_public          exclude public key from private key
 -passout val        Output file pass phrase source

Provider options:
 -provider-path val  Provider load path (must be before 'provider' argument if required)
 -provider val       Provider to load (can be specified multiple times)
 -propquery val      Property query used when fetching algorithms





2、openssl ecparam
[vagrant@vm-node1:btc]$ openssl ecparam -help
Usage: ecparam [options]

General options:
 -help               Display this summary
 -list_curves        Prints a list of all curve 'short names'
 -engine val         Use engine, possibly a hardware device
 -genkey             Generate ec key
 -in infile          Input file  - default stdin
 -inform PEM|DER     Input format - default PEM (DER or PEM)
 -out outfile        Output file - default stdout
 -outform PEM|DER    Output format - default PEM

Output options:
 -text               Print the ec parameters in text form
 -noout              Do not print the ec parameter
 -param_enc val      Specifies the way the ec parameters are encoded

Parameter options:
 -check              Validate the ec parameters
 -check_named        Check that named EC curve parameters have not been modified
 -no_seed            If 'explicit' parameters are chosen do not use the seed
 -name val           Use the ec parameters with specified 'short name'
 -conv_form val      Specifies the point conversion form

Random state options:
 -rand val           Load the given file(s) into the random number generator
 -writerand outfile  Write random data to the specified file

Provider options:
 -provider-path val  Provider load path (must be before 'provider' argument if required)
 -provider val       Provider to load (can be specified multiple times)
 -propquery val      Property query used when fetching algorithms


3、使用示例
#!/bin/sh

PRIVATE_KEY="ECDSA"
PUBLIC_KEY="ECDSA.pub"
BITCOIN_PRIVATE_KEY="bitcoin"
BITCOIN_PUBLIC_KEY="bitcoin.pub"

echo "Generating private key"
openssl ecparam -genkey -name secp256k1 -rand /dev/random -out $PRIVATE_KEY

echo "Generating public key"
openssl ec -in $PRIVATE_KEY -pubout -out $PUBLIC_KEY

echo "Generating Bitcoin private key"
openssl ec -in $PRIVATE_KEY -outform DER|tail -c +8|head -c 32|xxd -p -c 32 > $BITCOIN_PRIVATE_KEY

echo "Generating Bitcoin public key"
openssl ec -in $PRIVATE_KEY -pubout -outform DER|tail -c 65|xxd -p -c 65 > $BITCOIN_PUBLIC_KEY