crypto

package
v0.38.1 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: Apache-2.0 Imports: 15 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 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(key []byte) (*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 []byte) (*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(key []byte) (*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 []byte) (*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