algo

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrHashUnavailable = errors.New("hash function not available")
View Source
var ErrInvalidKeyType = errors.New("invalid key type")
View Source
var ErrInvalidSignature = errors.New("invalid signature")
View Source
var ErrKeyMustBePEMEncoded = errors.New("key must be PEM encoded")

Functions

func Base64ToKey

func Base64ToKey(base64Key string) ([]byte, error)

func DecodeSecret

func DecodeSecret(secret string) ([]byte, error)

func EncodeSecret

func EncodeSecret(secret []byte) string

func GenerateSecret

func GenerateSecret() []byte

func GetSignAlgorithmNames

func GetSignAlgorithmNames() []string

func HashSecret

func HashSecret(secret []byte) []byte

func KeyToBase64

func KeyToBase64(key []byte) string

func PemToKey

func PemToKey(pemBytes []byte) ([]byte, error)

func PrivateKeyToPem

func PrivateKeyToPem(pk []byte, out io.Writer)

func PublicKeyToPem

func PublicKeyToPem(pk []byte, out io.Writer)

func RegisterSignAlgorithm

func RegisterSignAlgorithm(alg SignAlgorithm)

Types

type DerKeys

type DerKeys struct {
	// PKIX binary format
	Public []byte
	// PKCS8 binary format
	Private []byte
}

type SignAlgorithm

type SignAlgorithm interface {
	Name() string
	/*
	  Generate keypair in DER format.
	*/
	Generate() (DerKeys, error)
	/*
		  Validate data signature.
			publicKey should be in PKIX DER format
			signature should be in binary format
			Return null if signature is valid, error otherwise.
	*/
	ValidateSignature(publicKey []byte, signature []byte, data []byte) error
	/*
	  Sign the data. Private key should be in PKCS8 DER format.
	*/
	Sign(privateKey []byte, data []byte) ([]byte, error)
}

func GetSignAlgorithm

func GetSignAlgorithm(name string) SignAlgorithm

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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