Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrCipherUninitialized = errors.New("cipher needs initialize before encrypt/decrypt") ErrCapcityNotEnough = errors.New("slice capcity is not enough") ErrAgain = errors.New("require more data") ErrEmptyPassword = errors.New("empty password") ErrUnsupportedMethod = errors.New("unsupported encryption method") )
Error type in encrypt packet
View Source
var (
// NonceSize defined the largest number nonce can reach, once reached, the nonce will warpped
NonceSize = 12
)
Functions ¶
func CheckCipherMethod ¶
CheckCipherMethod checks if the cipher method is supported
Types ¶
type Cipher ¶
type Cipher interface { KeySize() int // KeySize return the key length which cipher request InitBolckSize() int // InitBolckSize give out the size of init block for cipher init, also called as aslt or iv Copy() Cipher // Copy return the copy of the cipher with given password. Need to inititalze before use //Close() // Close the cipher and release the resource Encrypt(src, dest []byte) (int, error) // Encrypt data from src to dest, return the bytes after encryption Decrypt(src, dest []byte) (int, error) // Decrypt data from src to dest, return the bytes after decryption Pack(src, dest []byte) (int, error) // Pack will encrypt the src data block to dest and return the bytes encrypted, ONLY USED FOR UDP Unpack(src, dest []byte) (int, error) // Unpack decrypt the src data block to dest, return the bytes decrypted, ONLY USED FOR UDP EncryptorInited() bool // EncryptorInited return wether encryptor is initalized InitEncryptor() ([]byte, error) // InitEncryptor init the encryptor and return the randomly generated InintBolck DecryptorInited() bool // DecryptorInited return wether decryptor is initialized InitDecryptor(data []byte) error // InitDecryptor initialize the decryptor with given initBolck }
Cipher is the encdyptor and decryptor
func NewAEADCipher ¶
NewAEADCipher creates a cipher that can be used in Dial() etc. Use cipher.Copy() to create a new cipher with the same method and password to avoid the cost of repeated cipher initialization.
func NewStreamCipher ¶
NewStreamCipher creates a cipher that can be used in Dial() etc. Use cipher.Copy() to create a new cipher with the same method and password to avoid the cost of repeated cipher initialization.
func PickCipher ¶
PickCipher return the uninitialized cipher with given passwd
Click to show internal directories.
Click to hide internal directories.