crypt

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AesGCMDecrypt

func AesGCMDecrypt(key []byte, data []byte) ([]byte, error)

AesGCMDecrypt decrypt with the given 32 byte key the given cipher. GCM Mode use a 96-bit nonce that was preadded to the cipher. This nonce must be uniq

func AesGCMEncrypt

func AesGCMEncrypt(key []byte, data []byte) ([]byte, error)

AesGCMEncrypt encrypt with the given 32 byte key the given data. The none will be preadded to the ciphertext

func ChaCha20Decrypt

func ChaCha20Decrypt(key, data []byte) ([]byte, error)

ChaCha20Decrypt decrypt the given data with given key. nonce was preadded to ciphertext

func ChaCha20Encrypt

func ChaCha20Encrypt(key, data []byte) ([]byte, error)

ChaCha20Encrypt encrypt the given data with given key nonce will be preadded to ciphertext key should be randomly generated or derived from a function like Argon2. XCHACHA20_NONCE_LENGTH = 24

func GenRandKey

func GenRandKey(size int) ([]byte, error)

GenRandKey generates a (size) 32 byte random key

func GeneratePrivateKey

func GeneratePrivateKey(size int) ([]byte, error)

GeneratePrivateKey a secure private key from a random source

func LoadPrivatePEMKey

func LoadPrivatePEMKey(fn io.Reader) (*rsa.PrivateKey, error)

LoadPrivatePEMKey load private pem key from file

func LoadPublicPEMKey

func LoadPublicPEMKey(fn io.Reader) (*rsa.PublicKey, error)

LoadPublicPEMKey load public pem key from file

func SaveGobKey

func SaveGobKey(fn io.Writer, key interface{}) error

SaveGobKey save rsa key as glob to file to decode the key use the correct struct and gob.NewDecoder(fn).Decode(k)

func SavePrivatePEMKey

func SavePrivatePEMKey(fn io.Writer, key *rsa.PrivateKey) error

SavePrivatePEMKey save private pem key to file

func SavePublicPEMKey

func SavePublicPEMKey(fn io.Writer, pubkey rsa.PublicKey) error

SavePublicPEMKey save public pem key to file

func SignPKCS1v15

func SignPKCS1v15(r io.Reader, key *rsa.PrivateKey) ([]byte, error)

SignPKCS1v15 sign with the in PKCS1v15 standard the given bytes with private key

func VerifyPKCS1v15

func VerifyPKCS1v15(r io.Reader, pubkey *rsa.PublicKey, sig []byte) error

VerifyPKCS1v15 check if the given signature is valid and use the PKCS1v15 standard

Types

type KeyPair

type KeyPair struct {
	Priv [32]byte
	Pub  [32]byte
}

KeyPair stores private and public 32 byte keys

func GenKeyX25519

func GenKeyX25519() (*KeyPair, error)

GenKeyX25519 return a KeyPair generated with X25519

type KeyPairRSA

type KeyPairRSA struct {
	Pub  *rsa.PublicKey
	Priv *rsa.PrivateKey
}

KeyPairRSA to hold rsa private and public key

func GenKeyRSA

func GenKeyRSA() (*KeyPairRSA, error)

GenKeyRSA generate a private public rsa key pair with a size of 4096

Jump to

Keyboard shortcuts

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