crypto

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DefauleRSAKeySize = 2048

Variables

This section is empty.

Functions

func GenerateRSAPems

func GenerateRSAPems(size int) (private, public []byte, err error)

GenerateRSAPems generates RSA key pair and the PEM encoding of them.

func LoadRSAPrivateKey

func LoadRSAPrivateKey(path string) (*rsa.PrivateKey, error)

func LoadRSAPublicKey

func LoadRSAPublicKey(path string) (*rsa.PublicKey, error)

func ParseRSAPrivateKeyFromPem

func ParseRSAPrivateKeyFromPem(data []byte) (*rsa.PrivateKey, error)

func ParseRSAPublicKeyFromPem

func ParseRSAPublicKeyFromPem(data []byte) (*rsa.PublicKey, error)

Types

type AESEncryptDecrypter

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

func NewAESEncryptDecrypter

func NewAESEncryptDecrypter(keyFile string) (*AESEncryptDecrypter, error)

NewAESEncryptDecrypter reads the specified key file and returns an AES EncryptDecrypter.

func (*AESEncryptDecrypter) Decrypt

func (a *AESEncryptDecrypter) Decrypt(encryptedText string) (string, error)

func (*AESEncryptDecrypter) Encrypt

func (a *AESEncryptDecrypter) Encrypt(text string) (string, error)

type Decrypter

type Decrypter interface {
	Decrypt(encryptedText string) (string, error)
}

type EncryptDecrypter

type EncryptDecrypter interface {
	Encrypter
	Decrypter
}

type Encrypter

type Encrypter interface {
	Encrypt(text string) (string, error)
}

type HybridDecrypter

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

func NewHybridDecrypter

func NewHybridDecrypter(keyFile string) (*HybridDecrypter, error)

func (*HybridDecrypter) Decrypt

func (d *HybridDecrypter) Decrypt(encryptedText string) (string, error)

Decrypt performs a regular AES-GCM + RSA-OAEP decryption.

The implementation of this function was brought from well known Bitnami's SealedSecret library. https://github.com/bitnami-labs/sealed-secrets/blob/master/pkg/crypto/crypto.go#L86

type HybridEncrypter

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

HybridEncrypter uses RSA to encrypt a randomly generated key for a symmetric AES-GCM. RSA is able to encrypt only a very limited amount of data. In order to encrypt reasonable amounts of data a hybrid scheme is commonly used.

func NewHybridEncrypter

func NewHybridEncrypter(key string) (*HybridEncrypter, error)

func (*HybridEncrypter) Encrypt

func (e *HybridEncrypter) Encrypt(text string) (string, error)

Encrypt performs a regular AES-GCM + RSA-OAEP encryption. The output string is:

RSA ciphertext length || RSA ciphertext || AES ciphertext

The implementation of this function was brought from well known Bitnami's SealedSecret library. https://github.com/bitnami-labs/sealed-secrets/blob/master/pkg/crypto/crypto.go#L35

type RSADecrypter

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

func NewRSADecrypter

func NewRSADecrypter(keyFile string) (*RSADecrypter, error)

func (*RSADecrypter) Decrypt

func (d *RSADecrypter) Decrypt(encryptedText string) (string, error)

type RSAEncrypter

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

func NewRSAEncrypter

func NewRSAEncrypter(key string) (*RSAEncrypter, error)

func (*RSAEncrypter) Encrypt

func (e *RSAEncrypter) Encrypt(text string) (string, error)

Jump to

Keyboard shortcuts

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