crypt

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2020 License: AGPL-3.0 Imports: 31 Imported by: 5

Documentation

Index

Constants

View Source
const (
	AESGCMNonceSize = 12
)
View Source
const (
	// PBKDF2Iterations set to 10 000 which is the acceptable number of pbkdf2 iterations for year 2020
	PBKDF2Iterations = 10000
)

Variables

This section is empty.

Functions

func AESGCMDecrypt

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

func AESGCMDecryptWithNonce

func AESGCMDecryptWithNonce(key, nonce, data []byte) ([]byte, error)

func AESGCMEncrypt

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

func AESGCMEncryptWithSalt

func AESGCMEncryptWithSalt(key, salt, data []byte) ([]byte, error)

func GenerateCACertificate

func GenerateCACertificate(t *CertificateTemplate) (*x509.Certificate, error)

GenerateCACertificate generates a certificate for a CA

func GenerateServiceCertificate

func GenerateServiceCertificate(t *CertificateTemplate) (*x509.Certificate, error)

GenerateServiceCertificate generates a certificate for a service

func GenerateVerificationCode

func GenerateVerificationCode(max int) (string, error)

func LoadCertificate

func LoadCertificate(file string) (*x509.Certificate, error)

LoadCertificate load file and decode it into a x509.Certificate

func LoadPrivateKey

func LoadPrivateKey(password []byte, file string) (crypto.PrivateKey, error)

LoadPrivateKey load encrypted private key from "file" and decrypts it

func NewPassword

func NewPassword(length int) string

func PEMDecodeCertificate

func PEMDecodeCertificate(pemBytes []byte) (*x509.Certificate, error)

PEMDecodeCertificate creates certificate from pem bytes

func PEMDecodePublicKey

func PEMDecodePublicKey(pemBytes []byte) (interface{}, string, error)

func PEMEncodeCertificate

func PEMEncodeCertificate(cert *x509.Certificate) ([]byte, error)

PEMEncodeCertificate encodes certificate chain into pem file

func PEMEncodeKey

func PEMEncodeKey(key crypto.PrivateKey) ([]byte, error)

func PEMEncodePublicKey

func PEMEncodePublicKey(k crypto.PublicKey) ([]byte, error)

func RandomCode

func RandomCode(max int) (string, error)

func Reveal

func Reveal(phrase string, info *Info) ([]byte, error)

Reveal decrypts info.Encrypted with a key built from phrase and info content.

func StoreCertificate

func StoreCertificate(cert *x509.Certificate, file string, perm os.FileMode) error

StoreCertificate encode certificate and store the result in "file"

func StorePrivateKey

func StorePrivateKey(key crypto.PrivateKey, password []byte, file string) error

StorePrivateKey encrypts the private key and save it in "file"

Types

type AESGCMDecryptWrapper

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

func NewDecryptWrapper

func NewDecryptWrapper(key []byte, opts ...ReadOption) *AESGCMDecryptWrapper

func (*AESGCMDecryptWrapper) Wrap

func (d *AESGCMDecryptWrapper) Wrap(reader io.Reader) io.Reader

type AESGCMEncryptWrapper

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

func NewEncryptWrapper

func NewEncryptWrapper(key []byte, opts ...ReadOption) *AESGCMEncryptWrapper

func (*AESGCMEncryptWrapper) WithOutputSize

func (d *AESGCMEncryptWrapper) WithOutputSize(inputSize int64) int64

func (*AESGCMEncryptWrapper) Wrap

func (d *AESGCMEncryptWrapper) Wrap(reader io.Reader) io.Reader

type CertificateTemplate

type CertificateTemplate struct {
	Organization      string
	Name              string
	Domains           []string
	IPs               []net.IP
	Expiry            time.Duration
	PublicKey         crypto.PublicKey
	SignerPrivateKey  crypto.PrivateKey
	SignerCertificate *x509.Certificate
}

CertificateTemplate specs for generating a certificate

type Info

type Info struct {
	Iterations   int    `json:"iterations"`
	Salt         string `json:"salt"`
	Length       int    `json:"length"`
	Hash         string `json:"hash"`
	Alg          string `json:"alg"`
	EncryptedKey string `json:"encrypted_key"`
}

Info about encrypted key parameter

func Generate

func Generate(phrase string, length int) ([]byte, *Info, error)

Generate generates random password of size length. Then encrypted with a key derived from password using pbkdf2. The derivation parameters are put in an Info object

type ReadOption

type ReadOption func(*readOptions)

func WithBlockSize

func WithBlockSize(size int64) ReadOption

func WithLimit

func WithLimit(limit int64) ReadOption

func WithOffset

func WithOffset(offset int64) ReadOption

type ReaderWrapper

type ReaderWrapper interface {
	Wrap(reader io.Reader) io.Reader
}

type WriterWrapper

type WriterWrapper interface {
	Wrap(writer io.Writer) io.Writer
}

Jump to

Keyboard shortcuts

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