starkbank_ecdsa v1.1.0 EllipticCurve.PrivateKey View Source

Used to create private keys or convert them between struct and .der or .pem formats. Also allows creations of public keys from private keys.

Functions:

  • generate()
  • toPem()
  • toDer()
  • fromPem()
  • fromPem!()
  • fromDer()
  • fromDer!()

Link to this section Summary

Functions

Holds private key data. Is usually extracted from .pem files.

Converts a private key in der format into decoded struct format

Converts a private key in der format into decoded struct format

Converts a private key in pem format into decoded struct format

Converts a private key in pem format into decoded struct format

Gets the public associated with a private key

Converts a private key in decoded struct format into a der string (raw binary)

Converts a private key in decoded struct format into a pem string

Link to this section Functions

Link to this function

%EllipticCurve.PrivateKey{}

View Source (struct)

Holds private key data. Is usually extracted from .pem files.

Parameters:

  • :secret [integer]: private key secret number;
  • :curve [%EllipticCurve.Curve]: private key curve information;

Converts a private key in der format into decoded struct format

Parameters:

  • der [string]: private key in der format

Returns {:ok, privateKey}:

  • privateKey [%EllipticCurve.PrivateKey]: decoded private key struct;

Example:

iex> EllipticCurve.PrivateKey.fromDer(<<48, 116, 2, 1, 1, 4, 32, 59, 210, 253, 23, 93, 23, ...>>)
{:ok, %EllipticCurve.PrivateKey{...}}

Converts a private key in der format into decoded struct format

Parameters:

  • der [string]: private key in der format

Returns:

  • privateKey [%EllipticCurve.PrivateKey]: decoded private key struct;

Example:

iex> EllipticCurve.PrivateKey.fromDer!(<<48, 116, 2, 1, 1, 4, 32, 59, 210, 253, 23, 93, 23, ...>>)
%EllipticCurve.PrivateKey{...}

Converts a private key in pem format into decoded struct format

Parameters:

  • pem [string]: private key in pem format

Returns {:ok, privateKey}:

  • privateKey [%EllipticCurve.PrivateKey]: decoded private key struct;

Example:

iex> EllipticCurve.PrivateKey.fromPem("-----BEGIN EC PRIVATE KEY-----

MHQCAQEEIDvS/RddF6iYa/q4oVSrGa3Kbd7aSooNpwhv9puJVv1loAcGBSuBBAAK oUQDQgAErp2I78X4cqHscCRWMT4rhouyO197iQXRfdGgsgfS/UGaIviYiqnG3SSa 9dsOHU/NkVSTLkBPCI0RQLF3554dZg== -----END EC PRIVATE KEY----- ")

{:ok, %EllipticCurve.PrivateKey{...}}

Converts a private key in pem format into decoded struct format

Parameters:

  • pem [string]: private key in pem format

Returns:

  • privateKey [%EllipticCurve.PrivateKey]: decoded private key struct;

Example:

iex> EllipticCurve.PrivateKey.fromPem!("-----BEGIN EC PRIVATE KEY-----

MHQCAQEEIDvS/RddF6iYa/q4oVSrGa3Kbd7aSooNpwhv9puJVv1loAcGBSuBBAAK oUQDQgAErp2I78X4cqHscCRWMT4rhouyO197iQXRfdGgsgfS/UGaIviYiqnG3SSa 9dsOHU/NkVSTLkBPCI0RQLF3554dZg== -----END EC PRIVATE KEY----- ")

%EllipticCurve.PrivateKey{...}
Link to this function

generate(secret \\ nil, curve \\ :secp256k1)

View Source

Creates a new private key

Parameters:

  • secret [integer]: private key secret; Default: nil -> random key will be generated;
  • curve [atom]: curve name; Default: :secp256k1;

Returns:

  • privateKey [%EllipticCurve.PrivateKey]: private key struct

Example:

iex> EllipticCurve.PrivateKey.generate()
%EllipticCurve.PrivateKey{...}
Link to this function

getPublicKey(privateKey)

View Source

Gets the public associated with a private key

Parameters:

  • privateKey [%EllipticCurve.PrivateKey]: private key struct

Returns:

  • publicKey [%EllipticCurve.PublicKey]: public key struct

Example:

iex> EllipticCurve.PrivateKey.getPublicKey(privateKey)
%EllipticCurve.PublicKey{...}

Converts a private key in decoded struct format into a der string (raw binary)

Parameters:

  • privateKey [$EllipticCurve.PrivateKey]: decoded private key struct;

Returns:

  • der [string]: private key in der format

Example:

iex> EllipticCurve.PrivateKey.toDer(%EllipticCurve.PrivateKey{...})
<<48, 116, 2, 1, 1, 4, 32, 59, 210, 253, 23, 93, 23, ...>>

Converts a private key in decoded struct format into a pem string

Parameters:

  • privateKey [%EllipticCurve.PrivateKey]: decoded private key struct;

Returns:

  • pem [string]: private key in pem format

Example:

iex> EllipticCurve.PrivateKey.toPem(%EllipticCurve.PrivateKey{...})
"-----BEGIN EC PRIVATE KEY-----

MHQCAQEEIDvS/RddF6iYa/q4oVSrGa3Kbd7aSooNpwhv9puJVv1loAcGBSuBBAAK oUQDQgAErp2I78X4cqHscCRWMT4rhouyO197iQXRfdGgsgfS/UGaIviYiqnG3SSa 9dsOHU/NkVSTLkBPCI0RQLF3554dZg== -----END EC PRIVATE KEY----- "