ezcrypt

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2021 License: MIT Imports: 15 Imported by: 0

README

ezcrypt

GitHub Workflow Status godoc GitHub codecov

Golang Easy Cryptography

Installation

go get github.com/anantadwi13/ezcrypt

Documentation

Index

Constants

View Source
const (
	AESKey128 = AESKeySize(16)
	AESKey192 = AESKeySize(24)
	AESKey256 = AESKeySize(32)
)
View Source
const (
	RSAKey2048 = RSAKeySize(2048)
	RSAKey4096 = RSAKeySize(4096)
)

Variables

This section is empty.

Functions

func SetBase64Encoder

func SetBase64Encoder(encoder *base64.Encoding) error

func SetRandomReader

func SetRandomReader(reader io.Reader) error

Types

type AES added in v0.0.2

type AES interface {
	SymmetricEncryption
}

func AesCBC added in v0.0.2

func AesCBC(key AESKey) (AES, error)

func AesCBCWithPKCS5Padding added in v0.0.3

func AesCBCWithPKCS5Padding(key AESKey) (AES, error)

func AesCFB added in v0.0.2

func AesCFB(key AESKey) (AES, error)

func AesGCM added in v0.0.4

func AesGCM(key AESKey, additionalData []byte) (AES, error)

AesGCM return AES with Galois Counter Mode instance. It is using 12 bytes nonce and 16 bytes tag. additionalData is an optional parameter (used for authentication purpose). It can be nil or any size slice.

AesGCM.Encrypt will return bytes of base64encode(Nonce+CipherText+Tag). AesGCM.Decrypt requires bytes of base64encode(Nonce+CipherText+Tag) parameter.

type AESKey added in v0.0.2

type AESKey Key

func AesGenerateRandomKey added in v0.0.2

func AesGenerateRandomKey(keySize AESKeySize) AESKey

func AesLoadEncodedKey added in v0.0.2

func AesLoadEncodedKey(encodedKey []byte) (AESKey, error)

AesLoadEncodedKey loads encoded base64 key into AESKey

func (AESKey) Encode added in v0.0.2

func (a AESKey) Encode() ([]byte, error)

type AESKeySize added in v0.0.2

type AESKeySize int

type AsymmetricEncryption

type AsymmetricEncryption interface {
	EncryptWithPublicKey(message []byte) ([]byte, error)
	DecryptWithPrivateKey(cipher []byte) ([]byte, error)
	KeyPair() KeyPair
}

type Key added in v0.0.2

type Key []byte

type KeyPair

type KeyPair interface {
	Public() interface{}
	Private() interface{}
	EncodedPublic() ([]byte, error)
	EncodedPrivate() ([]byte, error)
}

type RSA

type RSA interface {
	AsymmetricEncryption
}

func RsaOAEPWithSHA256

func RsaOAEPWithSHA256(keyPair RSAKeyPair) (RSA, error)

func RsaOAEPWithSHA512

func RsaOAEPWithSHA512(keyPair RSAKeyPair) (RSA, error)

type RSAKeyPair

type RSAKeyPair interface {
	KeyPair
	PublicRsa() *rsa.PublicKey
	PrivateRsa() *rsa.PrivateKey
}

func RsaGenerateKeyPair

func RsaGenerateKeyPair(bits RSAKeySize) (RSAKeyPair, error)

func RsaLoadEncodedKeyPair

func RsaLoadEncodedKeyPair(privateKey []byte) (RSAKeyPair, error)

RsaLoadEncodedKeyPair loads base64 encoded privateKey into RSAKeyPair. It will create RSAKeyPair instance with private and public keys loaded.

func RsaLoadEncodedPublicKey added in v0.0.2

func RsaLoadEncodedPublicKey(publicKey []byte) (RSAKeyPair, error)

RsaLoadEncodedPublicKey loads base64 encoded publicKey only into RSAKeyPair. It will create RSAKeyPair instance without a private key.

**NOTE** This RSAKeyPair is used for encryption only.

type RSAKeySize

type RSAKeySize int

type SymmetricEncryption added in v0.0.2

type SymmetricEncryption interface {
	Encrypt(message []byte) ([]byte, error)
	Decrypt(cipher []byte) ([]byte, error)
	Key() Key
}

Directories

Path Synopsis
example
aes
rsa

Jump to

Keyboard shortcuts

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