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 BlockCrypt
- type BlockOption
- type Cipher
- type IvSizeError
- type KeyIvLen
- type KeySizeError
- type StreamOption
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 ¶
NewBlowfishCipher new blowfish cipher The key argument should be the Blowfish key, from 1 to 56 bytes.
func NewCast5Cipher ¶
NewCast5Cipher new cast5 cipher, The key size should 32
func NewChacha20 ¶
NewChacha20 new chacha20 key size should 32, iv size should one of 12,24
func NewSalsa20 ¶
NewSalsa20 new salsa20 key size should 32, iv size should one of 8
func NewTwofishCipher ¶
NewTwofishCipher new twofish cipher The key argument should be the Twofish key, 16, 24 or 32 bytes.
func NewXteaCipher ¶
NewXteaCipher new xtea cipher The key argument should be the XTEA key. XTEA only supports 128 bit (16 byte) keys.
func PCKSPadding ¶
PCKSPadding PKCS#5和PKCS#7 填充
func PCKSUnPadding ¶
PCKSUnPadding PKCS#5和PKCS#7 解填充
Types ¶
type BlockCrypt ¶
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
func NewBlockCipher ¶
func NewBlockCipher(key []byte, newCipher func(key []byte) (cipher.Block, error), opts ...BlockOption) (BlockCrypt, error)
default new with newCipher and key, key should be reference newCipher required. newCipher support follow or implement func(key []byte) (cipher.Block, error):
aes cipher des blowfish cast5 twofish xtea tea
support:
cbc(default): cipher.NewCBCEncrypter, cipher.NewCBCDecrypter
func NewStreamCipher ¶
func NewStreamCipher(key []byte, newCipher func(key []byte) (cipher.Block, error), opts ...StreamOption) (BlockCrypt, error)
NewStreamCipher new with newCipher and key newCipher support follow or implement func(key []byte) (cipher.Block, error):
aes cipher des blowfish cast5 twofish xtea tea
block stream cipher support:
cfb(default): cipher.NewCFBEncrypter, cipher.NewCFBDecrypter ctr: cipher.NewCTR, cipher.NewCTR ofb: cipher.NewOFB, cipher.NewOFB
type BlockOption ¶
type BlockOption func(bs *blockBlock)
BlockOption option
func WithBlockCodec ¶
func WithBlockRandIV ¶
func WithBlockRandIV(generateIv func(block cipher.Block) ([]byte, error)) BlockOption
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 StreamOption ¶
type StreamOption func(bs *blockStream)
StreamOption option
func WithStreamCodec ¶
func WithStreamRandIV ¶
func WithStreamRandIV(generateIv func(block cipher.Block) ([]byte, error)) StreamOption