cryptoswitch

package
v0.0.0-...-bfe60c0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cipher

type Cipher int
const (
	AES Cipher = iota
	DES
	TripleDES
	RC5
	Blowfish
	Twofish
	Camellia
	RC4
	SEAL
)

type CryptoSwitch

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

func NewCryptoSwitch

func NewCryptoSwitch(cipher Cipher, mode Mode) *CryptoSwitch

func (*CryptoSwitch) Decrypt

func (cw *CryptoSwitch) Decrypt(privkey *PrivateKey, msg []byte) ([]byte, error)

Decrypt decrypts a passed message with a receiver private key, returns plaintext or decryption error

func (*CryptoSwitch) Encrypt

func (cw *CryptoSwitch) Encrypt(pubkey *PublicKey, msg []byte) ([]byte, error)

Encrypt encrypts a passed message with a receiver public key, returns ciphertext or encryption error

type Mode

type Mode int
const (
	CBC Mode = iota
	GCM
)

type PrivateKey

type PrivateKey struct {
	*PublicKey
	D *big.Int
}

func GenerateKey

func GenerateKey() (*PrivateKey, error)

GenerateKey generates secp256k1 key pair

func (*PrivateKey) Encapsulate

func (k *PrivateKey) Encapsulate(pub *PublicKey) ([]byte, []byte, error)

Encapsulate encapsulates key by using Key Encapsulation Mechanism and returns symmetric key; can be safely used as encryption key

type PublicKey

type PublicKey struct {
	elliptic.Curve
	X, Y *big.Int
}

PublicKey instance with nested elliptic.Curve interface (secp256k1 instance in our case)

func (*PublicKey) Bytes

func (k *PublicKey) Bytes() []byte

Bytes returns public key raw bytes; Could be optionally compressed by dropping Y part

func (*PublicKey) Decapsulate

func (k *PublicKey) Decapsulate(priv *PrivateKey) ([]byte, []byte, error)

Decapsulate decapsulates key by using Key Encapsulation Mechanism and returns symmetric key; can be safely used as encryption key

Jump to

Keyboard shortcuts

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