keys

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package keys implements a unified interface for key handling.

The key types crypto/ecdsa, crypto/ed25519, crypto/rsa are supported.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrivatesEqual

func PrivatesEqual(privateKey1 crypto.PrivateKey, privateKey2 crypto.PrivateKey) bool

PrivatesEqual checks whether the two given private keys are equal.

func PublicFromPrivate

func PublicFromPrivate(privateKey crypto.PrivateKey) crypto.PublicKey

PublicFromPrivate gets the public key associated with the given private key.

func PublicsEqual

func PublicsEqual(publicKey1 crypto.PublicKey, publicKey2 crypto.PublicKey) bool

PublicsEqual checks whether the two given public keys are equal.

Types

type Algorithm

type Algorithm uint
const (
	UnknownAlgorithm Algorithm = 0
	RSA2048          Algorithm = 1 // RSA cipher 2048 bit key lenght
	RSA3072          Algorithm = 2 // RSA cipher 3072 bit key lenght
	RSA4096          Algorithm = 3 // RSA cipher 4096 bit key lenght
	RSA8192          Algorithm = 4 // RSA cipher 8192 bit key lenght
	ECDSA224         Algorithm = 5 // ECDSA cipher P-224 curve
	ECDSA256         Algorithm = 6 // ECDSA cipher P-256 curve
	ECDSA384         Algorithm = 7 // ECDSA cipher P-384 curve
	ECDSA521         Algorithm = 8 // ECDSA cipher P-521 curve
	ED25519          Algorithm = 9 // ED25519 cipher
)

func AlgorithmFromKey added in v0.0.3

func AlgorithmFromKey(publicKey crypto.PublicKey) (Algorithm, error)

AlgorithmFromKey determines the algorithm of the given public key.

func AlgorithmFromString added in v0.0.2

func AlgorithmFromString(name string) (Algorithm, error)

AlgorithmFromString determines an algorithm from its name.

func Algs

func Algs() []Algorithm

Algs returns the known algorithms.

func (Algorithm) NewKeyPairFactory

func (alg Algorithm) NewKeyPairFactory() KeyPairFactory

NewKeyPairFactory gets the KeyPairFactory for the given algorithm.

func (Algorithm) String added in v0.0.2

func (algorithm Algorithm) String() string

String gets the algorithm's name.

type Key

type Key interface {
	crypto.Signer
	Verify(signature []byte, digest []byte, opts crypto.SignerOpts) bool
}

Key interface provides a unified way to key related serivces like crypto.Signer.

func KeyFromPrivate

func KeyFromPrivate(privateKey crypto.PrivateKey) Key

KeyFromPrivate wraps the given private key into a Key interface.

type KeyPair

type KeyPair interface {
	// Name returns this [KeyPair]'s algorithm.
	Alg() Algorithm
	// Private returns the private key of a key pair.
	Private() crypto.PrivateKey
	// Public returns the public key of a key pair.
	Public() crypto.PublicKey
}

KeyPair interface provides unified access to a key pair.

type KeyPairFactory

type KeyPairFactory interface {
	// Name returns this [KeyPairFactory]'s algorithm.
	Alg() Algorithm
	// New generates a new key pair.
	New() (KeyPair, error)
}

KeyPairFactory interface provides a unified way to create key pairs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL