Documentation
¶
Overview ¶
Package secutil provide some security utils
Index ¶
- Constants
- Variables
- func DecryptGCM(key, nonce, ciphertext []byte) ([]byte, error)
- func EncryptGCM(key, plaintext []byte) (ciphertext, nonce []byte, err error)
- func PKCS5Padding(ciphertext []byte, blockSize int) []byte
- func PKCS5UnPadding(origData []byte) ([]byte, error)
- func PKCS7Padding(ciphertext []byte, blockSize int) []byte
- func PKCS7UnPadding(origData []byte) ([]byte, error)
- type AesCrypt
- func (p *AesCrypt) Config(fn func(c *CryptConfig)) *AesCrypt
- func (p *AesCrypt) Decrypt(enc []byte) ([]byte, error)
- func (p *AesCrypt) DecryptString(enc string) (string, error)
- func (p *AesCrypt) Encrypt(src []byte) ([]byte, error)
- func (p *AesCrypt) EncryptString(src string) (string, error)
- func (p *AesCrypt) Init() error
- type CryptConfig
Constants ¶
View Source
const ( CryptAes128CBC = "aes-128-cbc" CryptAes256CBC = "aes-256-cbc" )
aes methods
View Source
const ( PadTypeNone uint8 = iota PadTypeZeros PadTypePKCS5 PadTypePKCS7 )
padding type for encoding contents.
Variables ¶
View Source
var ( // ErrInvalidAESKeySize means the AES key length is not 16, 24 or 32 bytes. ErrInvalidAESKeySize = errors.New("secutil: invalid AES key size") // ErrInvalidGCMNonceSize means the GCM nonce length does not match AEAD requirements. ErrInvalidGCMNonceSize = errors.New("secutil: invalid GCM nonce size") )
View Source
var ErrUnPadding = errors.New("un-padding decrypted data fail")
ErrUnPadding error
Functions ¶
func DecryptGCM ¶ added in v0.7.5
DecryptGCM decrypts ciphertext with AES-GCM.
func EncryptGCM ¶ added in v0.7.5
EncryptGCM encrypts plaintext with AES-GCM.
The key length must be 16, 24 or 32 bytes. A random nonce is generated and returned alongside the ciphertext.
func PKCS5Padding ¶
PKCS5Padding input data
func PKCS5UnPadding ¶
PKCS5UnPadding input data
func PKCS7Padding ¶
PKCS7Padding input data
func PKCS7UnPadding ¶
PKCS7UnPadding input data
Types ¶
type AesCrypt ¶
type AesCrypt struct {
CryptConfig
// contains filtered or unexported fields
}
AesCrypt struct
func (*AesCrypt) Config ¶
func (p *AesCrypt) Config(fn func(c *CryptConfig)) *AesCrypt
Config crypt instance
func (*AesCrypt) DecryptString ¶
DecryptString to source string. return error on fail.
func (*AesCrypt) EncryptString ¶
EncryptString to encoded string. return error on fail.
type CryptConfig ¶
type CryptConfig struct {
Key string
// IV string, length must be equals to cipher.Block.BlockSize()
IV string
// Method name. eg: CryptAes256CBC
Method string
// PadType for padding string.
PadType uint8
Encoder byteutil.BytesEncoder
}
CryptConfig struct
Click to show internal directories.
Click to hide internal directories.