wzlib_crypto

package
v0.0.0-...-2af49ae Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: MIT Imports: 23 Imported by: 3

Documentation

Index

Constants

View Source
const (
	RSA_PEM_PUBKEY  = "public.pem"
	RSA_PEM_PRIVKEY = "private.pem"
	RSA_BIN_PUBKEY  = "public.key"
	RSA_BIN_PRIVKEY = "private.key"
)
View Source
const AES_TOKEN = "token.aes"

Variables

This section is empty.

Functions

This section is empty.

Types

type WzAES

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

func NewWzAES

func NewWzAES() *WzAES

func (*WzAES) Decrypt

func (wa *WzAES) Decrypt(ciphertext []byte) ([]byte, error)

Decrypt decrypts data using 256-bit AES-GCM. This both hides the content of the data and provides a check that it hasn't been altered. Expects input form nonce|ciphertext|tag where '|' indicates concatenation.

func (*WzAES) Encrypt

func (wa *WzAES) Encrypt(plaintext []byte) ([]byte, error)

Encrypt encrypts data using 256-bit AES-GCM. This both hides the content of the data and provides a check that it hasn't been altered. Output takes the form nonce|ciphertext|tag where '|' indicates concatenation.

func (*WzAES) GenerateKey

func (wa *WzAES) GenerateKey(pkiDir string) error

GenerateKey generates a random 256-bit key

func (*WzAES) IsLoaded

func (wa *WzAES) IsLoaded() bool

IsLoaded returns true if key is already loaded.

func (*WzAES) LoadKey

func (wa *WzAES) LoadKey(pkiDir string) error

LoadKey loads AES token from the pki directory.

type WzCryptoBundle

type WzCryptoBundle struct {
	wzlib_logger.WzLogger
	// contains filtered or unexported fields
}

WzClientCrypto class for all RSA/AES operations

func NewWzCryptoBundle

func NewWzCryptoBundle() *WzCryptoBundle

func (*WzCryptoBundle) GetAES

func (wcb *WzCryptoBundle) GetAES() *WzAES

GetAES token API

func (*WzCryptoBundle) GetRSA

func (wcb *WzCryptoBundle) GetRSA() *WzRSA

GetRSA keypair API

func (*WzCryptoBundle) GetUtils

func (wcb *WzCryptoBundle) GetUtils() *WzCryptoUtils

GetUtils returns crypto utils

func (*WzCryptoBundle) InitPkiDir

func (wcb *WzCryptoBundle) InitPkiDir(pkiDir string) (bool, bool)

InitPkiDir initialises the PKI directory with RSA keypair and AES token. Returns bool/bool, equivalent to rsa/aes accordingly.

func (*WzCryptoBundle) SignMessage

func (wcb *WzCryptoBundle) SignMessage(msg *wzlib_transport.WzGenericMessage) ([]byte, error)

SignMessage signs all message content, return serialised byte array

func (*WzCryptoBundle) VerifyMessageSignature

func (wcb *WzCryptoBundle) VerifyMessageSignature(keypem []byte, msg *wzlib_transport.WzGenericMessage) bool

VerifyMessageSignature from RSA PEM key

type WzCryptoUtils

type WzCryptoUtils struct {
	wzlib_logger.WzLogger
}

func NewWzCryptoUtils

func NewWzCryptoUtils() *WzCryptoUtils

func (*WzCryptoUtils) PEMKeyFingerprintFromBytes

func (wcu *WzCryptoUtils) PEMKeyFingerprintFromBytes(key []byte) string

PEMKeyFingerprintFromBytes reads PEM key from an array of bytes and returns SHA256 fingerprint.

func (*WzCryptoUtils) PEMKeyFingerprintFromFile

func (wcu *WzCryptoUtils) PEMKeyFingerprintFromFile(keypath string) string

PEMKeyFingerprintFromFile reads PEM key from a file and returns SHA256 fingerprint

func (*WzCryptoUtils) PEMKeyFingerprintFromString

func (wcu *WzCryptoUtils) PEMKeyFingerprintFromString(key string) string

PEMKeyFingerprintFromString reads PEM key from a string and returns SHA256 fingerprint

type WzRSA

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

func NewWzRSA

func NewWzRSA() *WzRSA

NewWzRSA creates an instance of a class that takes care of keypair management operations (generation, rotation, encrytion etc).

func (*WzRSA) Decrypt

func (wk *WzRSA) Decrypt(cipher []byte) ([]byte, error)

Decrypt decrypts data with private key

func (*WzRSA) Encrypt

func (wk *WzRSA) Encrypt(msg []byte) ([]byte, error)

Encrypt encrypts data with public key

func (*WzRSA) GenerateKeyPair

func (wk *WzRSA) GenerateKeyPair(pkiDir string) error

GenerateKeyPair generates all public and private keys in PEM and Gob formats.

func (*WzRSA) GetPubFp

func (wk *WzRSA) GetPubFp() string

GetPubFp returns a fingerprint of public key

func (*WzRSA) GetPublicPEMKey

func (wk *WzRSA) GetPublicPEMKey(pkiDir string) (pem []byte, err error)

Read PEM version of the public RSA key and return it as an array of bytes

func (*WzRSA) LoadPEMKeyPair

func (wk *WzRSA) LoadPEMKeyPair(pkiDir string) error

LoadPEMKeyPair loads previously generated pub/priv keys

func (*WzRSA) Sign

func (wk *WzRSA) Sign(data []byte) ([]byte, error)

Sign a specific content with the RSA private key

func (*WzRSA) VerifyPem

func (wk *WzRSA) VerifyPem(pubkey []byte, data []byte, signature []byte) (bool, error)

VerifyPerm a specific signed content with the RSA public key in PEM format

Jump to

Keyboard shortcuts

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