Sovite.DKIM.SigningKey (sovite v0.6.0)

Copy Markdown View Source

A private key to sign with, for one domain and selector, and the key record to publish for it.

{:ok, key} = Sovite.DKIM.SigningKey.from_pem(File.read!(path), "example.com", "s2026")
Sovite.DKIM.SigningKey.dns_name(key)    #=> "s2026._domainkey.example.com"
Sovite.DKIM.SigningKey.dns_record(key)  #=> "v=DKIM1; k=rsa; p=MIIBIjANBg..."

Keys are PEM files, as openssl genpkey writes them or generate/2 returns: PKCS#8 (PRIVATE KEY), or for RSA also PKCS#1 (RSA PRIVATE KEY). RSA keys must have at least 1024 bits; 2048 is the usual size (RFC 8301 §3.2).

Summary

Functions

The a= tag value.

The DNS name the key record goes at.

The key record (RFC 6376 §3.6.1) to publish at dns_name/1.

Loads a private key from PEM data.

Generates a new private key as PKCS#8 PEM: :rsa with bits (2048 by default) or :ed25519.

Signs data. For Ed25519 the SHA-256 hash of the data is signed (RFC 8463 §3).

Types

t()

@type t() :: %Sovite.DKIM.SigningKey{
  algorithm: :rsa_sha256 | :ed25519_sha256,
  domain: String.t(),
  private: tuple() | binary(),
  public: tuple() | binary(),
  selector: String.t()
}

Functions

algorithm_name(signing_key)

@spec algorithm_name(t()) :: String.t()

The a= tag value.

dns_name(key)

@spec dns_name(t()) :: String.t()

The DNS name the key record goes at.

dns_record(signing_key)

@spec dns_record(t()) :: String.t()

The key record (RFC 6376 §3.6.1) to publish at dns_name/1.

from_pem(pem, domain, selector)

@spec from_pem(binary(), String.t(), String.t()) :: {:ok, t()} | {:error, String.t()}

Loads a private key from PEM data.

generate(type, bits \\ 2048)

@spec generate(:rsa | :ed25519, pos_integer()) :: binary()

Generates a new private key as PKCS#8 PEM: :rsa with bits (2048 by default) or :ed25519.

sign(signing_key, data)

@spec sign(t(), iodata()) :: binary()

Signs data. For Ed25519 the SHA-256 hash of the data is signed (RFC 8463 §3).