gcrypto

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2019 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// Pbkdf2SaltLen is default salt len for pbkdf2
	Pbkdf2SaltLen = 16
	// Pbkdf2IterTimes is default iterator times for pbkdf2
	Pbkdf2IterTimes = 10000
	//Pbkdf2keyLen is default rootKey length for pbkdf2
	Pbkdf2keyLen = 40
)

Variables

View Source
var (
	// ErrAESTextSize ...
	ErrAESTextSize = errors.New("cipher text length is not a multiple of the block size")
	// ErrAESPadding ...
	ErrAESPadding = errors.New("cipher padding size error")
	// ErrInvalidKey ...
	ErrInvalidKey = errors.New("invalid key, it's length should more than 16")
)

Functions

func CmpPbkdf2Passwd

func CmpPbkdf2Passwd(password, salt, encrypted string, iter, keyLen int) bool

CmpPbkdf2Passwd compare the password

func GenPbkdf2Passwd

func GenPbkdf2Passwd(password string, saltlen, iter, keyLen int) (string, string)

GenPbkdf2Passwd generate a hmac pbkdf2 string

Types

type Crypto

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

Crypto the crypto object

func NewCrypto

func NewCrypto(factor string) (*Crypto, error)

NewCrypto create a instance of *Crypto

func (*Crypto) Decrypt

func (c *Crypto) Decrypt(src []byte) ([]byte, error)

Decrypt from an encrypted array of byte

func (*Crypto) DecryptStr

func (c *Crypto) DecryptStr(encryptedText string) (string, error)

DecryptStr decrypt from an encrypted base64 string

func (*Crypto) DecryptStrWithKey added in v0.1.2

func (c *Crypto) DecryptStrWithKey(encryptedKey string, encryptedText string) (plainText string, err error)

DecryptStrWithKey decrypt a string with encrypted work key

func (*Crypto) DecryptWithKey added in v0.1.2

func (c *Crypto) DecryptWithKey(encryptedKey []byte, encryptedText []byte) (plainText []byte, err error)

DecryptStrWithKey decrypt a byte array with encrypted work key

func (*Crypto) Encrypt

func (c *Crypto) Encrypt(src []byte) ([]byte, error)

Encrypt an array byte

func (*Crypto) EncryptStr

func (c *Crypto) EncryptStr(plainText string) (string, error)

EncryptStr encrypt a string

func (*Crypto) EncryptStrWithKey added in v0.1.2

func (c *Crypto) EncryptStrWithKey(key []byte, plainText string) (encryptedKey string, encryptedText string, err error)

EncryptStrWithKey encrypt a byte array with a given work key encrypt work key using root key firstly then encrypt text using work key

func (*Crypto) EncryptStrWithRandKey added in v0.1.2

func (c *Crypto) EncryptStrWithRandKey(plainText string) (encryptedKey string, encryptedText string, err error)

EncryptStrWithRandKey encrypt a string with a random work key

func (*Crypto) EncryptWithKey added in v0.1.2

func (c *Crypto) EncryptWithKey(key []byte, plainText []byte) (encryptedKey []byte, encryptedText []byte, err error)

EncryptWithKey encrypt a string with a given work key encrypt work key using root key firstly then encrypt text using work key

Jump to

Keyboard shortcuts

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