rsa_keys

Simple and easy set of functions to generate rsa keys, sign a message and verify it, targeting erlang.

Funções simples e fáceis para gerar chaves rsa, assinar uma mensagem e verificála, usando erlang.

Types

pub type PrivateKey {
  PrivateKey(der: BitArray, pem: String)
}

Constructors

  • PrivateKey(der: BitArray, pem: String)
pub type PublicKey {
  PublicKey(der: BitArray, pem: String)
}

Constructors

  • PublicKey(der: BitArray, pem: String)

Functions

pub fn generate_rsa_keys() -> #(PublicKey, PrivateKey)

Generate public and private RSA key pairs.

The pem records are PEM encoded and thus human readable.

pub fn sign_message(
  message msg: BitArray,
  private_key prvtkey: PrivateKey,
) -> Result(BitArray, String)

Hash a message using sha256 and sign it using a private key.

The returned signature can then be base16 encoded for readability.

pub fn verify_message(
  message msg: BitArray,
  public_key public_key: PublicKey,
  signature signature: BitArray,
) -> Result(Bool, String)

verify a message against its sha256 hash and signature using a public key.

returns a Ok(True) for valid signature

returns a Ok(False) for invalid signature

returns an Error for runtime issues.

Search Document