Documentation ¶
Overview ¶
Package encrypt implement common encrypt and decrypt for stream
Index ¶
- Variables
- func CipherMethods() []string
- func Evp2Key(password string, keyLen int) (key []byte)
- func HasCipherMethod(method string) (ok bool)
- func NewBlowfishCipher(key []byte) (cipher.Block, error)
- func NewCast5Cipher(key []byte) (cipher.Block, error)
- func NewChacha20(key, iv []byte) (cipher.Stream, error)
- func NewRc4Md5(key, iv []byte) (cipher.Stream, error)
- func NewSalsa20(key, iv []byte) (cipher.Stream, error)
- func NewStream(method string, key, iv []byte, encrypt bool) (cipher.Stream, error)
- func NewTwofishCipher(key []byte) (cipher.Block, error)
- func NewXteaCipher(key []byte) (cipher.Block, error)
- func PCKSPadding(origData []byte, blockSize int) []byte
- func PCKSUnPadding(origData []byte) ([]byte, error)
- func RandIV(block cipher.Block) ([]byte, error)
- func Valid(method, password string) bool
- type Apply
- type BlockCrypt
- type BlockModeCipher
- type BlockStreamCipher
- type Cipher
- type IvSizeError
- type KeyIvLen
- type KeySizeError
- type Option
- type Stream
Constants ¶
This section is empty.
Variables ¶
var ( ErrInputInvalidLength = errors.New("encoded message length must be more than zero") ErrInputNotMoreABlock = errors.New("decoded message length must be more than a block size") ErrInputNotMultipleBlocks = errors.New("decoded message length must be multiple of block size") ErrInvalidIvSize = errors.New("iv length must equal block size") ErrUnPaddingOutOfRange = errors.New("unPadding out of range") )
error defined
Functions ¶
func NewBlowfishCipher ¶ added in v0.0.9
NewBlowfishCipher new blowfish cipher
func NewCast5Cipher ¶ added in v0.0.9
NewCast5Cipher new cast5 cipher
func NewChacha20 ¶ added in v0.0.9
NewChacha20 new chacha20 key size should 32, iv size should one of 12,24
func NewRc4Md5 ¶ added in v0.0.9
NewRc4Md5 new rc4-md5 key size should 16, iv size should one of 6,16
func NewSalsa20 ¶ added in v0.0.9
NewSalsa20 new salsa20 key size should 32, iv size should one of 8
func NewTwofishCipher ¶ added in v0.0.9
NewTwofishCipher new twofish cipher
func NewXteaCipher ¶ added in v0.0.9
NewXteaCipher new xtea cipher
func PCKSPadding ¶ added in v0.0.9
PCKSPadding PKCS#5和PKCS#7 填充
func PCKSUnPadding ¶ added in v0.0.9
PCKSUnPadding PKCS#5和PKCS#7 解填充
Types ¶
type Apply ¶ added in v0.0.9
type Apply interface {
// contains filtered or unexported methods
}
Apply apply
type BlockCrypt ¶ added in v0.0.9
type BlockCrypt interface { // BlockSize returns the mode's block size. BlockSize() int // Encrypt plain text. return iv + cipher text Encrypt(plainText []byte) ([]byte, error) // Encrypt cipher text(iv + cipher text). plain text. Decrypt(cipherText []byte) ([]byte, error) }
BlockCrypt block crypt interface
type BlockModeCipher ¶ added in v0.0.9
type BlockModeCipher struct { NewEncrypt func(block cipher.Block, iv []byte) cipher.BlockMode NewDecrypt func(block cipher.Block, iv []byte) cipher.BlockMode }
BlockModeCipher block mode cipher support:
cbc: cipher.NewCBCEncrypter, cipher.NewCBCDecrypter
func (*BlockModeCipher) New ¶ added in v0.0.9
func (sf *BlockModeCipher) New(key []byte, newCipher func(key []byte) (cipher.Block, error), opts ...Option) (BlockCrypt, error)
New new with newCipher and key newCipher support follow or implement func(key []byte) (cipher.Block, error):
aes cipher des blowfish cast5 twofish xtea tea
type BlockStreamCipher ¶ added in v0.0.9
type BlockStreamCipher struct { NewEncrypt func(block cipher.Block, iv []byte) cipher.Stream NewDecrypt func(block cipher.Block, iv []byte) cipher.Stream }
BlockStreamCipher block stream cipher support:
cfb: cipher.NewCFBEncrypter, cipher.NewCFBDecrypter ctr: cipher.NewCTR, cipher.NewCTR ofb: cipher.NewOFB, cipher.NewOFB
func (*BlockStreamCipher) New ¶ added in v0.0.9
func (sf *BlockStreamCipher) New(key []byte, newCipher func(key []byte) (cipher.Block, error), opts ...Option) (BlockCrypt, error)
New new with newCipher and key newCipher support follow or implement func(key []byte) (cipher.Block, error):
aes cipher des blowfish cast5 twofish xtea tea
type Cipher ¶
Cipher implement write and read cipher.Stream
func NewCipher ¶
NewCipher new cipher method support:
aes-128-cfb aes-192-cfb aes-256-cfb aes-128-ctr aes-192-ctr aes-256-ctr aes-128-ofb aes-192-ofb aes-256-ofb des-cfb des-ctr des-ofb 3des-cfb 3des-ctr 3des-ofb blowfish-cfb blowfish-ctr blowfish-ofb cast5-cfb cast5-ctr cast5-ofb twofish-128-cfb twofish-192-cfb twofish-256-cfb twofish-128-ctr twofish-192-ctr twofish-256-ctr twofish-128-ofb twofish-192-ofb twofish-256-ofb tea-cfb tea-ctr tea-ofb xtea-cfb xtea-ctr xtea-ofb rc4-md5 rc4-md5-6 chacha20 chacha20-ietf salsa20
type IvSizeError ¶ added in v0.0.9
type IvSizeError int
IvSizeError iv size error
func (IvSizeError) Error ¶ added in v0.0.9
func (i IvSizeError) Error() string
Error implement Error interface
type KeySizeError ¶ added in v0.0.9
type KeySizeError int
KeySizeError key size error
func (KeySizeError) Error ¶ added in v0.0.9
func (k KeySizeError) Error() string
Error implement Error interface
type Option ¶ added in v0.0.9
type Option func(apply Apply)
Option option
func WithGenerateIv ¶ added in v0.1.1
WithGenerateIv with custom generate new iv function