BSV-ex v0.2.3 BSV.Crypto.ECDSA View Source
Functions for use with ECDSA asymmetric cryptography.
Examples
iex> private_key = BSV.Crypto.ECDSA.generate_key
...> public_key = BSV.Crypto.ECDSA.PrivateKey.get_public_key(private_key)
...>
...> "hello world"
...> |> BSV.Crypto.ECDSA.sign(private_key)
...> |> BSV.Crypto.ECDSA.verify("hello world", public_key)
true
Link to this section Summary
Functions
Generates a new ECDSA private key.
Generates a new ECDSA public and private key pair, returned as a tuple containing two binaries.
Decodes the given PEM string into a ECDSA key.
Encodes the given public or private key into a PEM string.
Creates a signature for the given message, using the given private key.
Verify the given message and signature, using the given public key.
Link to this section Functions
generate_key(options \\ [])
View Sourcegenerate_key(keyword()) :: BSV.Crypto.ECDSA.PrivateKey.t()
Generates a new ECDSA private key.
Options
The accepted options are:
:named_curve
- Specify the elliptic curve name. Defaults to:secp256k1
.
Examples
iex> private_key = BSV.Crypto.ECDSA.generate_key
...> private_key.__struct__ == BSV.Crypto.ECDSA.PrivateKey
true
Generates a new ECDSA public and private key pair, returned as a tuple containing two binaries.
Options
The accepted options are:
:named_curve
- Specify the elliptic curve name. Defaults to:secp256k1
.:private_key
- When a private key binary is given, it will be returned with its public key.
Examples
iex> BSV.Crypto.ECDSA.generate_key_pair
...> |> is_tuple
true
iex> ecdsa_key = BSV.Crypto.ECDSA.PrivateKey.from_sequence(BSV.Test.ecdsa_key)
...>
...> public_key = BSV.Crypto.ECDSA.generate_key_pair(private_key: ecdsa_key.private_key)
...> |> elem(0)
...> public_key == ecdsa_key.public_key
true
pem_decode(pem)
View Sourcepem_decode(binary()) :: BSV.Crypto.ECDSA.PrivateKey.t()
Decodes the given PEM string into a ECDSA key.
Examples
iex> ecdsa_key = BSV.Crypto.ECDSA.PrivateKey.from_sequence(BSV.Test.ecdsa_key)
...> pem = BSV.Crypto.ECDSA.pem_encode(ecdsa_key)
...>
...> imported_key = BSV.Crypto.ECDSA.pem_decode(pem)
...> imported_key == ecdsa_key
true
pem_encode(ecdsa_key)
View Sourcepem_encode(BSV.Crypto.ECDSA.PrivateKey.t()) :: binary()
Encodes the given public or private key into a PEM string.
Examples
iex> BSV.Crypto.ECDSA.PrivateKey.from_sequence(BSV.Test.ecdsa_key)
...> |> BSV.Crypto.ECDSA.pem_encode
...> |> String.starts_with?("-----BEGIN EC PRIVATE KEY-----")
true
sign(message, private_key, options \\ [])
View Sourcesign(binary(), BSV.Crypto.ECDSA.PrivateKey.t() | binary(), keyword()) :: binary()
Creates a signature for the given message, using the given private key.
Options
The accepted options are:
:named_curve
- Specific the elliptic curve name. Defaults to:secp256k1
.:encoding
- Optionally encode the returned binary with either the:base64
or:hex
encoding scheme.
Examples
BSV.Crypto.ECDSA.sign("hello world", private_key, encoding: :base64)
<< signature >>
Verify the given message and signature, using the given public key.
Options
The accepted options are:
:encoding
- Optionally decode the given signature with either the:base64
or:hex
encoding scheme.:named_curve
- Specific the elliptic curve name. Defaults to:secp256k1
.
Examples
BSV.Crypto.ECDSA.verify(signature, message, public_key)
true