keys

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: AGPL-3.0 Imports: 15 Imported by: 6

Documentation

Index

Constants

View Source
const AesGcm = "AES_GCM"

AesGcm represents AES with the block cipher mode GCM

View Source
const AesKeyBitLength = 256

AesKeyBitLength is the used aes key length

View Source
const MaxRSAEncryptionLength = 64

MaxRSAEncryptionLength defines the max length of values which will be encrypted with RSA instead of hybrid encryption

View Source
const NonceBitLength = 96

NonceBitLength is the used nonce length

Variables

View Source
var KeyProviders []string

KeyProviders contains the list of implemented key providers and is dynamically filled by the providers in keys package.

Functions

This section is empty.

Types

type Decrypter

type Decrypter func(rand io.Reader, priv *rsa.PrivateKey, ciphertext []byte) ([]byte, error)

Decrypter decrypts a given reader stream with a given public key. This method may be exported into a library and must not be unexported.

type Encrypter

type Encrypter func(random io.Reader, pub *rsa.PublicKey, msg []byte) ([]byte, error)

Encrypter encrypts a given reader stream with a given public key. This method may be exported into a library and must not be unexported.

type Encryption

type Encryption struct {
	Type  string `json:"type"`
	Key   string `json:"key"`
	Nonce string `json:"nonce"`
}

Encryption contains the type, used key and the nonce (needed for AES GCM)

type HybridEncryptionValue

type HybridEncryptionValue struct {
	Encryption Encryption `json:"encryption"`
	Value      string     `json:"value"`
}

HybridEncryptionValue contains an encrypted value and information about the encryption

func NewHybridEncryptionValue

func NewHybridEncryptionValue(encryptionAlgorithm string, encryptedKey string, nonce []byte, encryptedValue []byte) HybridEncryptionValue

NewHybridEncryptionValue returns a new HybridEncryptionValue object for the given parameters

type Key

type Key interface {
	// AsString returns the key as pem formatted string
	AsString() (string, error)
	// AsBytes returns the key as pem formatted byte array
	AsBytes() ([]byte, error)
	// ToFile writes the key to disk in pem format
	ToFile(path string) error
}

Key interface defines the common functions of a key

type KeyPair

type KeyPair struct {
	// contains filtered or unexported fields
}

KeyPair represents a public/private key pair

func (*KeyPair) Private

func (kp *KeyPair) Private() *PrivateKey

Private returns the private key

func (*KeyPair) Public

func (kp *KeyPair) Public() *PublicKey

Public returns the public key

type KeyProvider

type KeyProvider struct {
	Encrypter Encrypter
	Decrypter Decrypter
}

KeyProvider provides functions for en- and decryption. This method may be exported into a library and must not be unexported.

func NewKeyProvider

func NewKeyProvider(keyType string) (*KeyProvider, error)

NewKeyProvider creates a new KeyProvider. This method may be exported into a library and must not be unexported.

func (*KeyProvider) FromPrivateKey

func (provider *KeyProvider) FromPrivateKey(privateKey []byte) (*KeyPair, error)

FromPrivateKey creates a key pair from the private key.

func (*KeyProvider) FromPrivateKeyPath

func (provider *KeyProvider) FromPrivateKeyPath(path string) (*KeyPair, error)

FromPrivateKeyPath reads the keypair from the private key file path.

func (*KeyProvider) Generate

func (provider *KeyProvider) Generate() (*KeyPair, error)

Generate creates a new public/private key.

func (*KeyProvider) ReadPublicKey

func (provider *KeyProvider) ReadPublicKey(publicKey []byte) (*PublicKey, error)

ReadPublicKey reads a public key from an byte array.

func (*KeyProvider) ReadPublicKeyFromString

func (provider *KeyProvider) ReadPublicKeyFromString(publicKeyString string) (*PublicKey, error)

ReadPublicKeyFromString reads a public key from its string representation.

type PrivateKey

type PrivateKey struct {
	// contains filtered or unexported fields
}

func (*PrivateKey) AsBytes

func (pk *PrivateKey) AsBytes() ([]byte, error)

AsBytes returns the key as pem formatted byte array.

func (*PrivateKey) AsString

func (pk *PrivateKey) AsString() (string, error)

AsString returns the key as pem formatted string.

func (*PrivateKey) Decrypt

func (pk *PrivateKey) Decrypt(input string) (string, error)

Decrypt decrypts a text which was encrypted with the Encrypt function of the Public key of the same key pair. In cases where the input is a meta value, we have to decrypt the symmetric key and use it for decrypting the real value.

func (*PrivateKey) ToFile

func (pk *PrivateKey) ToFile(path string) error

ToFile writes the key to disk in pem format.

type PublicKey

type PublicKey struct {
	// contains filtered or unexported fields
}

PublicKey is the public key part of the KeyPair.

func (*PublicKey) AsBytes

func (pk *PublicKey) AsBytes() ([]byte, error)

AsBytes returns the key as pem formatted byte array.

func (*PublicKey) AsString

func (pk *PublicKey) AsString() (string, error)

AsString returns the key as pem formatted string.

func (*PublicKey) Encrypt

func (pk *PublicKey) Encrypt(input string) (string, error)

Encrypt encrypts the given input. In cases where the input can not be encrypted with RSA because it is too long, we switch to a hybrid encryption (i. e. using symmetric crypto for the actual content via a randomly generated key which in turn is encrypted with RSA).

func (*PublicKey) ToFile

func (pk *PublicKey) ToFile(path string) error

ToFile writes the key to disk in pem format.

Jump to

Keyboard shortcuts

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