cryptox

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AES  = "AES"
	DES  = "DES"
	DES3 = "DES3"
)

Variables

View Source
var (
	ErrAesKeySize          = errors.New("key size must be 16, 24, or 32 bytes")
	ErrDesKeySize          = errors.New("key size must be 8")
	ErrAesNotSupportedGcm  = errors.New("aes-gcm not supported")
	ErrDesNotSupportedGcm  = errors.New("des-gcm not supported")
	ErrDes3NotSupportedGcm = errors.New("des3-gcm not supported")
)

Functions

func HmacSha256

func HmacSha256(data []byte, key string) string

func HmacSha256String

func HmacSha256String(data string, key string) string

func MD5

func MD5(data []byte) *encodex.Encode

MD5 returns the MD5 hash of the string

func NotAesValidKeySize

func NotAesValidKeySize(k KeySize) bool

func PadZeroKey

func PadZeroKey(key []byte, size int) []byte

func RSADecrypt

func RSADecrypt(src, priKey []byte) ([]byte, error)

RSADecrypt decrypts data.tmpl using RSA private key.

func RSAEncrypt

func RSAEncrypt(src, pubKey []byte) ([]byte, error)

RSAEncrypt encrypts data.tmpl with rsa public key

func RSAGenerateKey

func RSAGenerateKey(bits int, out io.Writer) error

RSAGenerateKey generates a new RSA key pair.

func RSAGeneratePublicKey

func RSAGeneratePublicKey(priKey []byte, out io.Writer) error

RSAGeneratePublicKey generates a public key from a private key

func RSASign

func RSASign(src []byte, priKey []byte, hash ...crypto.Hash) ([]byte, error)

RSASign signs the given data.tmpl using the given private key. The hash defaults to crypto.SHA256

func RSAVerify

func RSAVerify(src, sign, pubKey []byte, hash ...crypto.Hash) error

RSAVerify verifies the given data.tmpl using the given public key. The hash defaults to crypto.SHA256

func SHA1

func SHA1(data []byte) *encodex.Encode

SHA1 returns the SHA1 hash of the string

func SHA224

func SHA224(data []byte) *encodex.Encode

func SHA256

func SHA256(data []byte) *encodex.Encode

func SHA384

func SHA384(data []byte) *encodex.Encode

func SHA512

func SHA512(data []byte) *encodex.Encode

Types

type Crypto

type Crypto interface {
	Encrypt(plaintext []byte) (*encodex.Encode, error)
	Decrypt(ciphertext []byte) (plaintext []byte, err error)
}

func NewAES

func NewAES(fns ...OptionFn) (Crypto, error)

func NewDES

func NewDES(fns ...OptionFn) (Crypto, error)

func NewDES3

func NewDES3(fns ...OptionFn) (Crypto, error)

func NewRC4

func NewRC4(key []byte) (Crypto, error)

type KeySize

type KeySize int
const (
	KeySize128 KeySize = 16
	KeySize192 KeySize = 24
	KeySize256 KeySize = 32

	// KeySize64 is supported by Des, but not by AES.
	KeySize64 KeySize = 8
)

func (KeySize) Int

func (k KeySize) Int() int

func (KeySize) Not

func (k KeySize) Not(size KeySize) bool

type Method

type Method string

func (Method) Is

func (m Method) Is(m1 Method) bool

func (Method) String

func (m Method) String() string

type OptionFn

type OptionFn func(*options)

func WithIV

func WithIV(iv []byte) OptionFn

func WithKey

func WithKey(key []byte) OptionFn

func WithKeySize

func WithKeySize(keySize KeySize) OptionFn

func WithMethod

func WithMethod(method Method) OptionFn

func WithMode

func WithMode(m mode.Mode) OptionFn

func WithPadding

func WithPadding(p padding.Mode) OptionFn

type RC4

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

func (*RC4) Decrypt

func (r *RC4) Decrypt(ciphertext []byte) (plaintext []byte, err error)

func (*RC4) Encrypt

func (r *RC4) Encrypt(plaintext []byte) (*encodex.Encode, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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