Kryptonite v0.1.4 Kryptonite.RSA.PrivateKey View Source

This module provides abstraction around Erlang’s :public_key functions that aim to manipulate private keys.

Most if not all of the functions in this module are meant to be easily compatible with elixir’s with construct, and therefore returns something that can always be pattern-matched for success (Typically a {:ok, value} tuple).

Link to this section Summary

Functions

Performs the decryption of a given message using the provided private key. The message has to be encrypted using the matching public key, or an error will be returned

Performs the encryption of a given message using the provided private key. Note that this function will rarelly be used, as the only way to decrypt the generated cypher would be using the public key, which isn’t usually the intended way of exchanging secure messages

Can be used when an Erlang native private key has to be converted in a format that this library will understand

This function is used to generate a new private key given a size_in_bits and a public_exponent, both of which have sane default values

Allows to extract the public components from a private key and return a Kryptonite.RSA.PublicKey.t() construct, which later can be used to perform various cryptographic operations such as decrypting cypher messages

Signs a given message using the provided private key

Most of this module’s function internally use Erlang’s native format when performing cryptographic operations; therefore this function is provided as a helper

Link to this section Types

Link to this type t() View Source
t() :: %Kryptonite.RSA.PrivateKey{
  ctr_coefficient: pos_integer(),
  exponent_one: pos_integer(),
  exponent_two: pos_integer(),
  other_prime_infos: atom(),
  prime_one: pos_integer(),
  prime_two: pos_integer(),
  private_exponent: pos_integer(),
  public_exponent: pos_integer(),
  public_modulus: pos_integer(),
  version: :"two-prime"
}

Link to this section Functions

Link to this function decrypt(key, cypher_bytes) View Source
decrypt(t(), Kryptonite.RSA.cypher()) ::
  {:ok, Kryptonite.RSA.message()} | {:error, any()}

Performs the decryption of a given message using the provided private key. The message has to be encrypted using the matching public key, or an error will be returned.

Link to this function encrypt(key, msg) View Source
encrypt(t(), Kryptonite.RSA.message()) ::
  {:ok, Kryptonite.RSA.cypher()} | {:error, any()}

Performs the encryption of a given message using the provided private key. Note that this function will rarelly be used, as the only way to decrypt the generated cypher would be using the public key, which isn’t usually the intended way of exchanging secure messages.

Link to this function from_native(arg1) View Source
from_native(native()) :: t() | {:error, any()}

Can be used when an Erlang native private key has to be converted in a format that this library will understand.

Link to this function new(size_in_bits \\ 1024, public_exponent \\ 65537) View Source
new(pos_integer(), pos_integer()) :: t() | {:error, any()}

This function is used to generate a new private key given a size_in_bits and a public_exponent, both of which have sane default values.

Link to this function public_key(arg1) View Source
public_key(t()) :: Kryptonite.RSA.PublicKey.t() | {:error, any()}

Allows to extract the public components from a private key and return a Kryptonite.RSA.PublicKey.t() construct, which later can be used to perform various cryptographic operations such as decrypting cypher messages.

Signs a given message using the provided private key.

Link to this function to_native(t) View Source
to_native(t()) :: native() | {:error, any()}

Most of this module’s function internally use Erlang’s native format when performing cryptographic operations; therefore this function is provided as a helper.