crypto

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CryptoNone     = CryptoType(0)
	CryptoChaCha20 = CryptoType(1)
	CryptoTea      = CryptoType(2)
	CryptoAES128   = CryptoType(3)

	NoneKeyLen       = uint8(0)
	ChaCha20KeyLen   = uint8(32)
	ChaCha20NonceLen = uint8(8)
	TeaKeyLen        = uint8(4)
	TeaByteKeyLen    = uint8(32)
	AES128KeyLen     = uint8(16)
)

Variables

This section is empty.

Functions

func AesDecrypt

func AesDecrypt(crypted, key []byte) ([]byte, error)

func AesEncrypt

func AesEncrypt(origData, key []byte) ([]byte, error)

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

func TeaDecrypt

func TeaDecrypt(src, teaKey []byte, key uint32)

func TeaEncrypt

func TeaEncrypt(src, teaKey []byte, key uint32)

Types

type CryptoType

type CryptoType uint8

func CryptoFromString

func CryptoFromString(method string) CryptoType

type Cryptor

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

func NewCryptor

func NewCryptor() *Cryptor

func (*Cryptor) Decrypt

func (c *Cryptor) Decrypt(cryptoCode CryptoType, isOrderStream bool, src []byte, keys ...[]byte) ([]byte, error)

* ** Encrypt 解密方法 ** @param cryptoCode 加密算法 ** @param isOrderStream 是否是有序字节流,针对UDP数据流,数据报有可能乱序,所以如果不是有序的,chacha20每次都需要初始化 ** @param src 原始数据 ** @param keys 密钥,不同算法密钥长度不一样 ** return 解密后的数据 *

func (*Cryptor) Encrypt

func (c *Cryptor) Encrypt(cryptoCode CryptoType, isOrderStream bool, src []byte, keys ...[]byte) ([]byte, error)

* ** Encrypt 加密方法 ** @param cryptoCode 加密算法 ** @param isOrderStream 是否是有序字节流,针对UDP数据流,数据报有可能乱序,所以如果不是有序的,chacha20每次都需要初始化 ** @param src 原始数据 ** @param keys 密钥,不同算法密钥长度不一样 ** return 加密后的数据 *

Jump to

Keyboard shortcuts

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