keys

package
v3.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RS256 represents a RSA key with SHA-256 signing method
	RS256 string = "RS256"
	// RS384 represents a RSA key with SHA-384 signing method
	RS384 string = "RS384"
	// RS512 represents a RSA key with SHA-512 signing method
	RS512 string = "RS512"
	// PS256 represents a RSA-PSS key with SHA-256 signing method
	PS256 string = "PS256"
	// PS384 represents a RSA-PSS key with SHA-384 signing method
	PS384 string = "PS384"
	// PS512 represents a RSA-PSS key with SHA-512 signing method
	PS512 string = "PS512"
	// ES256 represents an Elliptic Curve with SHA-256 signing method
	ES256 string = "ES256"
	// ES384 represents an Elliptic Curve with SHA-384 signing method
	ES384 string = "ES384"
	// ES512 represents an Elliptic Curve with SHA-512 signing method
	ES512 string = "ES512"
	// EdDSA represents an Edwards Curve signing method
	EdDSA string = "EdDSA"

	// KeyTypeRSA represents the RSA key type
	KeyTypeRSA string = "RSA"
	// KeyTypeEC represents the EC key type
	KeyTypeEC string = "EC"
	// KeyTypeEdDSA represents the EdDSA key type
	KeyTypeEdDSA string = "EdDSA"
)

Variables

This section is empty.

Functions

func NewAsymmetricKeyPair

func NewAsymmetricKeyPair(alg string, bits int) (*PrivKey, *PubKey, error)

NewAsymmetricKeyPair returns a new keypair for the type of the given algorithm

bits is only used when generating RSA keys

Types

type PrivKey

type PrivKey struct {
	Key    interface{} `json:"-" bson:"-"`
	KeyPem string      `json:"key_pem" bson:"key_pem" validate:"required"`
	Alg    string      `json:"alg" bson:"alg" validate:"required"`
	PubKey *PubKey     `json:"-" bson:"-"`
}

PrivKey represents a private key object including the key and related metadata

func NewPrivKey

func NewPrivKey(alg string, keyPEM string) (*PrivKey, error)

NewPrivKey creates a new PrivKey with the provided algorithm and PEM

func (*PrivKey) ComputePubKey

func (p *PrivKey) ComputePubKey() error

ComputePubKey computes and sets the public key representation corresponding to the private key

func (*PrivKey) Decode

func (p *PrivKey) Decode() error

Decode sets the "Key" by decoding "KeyPem"

func (*PrivKey) Decrypt

func (p *PrivKey) Decrypt(data []byte, label []byte) (string, error)

Decrypt decrypts data using "key"

func (*PrivKey) Encode

func (p *PrivKey) Encode() error

Encode sets the "KeyPem" by encoding "Key" in PEM form

func (*PrivKey) Equal

func (p *PrivKey) Equal(other *PrivKey) bool

Equal determines whether the privkey is equivalent to other

func (*PrivKey) Sign

func (p *PrivKey) Sign(message []byte) (string, error)

Sign uses "key" to sign message

type PubKey

type PubKey struct {
	Key    interface{} `json:"-" bson:"-"`
	KeyPem string      `json:"key_pem" bson:"key_pem" validate:"required"`
	Alg    string      `json:"alg" bson:"alg" validate:"required"`
	KeyID  string      `json:"-" bson:"-"`
}

PubKey represents a public key object including the key and related metadata

func NewPubKey

func NewPubKey(alg string, keyPEM string) (*PubKey, error)

NewPubKey creates a new PubKey with the provided algorithm and PEM

func (*PubKey) ComputeKeyFingerprint

func (p *PubKey) ComputeKeyFingerprint() error

ComputeKeyFingerprint computes and sets the "KeyID"

func (*PubKey) Decode

func (p *PubKey) Decode() error

Decode sets the "Key" by decoding "KeyPem" and sets the "KeyID"

func (*PubKey) Encode

func (p *PubKey) Encode() error

Encode sets the "KeyPem" by encoding "Key" in PEM form and sets the "KeyID"

func (*PubKey) Encrypt

func (p *PubKey) Encrypt(data []byte, label []byte) ([]byte, error)

Encrypt uses "Key" to encrypt data

func (*PubKey) Equal

func (p *PubKey) Equal(other *PubKey) bool

Equal determines whether the pubkey is equivalent to other

func (*PubKey) Verify

func (p *PubKey) Verify(message []byte, signature string) error

Verify verifies that signature matches message by using "Key"

Jump to

Keyboard shortcuts

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