codec

package
v1.4.4-alpha1202-diff-... Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: AGPL-3.0 Imports: 62 Imported by: 83

Documentation

Index

Constants

View Source
const DefaultBytesToKeyIterations = 1
View Source
const DefaultPBKDF2Iterations = 10000

Variables

View Source
var (
	EscapeHtmlString   = html.EscapeString
	UnescapeHtmlString = html.UnescapeString
	StrConvUnquote     = strconv.Unquote
	StrConvQuote       = strconv.Quote
)
View Source
var (
	// BytesToKeyMD5 utilizes MD5 key-derivation (`-md md5`)
	BytesToKeyMD5 = NewBytesToKeyGenerator(md5.New, DefaultBytesToKeyIterations)
	// BytesToKeySHA1 utilizes SHA1 key-derivation (`-md sha1`)
	BytesToKeySHA1 = NewBytesToKeyGenerator(sha1.New, DefaultBytesToKeyIterations)
	// BytesToKeySHA256 utilizes SHA256 key-derivation (`-md sha256`)
	BytesToKeySHA256 = NewBytesToKeyGenerator(sha256.New, DefaultBytesToKeyIterations)
	// BytesToKeySHA384 utilizes SHA384 key-derivation (`-md sha384`)
	BytesToKeySHA384 = NewBytesToKeyGenerator(sha512.New384, DefaultBytesToKeyIterations)
	// BytesToKeySHA512 utilizes SHA512 key-derivation (`-md sha512`)
	BytesToKeySHA512 = NewBytesToKeyGenerator(sha512.New, DefaultBytesToKeyIterations)
	// PBKDF2MD5 utilizes PBKDF2 key derivation with MD5 hashing (`-pbkdf2 -md md5`)
	PBKDF2MD5 = NewPBKDF2Generator(md5.New, DefaultPBKDF2Iterations)
	// PBKDF2SHA1 utilizes PBKDF2 key derivation with SHA1 hashing (`-pbkdf2 -md sha1`)
	PBKDF2SHA1 = NewPBKDF2Generator(sha1.New, DefaultPBKDF2Iterations)
	// PBKDF2SHA256 utilizes PBKDF2 key derivation with SHA256 hashing (`-pbkdf2 -md sha256`)
	PBKDF2SHA256 = NewPBKDF2Generator(sha256.New, DefaultPBKDF2Iterations)
	// PBKDF2SHA384 utilizes PBKDF2 key derivation with SHA384 hashing (`-pbkdf2 -md sha384`)
	PBKDF2SHA384 = NewPBKDF2Generator(sha512.New384, DefaultPBKDF2Iterations)
	// PBKDF2SHA512 utilizes PBKDF2 key derivation with SHA512 hashing (`-pbkdf2 -md sha512`)
	PBKDF2SHA512 = NewPBKDF2Generator(sha512.New, DefaultPBKDF2Iterations)
)
View Source
var (
	CBC = "CBC"
	ECB = "ECB"
	CFB = "CFB"
	OFB = "OFB"
	CTR = "CTR"
)
View Source
var AESGCMEncryptWithNonceSize16 = AESGCMEncrypt
View Source
var DESDecryptCBCWithPKCSPadding = DESDecFactory(PKCS5UnPadding, CBC)
View Source
var DESDecryptECBWithPKCSPadding = DESDecFactory(PKCS5UnPadding, ECB)
View Source
var DESDecryptECBWithZeroPadding = DESDecFactory(ZeroUnPadding, ECB)
View Source
var DESEncryptCBCWithPKCSPadding = DESEncFactory(PKCS5Padding, CBC)

Des

View Source
var DESEncryptECBWithPKCSPadding = DESEncFactory(PKCS5Padding, ECB)
View Source
var DoubleDecodeUrl = func(i string) (string, error) {
	raw, err := url.QueryUnescape(i)
	if err != nil {
		return "", err
	}

	return url.QueryUnescape(raw)
}
View Source
var DoubleEncodeUrl = func(i interface{}) string {
	return url.QueryEscape(EncodeUrlCode(i))
}
View Source
var PKCS7Padding = sm4.PKCS7Padding
View Source
var PKCS7UnPadding = sm4.PKCS7UnPadding
View Source
var PathEscape = url.PathEscape
View Source
var SM4DecryptCBCWithZeroPadding = SM4DecFactory(ZeroUnPadding, CBC)
View Source
var SM4DecryptCFBWithZeroPadding = SM4DecFactory(ZeroUnPadding, CFB)
View Source
var SM4DecryptCTRWithPKCSPadding = SM4DecFactory(PKCS5UnPadding, CTR)
View Source
var SM4DecryptCTRWithZeroPadding = SM4DecFactory(ZeroUnPadding, CTR)
View Source
var SM4DecryptECBWithZeroPadding = SM4DecFactory(ZeroUnPadding, ECB)
View Source
var SM4DecryptOFBWithZeroPadding = SM4DecFactory(ZeroUnPadding, OFB)
View Source
var SM4EncryptCBCWithZeroPadding = SM4EncFactory(ZeroPadding, CBC)

other func

View Source
var SM4EncryptCFBWithZeroPadding = SM4EncFactory(ZeroPadding, CFB)
View Source
var SM4EncryptCTRWithPKCSPadding = SM4EncFactory(PKCS5Padding, CTR)
View Source
var SM4EncryptCTRWithZeroPadding = SM4EncFactory(ZeroPadding, CTR)
View Source
var SM4EncryptECBWithZeroPadding = SM4EncFactory(ZeroPadding, ECB)
View Source
var SM4EncryptOFBWithZeroPadding = SM4EncFactory(ZeroPadding, OFB)
View Source
var SM4GCMDecrypt = SM4GCMDec
View Source
var SM4GCMEncrypt = SM4GCMEnc
View Source
var TripleDESDecryptCBCWithPKCSPadding = TripleDESDecFactory(PKCS5UnPadding, CBC)
View Source
var TripleDESDecryptECBWithPKCSPadding = TripleDESDecFactory(PKCS5UnPadding, ECB)
View Source
var TripleDESDecryptECBWithZeroPadding = TripleDESDecFactory(ZeroUnPadding, ECB)
View Source
var TripleDESEncryptCBCWithPKCSPadding = TripleDESEncFactory(PKCS5Padding, CBC)

TripleDes

View Source
var TripleDESEncryptECBWithPKCSPadding = TripleDESEncFactory(PKCS5Padding, ECB)
View Source
var TripleDESEncryptECBWithZeroPadding = TripleDESEncFactory(ZeroPadding, ECB)

Functions

func AESDec added in v1.3.3

func AESDec(key []byte, data []byte, iv []byte, mode string) ([]byte, error)

AESDecryptBasic 使用 AES 算法对数据进行解密,支持多种模式(CBC、CFB、ECB、OFB、CTR)。 注意:此函数是底层的高级用法,需要外部自行处理 padding,key,iv 等问题。 example: ```

codec.AESDecryptBasic("1234567890123456", cipertext, "1234567890123456", codec.CBC)

```

func AESDecWithPassphrase

func AESDecWithPassphrase(passphrase, data, salt []byte, KDF KeyDerivationFunc, aesMode string) ([]byte, error)

func AESDecryptCBCWithPKCSPadding added in v1.3.3

func AESDecryptCBCWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

AESCBCDecryptWithPKCS7Padding 使用 AES 算法,在 CBC 模式下,使用 PKCS5 填充来解密数据。 它接受一个密钥(key)、需要解密的数据(data to decrypt)和一个初始化向量(iv)。 密钥的长度必须是 16、24 或 32 字节(分别对应 AES-128、AES-192 或 AES-256)。 如果iv为 nil,则使用key的前16字节作为iv。 注意:AESCBCDecrypt AESDecrypt 和 AESCBCDecryptWithPKCS7Padding 是同一个函数的别名 example: ```

codec.AESCBCDecryptWithPKCS7Padding("1234567890123456", ciphertext, "1234567890123456")

```

func AESDecryptCBCWithZeroPadding added in v1.3.3

func AESDecryptCBCWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

AESCBCDecryptWithZeroPadding 使用 AES 算法,在 CBC 模式下,使用 Zero 填充来解密数据。 它接受一个密钥(key)、需要解密的数据(data to decrypt)和一个初始化向量(iv)。 密钥的长度必须是 16、24 或 32 字节(分别对应 AES-128、AES-192 或 AES-256)。 如果iv为 nil,则使用key的前16字节作为iv。 example: ``` codec.AESCBCDecryptWithZeroPadding("1234567890123456", ciphertext, "1234567890123456") ```

func AESDecryptCFBWithPKCSPadding

func AESDecryptCFBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

AESCFBDecryptWithPKCS7Padding 使用 AES 算法,在 CFB 模式下,使用 PKCS5 填充来解密数据。 密钥的长度必须是 16、24 或 32 字节(分别对应 AES-128、AES-192 或 AES-256)。 如果iv为 nil,则使用key的前16字节作为iv。

func AESDecryptCFBWithZeroPadding

func AESDecryptCFBWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

AESCFBDecryptWithZeroPadding 使用 AES 算法,在 CFB 模式下,使用 Zero 填充来解密数据。

func AESDecryptECBWithPKCSPadding added in v1.3.3

func AESDecryptECBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

AESDecryptECBWithPKCSPadding 使用 AES 算法,在 ECB 模式下对数据进行解密,使用 PKCSPadding 填充方式 它接受一个密钥(key)、需要解密的数据(data to decrypt)。 ecb 模式下iv 无用。 密钥的长度必须是 16、24 或 32 字节(分别对应 AES-128、AES-192 或 AES-256)。 AESECBDecrypt 和 AESDecryptECBWithPKCSPadding 是同一个函数。 example: ``` codec.AESECBDecryptWithPKCS7Padding("1234567890123456", "hello world", nil) ```

func AESDecryptECBWithZeroPadding added in v1.3.3

func AESDecryptECBWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

AESDecryptECBWithZeroPadding 使用 AES 算法,在 ECB 模式下对数据进行解密,使用 ZeroPadding 填充方式 它接受一个密钥(key)、需要解密的数据(data to decrypt)。 ecb 模式下iv 无用。 密钥的长度必须是 16、24 或 32 字节(分别对应 AES-128、AES-192 或 AES-256)。 example: ``` codec.AESECBDecryptWithZeroPadding("1234567890123456", "hello world", nil) ```

func AESEnc added in v1.3.3

func AESEnc(key []byte, data []byte, iv []byte, mode string) ([]byte, error)

AESEncryptBasic 使用 AES 算法对数据进行加密,支持多种模式(CBC、CFB、ECB、OFB、CTR) 。 注意:此函数是底层的高级用法,需要外部自行处理 padding,key,iv 等问题。 example: ```

codec.AESEncryptBasic("1234567890123456", codec.PKCS5Padding("hello world",16), "1234567890123456", codec.CBC)

```

func AESEncWithPassphrase

func AESEncWithPassphrase(passphrase, data, salt []byte, KDF KeyDerivationFunc, aesMode string) ([]byte, error)

func AESEncryptCBCWithPKCSPadding added in v1.3.3

func AESEncryptCBCWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

AESCBCEncryptWithPKCS7Padding 使用 AES 算法,在 CBC 模式下,使用 PKCS5 填充来加密数据。 它接受一个密钥(key)、需要加密的数据(data to encrypt)和一个初始化向量(iv)。 密钥的长度必须是 16、24 或 32 字节(分别对应 AES-128、AES-192 或 AES-256)。 如果iv为 nil,则使用key的前16字节作为iv。 注意:AESCBCEncrypt AESEncrypt 和 AESCBCEncryptWithPKCS7Padding 是同一个函数的别名 example: ```

codec.AESCBCEncryptWithPKCS7Padding("1234567890123456", "hello world", "1234567890123456")

```

func AESEncryptCBCWithZeroPadding added in v1.3.3

func AESEncryptCBCWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

AESCBCEncryptWithZeroPadding 使用 AES 算法,在 CBC 模式下,使用 Zero 填充来加密数据。 它接受一个密钥(key)、需要加密的数据(data to encrypt)和一个初始化向量(iv)。 密钥的长度必须是 16、24 或 32 字节(分别对应 AES-128、AES-192 或 AES-256)。 如果iv为 nil,则使用key的前16字节作为iv。 example: ``` codec.AESCBCEncryptWithZeroPadding("1234567890123456", "hello world", "1234567890123456") ```

func AESEncryptCFBWithPKCSPadding

func AESEncryptCFBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

AESEncryptCFBWithPKCSPadding 使用 AES 算法,在 CFB 模式下,使用 PKCS5 填充来加密数据。 密钥的长度必须是 16、24 或 32 字节(分别对应 AES-128、AES-192 或 AES-256)。 如果iv为 nil,则使用key的前16字节作为iv。

func AESEncryptCFBWithZeroPadding

func AESEncryptCFBWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

AESCFBEncryptWithZeroPadding 使用 AES 算法,在 CFB 模式下,使用 Zero 填充来加密数据。

func AESEncryptECBWithPKCSPadding added in v1.3.3

func AESEncryptECBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

AESCBCEncryptWithZeroPadding 使用 AES 算法,在 ECB 模式下对数据进行加密,使用 PKCSPadding 填充方式 它接受一个密钥(key)、需要加密的数据(data to encrypt)。 ecb 模式下iv 无用。 密钥的长度必须是 16、24 或 32 字节(分别对应 AES-128、AES-192 或 AES-256)。 AESECBEncrypt 和 AESECBEncryptWithPKCSPadding 是同一个函数。 example: ``` codec.AESECBEncryptWithPKCS7Padding("1234567890123456", "hello world", nil) ```

func AESEncryptECBWithZeroPadding added in v1.3.3

func AESEncryptECBWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

AESCBCEncryptWithZeroPadding 使用 AES 算法,在 ECB 模式下对数据进行加密,使用 ZeroPadding 填充方式 它接受一个密钥(key)、需要加密的数据(data to encrypt)。 ecb 模式下iv 无用。 密钥的长度必须是 16、24 或 32 字节(分别对应 AES-128、AES-192 或 AES-256)。 example: ``` codec.AESECBEncryptWithZeroPadding("1234567890123456", "hello world", nil) ```

func AESGCMDecrypt

func AESGCMDecrypt(key []byte, data interface{}, nonce []byte) ([]byte, error)

func AESGCMDecryptWithNonceSize

func AESGCMDecryptWithNonceSize(key []byte, data interface{}, nonceRaw []byte, nonceSize int) ([]byte, error)

func AESGCMDecryptWithNonceSize12

func AESGCMDecryptWithNonceSize12(key []byte, data interface{}, nonce []byte) ([]byte, error)

func AESGCMDecryptWithNonceSize16

func AESGCMDecryptWithNonceSize16(key []byte, data interface{}, nonce []byte) ([]byte, error)

func AESGCMEncrypt

func AESGCMEncrypt(key []byte, data interface{}, nonceRaw []byte) ([]byte, error)

//AES GCM 加密后的payload shiro 1.4.2版本更换为了AES-GCM加密方式

func AES_GCM_Encrypt(key []byte, Content []byte) string {
	block, _ := aes.NewCipher(key)
	nonce := make([]byte, 16)
	io.ReadFull(rand.Reader, nonce)
	aesgcm, _ := cipher.NewGCMWithNonceSize(block, 16)
	ciphertext := aesgcm.Seal(nil, nonce, Content, nil)
	return base64.StdEncoding.EncodeToString(append(nonce, ciphertext...))
}

func AESGCMEncryptWithNonceSize

func AESGCMEncryptWithNonceSize(key []byte, data interface{}, nonceRaw []byte, nonceSize int) ([]byte, error)

func AESGCMEncryptWithNonceSize12

func AESGCMEncryptWithNonceSize12(key []byte, data interface{}, nonceRaw []byte) ([]byte, error)

func AllASCII

func AllASCII(i any) bool

func AnyToBytes added in v1.2.6

func AnyToBytes(i interface{}) (result []byte)

func AnyToString added in v1.2.6

func AnyToString(i interface{}) (result string)

func Atob added in v1.2.6

func Atob(i string) bool

func Atof added in v1.2.6

func Atof(i string) float64

func Atoi added in v1.2.6

func Atoi(i string) int

func Atoi64

func Atoi64(i string) int64

func Base32Padding

func Base32Padding(i string) string

func Base64Padding

func Base64Padding(i string) string

func BlockCheck added in v1.3.3

func BlockCheck(iv, data []byte, blockSize int) error

func CBCDecode added in v1.3.3

func CBCDecode(c cipher.Block, iv, data []byte) ([]byte, error)

func CBCEncode added in v1.3.3

func CBCEncode(c cipher.Block, iv, data []byte) ([]byte, error)

func CFBDecode added in v1.3.3

func CFBDecode(c cipher.Block, iv, data []byte) ([]byte, error)

func CFBEncode added in v1.3.3

func CFBEncode(c cipher.Block, iv, data []byte) ([]byte, error)

func CTRDecode added in v1.3.3

func CTRDecode(c cipher.Block, iv, data []byte) ([]byte, error)

func CTREncode added in v1.3.3

func CTREncode(c cipher.Block, iv, data []byte) ([]byte, error)

func CharDetect

func CharDetect(raw interface{}) ([]chardet.Result, error)

func CharDetectBest

func CharDetectBest(raw interface{}) (*chardet.Result, error)

func Cmac added in v1.3.3

func Cmac(alg string, key []byte, message []byte) ([]byte, error)

func DESDec added in v1.3.3

func DESDec(key []byte, data []byte, iv []byte, mode string) ([]byte, error)

func DESDecryptCBCWithZeroPadding added in v1.3.3

func DESDecryptCBCWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

DESCBCDecrypt 是一个便捷函数,用于使用 DES 算法,在 CBC 模式下,使用零填充来解密数据。 它接受一个密钥(key)、需要解密的数据(data to decrypt)和一个初始化向量(iv)。 密钥的长度必须是 8 个字节,并且 iv 可以是 nil 或者 8 个字节长。 如果 iv 为 nil,它将被固定为密钥,或者用零填充到 8 个字节。 DESCBCDecrypt DESDecrypt 是同一个函数。 example: ``` codec.DESCBCEncrypt([]byte("12345678"), ciphertext, "12345678") ```

func DESECBDec

func DESECBDec(key []byte, data []byte) ([]byte, error)

DESECBDecrypt 是一个便捷函数,用于使用 DES 算法,在 ECB 模式下,使用 零填充来解密数据。 它接受一个密钥(key)、需要解密的数据(data to decrypt)(ecb 模式下 iv 无用) 密钥的长度必须是 8 个字节。 example: ``` codec.DESECBDecrypt([]byte("12345678"), ciphertext) ```

func DESECBEnc

func DESECBEnc(key []byte, data []byte) ([]byte, error)

DESECBEncrypt 是一个便捷函数,用于使用 DES 算法,在 ECB 模式下,使用 零填充来加密数据。 它接受一个密钥(key)、需要加密的数据(data to encrypt)(ecb 模式下 iv 无用) 密钥的长度必须是 8 个字节。 example: ``` codec.DESECBEncrypt([]byte("12345678"), "hello world") ```

func DESEnc added in v1.3.3

func DESEnc(key []byte, data []byte, iv []byte, mode string) ([]byte, error)

func DESEncryptCBCWithZeroPadding added in v1.3.3

func DESEncryptCBCWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

DESCBCEncrypt 是一个便捷函数,用于使用 DES 算法,在 CBC 模式下,使用零填充来加密数据。 它接受一个密钥(key)、需要加密的数据(data to encrypt)和一个初始化向量(iv)。 密钥的长度必须是 8 个字节,并且 iv 可以是 nil 或者 8 个字节长。 如果 iv 为 nil,它将被固定为密钥,或者用零填充到 8 个字节。 加密数据长度需要是8的倍数。默认使用零填充方式进行填充。 如果希望使用其他填充方式,请使用 codec.PKCS7PaddingForDES 进行填充后,再调用此函数进行加密。 DESCBCEncrypt DESEncrypt 是同一个函数。 example: ``` codec.DESCBCEncrypt([]byte("12345678"), "hello world", "12345678") ```

func DESEncryptECBWithZeroPadding added in v1.3.3

func DESEncryptECBWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

DESECBEncrypt 是一个便捷函数,用于使用 DES 算法,在 ECB 模式下,使用 零填充来加密数据。 它接受一个密钥(key)、需要加密的数据(data to encrypt)。 ecb 模式下 iv 无用。 密钥的长度必须是 8 个字节。 example: ``` codec.DESECBEncrypt([]byte("12345678"), "hello world", nil) ```

func DecodeBase32 added in v1.2.4

func DecodeBase32(i string) ([]byte, error)

func DecodeBase64

func DecodeBase64(i string) ([]byte, error)

func DecodeBase64Url

func DecodeBase64Url(i interface{}) ([]byte, error)

func DecodeHex

func DecodeHex(i string) ([]byte, error)

func Decodebig5

func Decodebig5(s []byte) ([]byte, error)

Decodebig5 converts BIG5 to UTF-8

func Decodegbk

func Decodegbk(s []byte) ([]byte, error)

Decodegbk converts GBK to UTF-8

func ECBDecode added in v1.3.3

func ECBDecode(c cipher.Block, data []byte) ([]byte, error)

func ECBEncode added in v1.3.3

func ECBEncode(c cipher.Block, data []byte) ([]byte, error)

func EncodeBase32 added in v1.2.4

func EncodeBase32(i interface{}) string

func EncodeBase64

func EncodeBase64(i interface{}) string

func EncodeBase64Url

func EncodeBase64Url(i interface{}) string

func EncodeByType added in v1.2.8

func EncodeByType(t string, i interface{}) string

func EncodeHtmlEntity

func EncodeHtmlEntity(i interface{}) string

func EncodeHtmlEntityEx added in v1.3.1

func EncodeHtmlEntityEx(i interface{}, encodeType string, fullEncode bool) string

todo replace HtmlEntityEncode

func EncodeHtmlEntityHex

func EncodeHtmlEntityHex(i interface{}) string

func EncodeToHex

func EncodeToHex(i interface{}) string

func EncodeUrlCode

func EncodeUrlCode(i interface{}) string

func Encodebig5

func Encodebig5(s []byte) ([]byte, error)

Encodebig5 converts UTF-8 to BIG5

func Equal added in v1.3.3

func Equal(mac1, mac2 []byte) bool

Equal compares two MACs for equality without leaking timing information.

func EscapeInvalidUTF8Byte

func EscapeInvalidUTF8Byte(s []byte) string

func FixIV added in v1.3.3

func FixIV(iv, key []byte, blockSize int) []byte

func ForceQueryUnescape added in v1.2.8

func ForceQueryUnescape(s string) string

func GB18030ToUtf8

func GB18030ToUtf8(s []byte) ([]byte, error)

func GBKSafeString

func GBKSafeString(s []byte) (string, error)

func GbkToUtf8

func GbkToUtf8(s []byte) ([]byte, error)

func GenerateSM2PrivateKeyHEX

func GenerateSM2PrivateKeyHEX() ([]byte, []byte, error)

func GenerateSM2PrivateKeyPEM

func GenerateSM2PrivateKeyPEM() ([]byte, []byte, error)

func HTTPChunkedDecode

func HTTPChunkedDecode(raw []byte) ([]byte, error)

func HTTPChunkedDecodeWithRestBytes added in v1.2.6

func HTTPChunkedDecodeWithRestBytes(raw []byte) ([]byte, []byte)

func HTTPChunkedDecoderWithRestBytes added in v1.2.6

func HTTPChunkedDecoderWithRestBytes(raw io.Reader) ([]byte, []byte, io.Reader, error)

func HTTPChunkedEncode

func HTTPChunkedEncode(raw []byte) []byte

func HZGB2312ToUtf8

func HZGB2312ToUtf8(s []byte) ([]byte, error)

func HmacMD5

func HmacMD5(key, data interface{}) []byte

func HmacSM3

func HmacSM3(key, data interface{}) []byte

func HmacSha1

func HmacSha1(key, data interface{}) []byte

func HmacSha256

func HmacSha256(key, data interface{}) []byte

func HmacSha512

func HmacSha512(key, data interface{}) []byte

func HtmlCharsetPrescan

func HtmlCharsetPrescan(content []byte, callback ...func(start, end int, matched PrescanResult)) (e encoding.Encoding, name string)

func IsControl added in v1.3.3

func IsControl(r rune) bool

func IsGBK

func IsGBK(data []byte) bool

func IsUTF8

func IsUTF8(i any) (bool, error)

func IsUTF8File

func IsUTF8File(filename string) (bool, error)

IsUTF8File checks if a file is UTF-8 encoded using sampling strategy For files < 0.5K: check entire content For files 0.5K-1K: check one 0.5K sample For files > 1K: check 4+ samples (256 runes each), up to 8 samples max If sampling cuts into UTF-8 character, look forward/backward to find valid boundaries

func IsUtf8

func IsUtf8(data []byte) bool

func Itoa added in v1.2.8

func Itoa(i int) string

func JsonUnicodeDecode

func JsonUnicodeDecode(i string) string

func JsonUnicodeEncode

func JsonUnicodeEncode(i string) string

func MMH3Hash128

func MMH3Hash128(i interface{}) string

func MMH3Hash128x64

func MMH3Hash128x64(i interface{}) string

func MMH3Hash32

func MMH3Hash32(i interface{}) int64

func Md5

func Md5(i interface{}) string

func MustPKCS5UnPadding added in v1.2.2

func MustPKCS5UnPadding(origData []byte) ([]byte, error)

func OFBDecode added in v1.3.3

func OFBDecode(c cipher.Block, iv, data []byte) ([]byte, error)

func OFBEncode added in v1.3.3

func OFBEncode(c cipher.Block, iv, data []byte) ([]byte, error)

func PKCS5Padding

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

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

func PKCS7PaddingFor8ByteBlock added in v1.3.3

func PKCS7PaddingFor8ByteBlock(src []byte) []byte

func PKCS7UnPaddingFor8ByteBlock added in v1.3.3

func PKCS7UnPaddingFor8ByteBlock(src []byte) []byte

func PathUnescape

func PathUnescape(s string) (string, error)

func QueryEscape

func QueryEscape(s string) string

func QueryUnescape

func QueryUnescape(s string) (string, error)

func RC4Decrypt

func RC4Decrypt(cipherKey []byte, cipherText []byte) ([]byte, error)

func RC4Encrypt

func RC4Encrypt(cipherKey []byte, plainText []byte) ([]byte, error)

func RandBytes

func RandBytes(n int) []byte

func RandomUpperAndLower

func RandomUpperAndLower(s string) string

func ReadChunkedStream

func ReadChunkedStream(r io.Reader) (io.Reader, io.Reader, error)

func ReadHTTPChunkedDataWithFixed added in v1.2.6

func ReadHTTPChunkedDataWithFixed(raw []byte) (data []byte, fixedChunked []byte, rest []byte)

func ReadHTTPChunkedDataWithFixedError added in v1.3.3

func ReadHTTPChunkedDataWithFixedError(raw []byte) (data []byte, fixedChunked []byte, rest []byte, _ error)

func SM2DecryptASN1

func SM2DecryptASN1(priKey []byte, data []byte) ([]byte, error)

func SM2DecryptASN1WithPassword

func SM2DecryptASN1WithPassword(priKey []byte, data []byte, password []byte) ([]byte, error)

func SM2DecryptC1C2C3

func SM2DecryptC1C2C3(priKey []byte, data []byte) ([]byte, error)

func SM2DecryptC1C2C3WithPassword

func SM2DecryptC1C2C3WithPassword(priKey []byte, data []byte, password []byte) ([]byte, error)

func SM2DecryptC1C3C2

func SM2DecryptC1C3C2(priKey []byte, data []byte) ([]byte, error)

func SM2DecryptC1C3C2WithPassword

func SM2DecryptC1C3C2WithPassword(priKey []byte, data []byte, password []byte) ([]byte, error)

func SM2EncryptASN1

func SM2EncryptASN1(pubKey []byte, data []byte) ([]byte, error)

func SM2EncryptC1C2C3

func SM2EncryptC1C2C3(pubKey []byte, data []byte) ([]byte, error)

func SM2EncryptC1C3C2

func SM2EncryptC1C3C2(pubKey []byte, data []byte) ([]byte, error)

func SM2GenerateTemporaryKeyPair

func SM2GenerateTemporaryKeyPair() ([]byte, []byte, error)

SM2GenerateTemporaryKeyPair 生成用于密钥交换的临时密钥对

返回值:

  • []byte: 临时私钥(HEX格式)
  • []byte: 临时公钥(HEX格式)
  • error: 错误信息

Example: ``` tempPriKey, tempPubKey, err := codec.Sm2GenerateTemporaryKeyPair() die(err) println("临时私钥:", string(tempPriKey)) println("临时公钥:", string(tempPubKey)) ```

func SM2KeyExchange

func SM2KeyExchange(keyLength int, idA, idB, priKey, pubKey, tempPriKey, tempPubKey []byte, thisIsA bool) ([]byte, []byte, []byte, error)

SM2KeyExchange 执行SM2密钥交换算法

参数说明:

  • keyLength: 期望的共享密钥长度(字节)
  • idA: A方标识([]byte)
  • idB: B方标识([]byte)
  • priKey: 调用方私钥([]byte,支持PEM、HEX、原始字节)
  • pubKey: 对方公钥([]byte,支持PEM、HEX、原始字节)
  • tempPriKey: 调用方临时私钥([]byte,支持PEM、HEX、原始字节)
  • tempPubKey: 对方临时公钥([]byte,支持PEM、HEX、原始字节)
  • thisIsA: 如果是A方调用设置为true,B方调用设置为false

返回值:

  • sharedKey: 协商得到的共享密钥([]byte)
  • s1: 验证值S1,用于A验证B的身份([]byte)
  • s2: 验证值S2,用于B验证A的身份([]byte)
  • error: 错误信息

Example: ``` // A方和B方各自生成长期密钥对 priKeyA, pubKeyA, _ := codec.Sm2GenerateHexKeyPair() priKeyB, pubKeyB, _ := codec.Sm2GenerateHexKeyPair()

// A方和B方各自生成临时密钥对 tempPriKeyA, tempPubKeyA, _ := codec.Sm2GenerateHexKeyPair() tempPriKeyB, tempPubKeyB, _ := codec.Sm2GenerateHexKeyPair()

// A方执行密钥交换 sharedKeyA, s1A, s2A, err := codec.Sm2KeyExchange(32, []byte("Alice"), []byte("Bob"),

priKeyA, pubKeyB, tempPriKeyA, tempPubKeyB, true)

die(err)

// B方执行密钥交换 sharedKeyB, s1B, s2B, err := codec.Sm2KeyExchange(32, []byte("Alice"), []byte("Bob"),

priKeyB, pubKeyA, tempPriKeyB, tempPubKeyA, false)

die(err)

println("A方协商密钥:", codec.EncodeToHex(sharedKeyA)) println("B方协商密钥:", codec.EncodeToHex(sharedKeyB)) ```

func SM2SignWithSM3

func SM2SignWithSM3(priKeyBytes []byte, data interface{}) ([]byte, error)

SM2SignWithSM3 使用SM2私钥对数据进行SM3签名,返回签名与错误

参数 priKeyBytes 表示 SM2 私钥,支持以下格式:

  • PEM 编码(例如 "-----BEGIN PRIVATE KEY-----" 块)
  • HEX 字符串格式(64位十六进制字符串)
  • 原始字节数组(32字节的私钥数据)

参数 data 是要签名的原始数据,可以是 []byte、string 或其他可转换为字节数组的类型。 返回值是SM2签名结果(ASN.1 DER编码),如果签名失败则返回错误。

Example: ``` priKey, pubKey, _ := codec.Sm2GeneratePemKeyPair() data := "hello world" signature, err := codec.Sm2SignWithSM3(priKey, data) die(err) println("签名成功") ```

func SM2SignWithSM3WithPassword

func SM2SignWithSM3WithPassword(priKeyBytes []byte, data interface{}, password []byte) ([]byte, error)

SM2SignWithSM3WithPassword 使用带密码保护的SM2私钥对数据进行SM3签名

参数 priKeyBytes 表示加密的 SM2 私钥(PEM格式) 参数 data 是要签名的原始数据 参数 password 是私钥的保护密码,如果私钥未加密则传入 nil 返回值是SM2签名结果(ASN.1 DER编码),如果签名失败则返回错误。

Example: ``` encryptedPriKey := []byte(`-----BEGIN ENCRYPTED PRIVATE KEY----- MIGHAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBG0wawIBAQQg... -----END ENCRYPTED PRIVATE KEY-----`) data := "hello world" password := []byte("mypassword") signature, err := codec.Sm2SignWithSM3WithPassword(encryptedPriKey, data, password) die(err) println("加密私钥签名成功") ```

func SM2VerifyWithSM3

func SM2VerifyWithSM3(pubKeyBytes []byte, originData interface{}, sign []byte) error

SM2VerifyWithSM3 使用SM2公钥对数据进行SM3签名验证,返回错误

参数 pubKeyBytes 表示 SM2 公钥,支持以下格式:

  • PEM 编码(例如 "-----BEGIN PUBLIC KEY-----" 块)
  • HEX 字符串格式(128位或130位十六进制字符串)
  • 原始字节数组(64或65字节的公钥数据)

参数 originData 是原始签名数据 参数 sign 是SM2签名结果(ASN.1 DER编码) 如果验证成功返回 nil,验证失败返回错误信息。

Example: ``` priKey, pubKey, _ := codec.Sm2GeneratePemKeyPair() data := "hello world" signature, _ := codec.Sm2SignWithSM3(priKey, data) err := codec.Sm2VerifyWithSM3(pubKey, data, signature)

if err == nil {
   println("签名验证成功")
}else {

   println("签名验证失败:", err.Error())
}

```

func SM3

func SM3(raw interface{}) []byte

func SM4Dec added in v1.3.3

func SM4Dec(key, data, iv []byte, mode string) ([]byte, error)

func SM4DecryptCBCWithPKCSPadding added in v1.3.3

func SM4DecryptCBCWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

SM4DecryptCBCWithPKCSPadding 使用 SM4 算法,在 CBC 模式下,使用 PKCS#7 填充来解密数据 CBC 模式下需要 IV (初始化向量),若为空则会使用 key 的前 16 字节作为 IV。 注意:SM4Decrypt SM4CBCDecrypt 和 SM4DecryptCBCWithPKCSPadding 是同一个函数的别名 Example: ``` codec.SM4DecryptCBCWithPKCSPadding("1234123412341234", "123412341234123456", "1234123412341234") ```

func SM4DecryptCFBWithPKCSPadding added in v1.3.3

func SM4DecryptCFBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

SM4DecryptCFBWithPKCSPadding 使用 SM4 算法,在 CFB 模式下,使用 PKCS#7 填充来解密数据 CFB 模式下需要 IV (初始化向量),若为空则会使用 key 的前 16 字节作为 IV。 注意:SM4CFBDecrypt 和 SM4DecryptCFBWithPKCSPadding 是同一个函数的别名 Example: ``` codec.SM4DecryptCFBWithPKCSPadding("1234123412341234", "123412341234123456", "1234123412341234") ```

func SM4DecryptEBCWithPKCSPadding

func SM4DecryptEBCWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

SM4DecryptECBWithPKCSPadding 使用 SM4 算法,在 ECB 模式下,使用 PKCS#7 填充来解密数据 Deprecated: 请使用 Sm4ECBDecrypt(EBC 是 ECB 的拼写错误)

func SM4DecryptECBWithPKCSPadding added in v1.3.3

func SM4DecryptECBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

SM4DecryptECBWithPKCSPadding 使用 SM4 算法,在 ECB 模式下,使用 PKCS#7 填充来解密数据 ECB 模式下不需要 IV (初始化向量),因此其是一个无用字段。 注意:SM4ECBDecrypt 和 SM4DecryptECBWithPKCSPadding 是同一个函数的别名 Example: ``` codec.SM4DecryptECBWithPKCSPadding("1234123412341234", "123412341234123456", nil) ```

func SM4DecryptOFBWithPKCSPadding added in v1.3.3

func SM4DecryptOFBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

SM4DecryptOFBWithPKCSPadding 使用 SM4 算法,在 OFB 模式下,使用 PKCS#7 填充来解密数据 OFB 模式下需要 IV (初始化向量),若为空则会使用 key 的前 16 字节作为 IV。 注意:SM4OFBDecrypt 和 SM4DecryptOFBWithPKCSPadding 是同一个函数的别名 Example: ``` codec.SM4DecryptOFBWithPKCSPadding("1234123412341234", "123412341234123456", "1234123412341234") ```

func SM4Enc added in v1.3.3

func SM4Enc(key, data, iv []byte, mode string) ([]byte, error)

func SM4EncryptCBCWithPKCSPadding added in v1.3.3

func SM4EncryptCBCWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

SM4EncryptCBCWithPKCSPadding 使用 SM4 算法,在 CBC 模式下,使用 PKCS#7 填充来加密数据 CBC 模式下需要 IV (初始化向量),若为空则会使用 key 的前 16 字节作为 IV。 注意:SM4Encrypt SM4CBCEncrypt 和 SM4EncryptCBCWithPKCSPadding 是同一个函数的别名 Example: ``` codec.SM4EncryptCBCWithPKCSPadding("1234123412341234", "123412341234123456", "1234123412341234") ```

func SM4EncryptCFBWithPKCSPadding added in v1.3.3

func SM4EncryptCFBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

SM4EncryptCFBWithPKCSPadding 使用 SM4 算法,在 CFB 模式下,使用 PKCS#7 填充来加密数据 CFB 模式下需要 IV (初始化向量),若为空则会使用 key 的前 16 字节作为 IV。 注意:SM4CFBEncrypt 和 SM4EncryptCFBWithPKCSPadding 是同一个函数的别名 Example: ``` codec.SM4EncryptCFBWithPKCSPadding("1234123412341234", "123412341234123456", "1234123412341234") ```

func SM4EncryptEBCWithPKCSPadding

func SM4EncryptEBCWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

SM4EncryptECBWithPKCSPadding 使用 SM4 算法,在 ECB 模式下,使用 PKCS#7 填充来加密数据 Deprecated: 请使用 Sm4ECBEncrypt(EBC 是 ECB 的拼写错误)

func SM4EncryptECBWithPKCSPadding added in v1.3.3

func SM4EncryptECBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

SM4EncryptECBWithPKCSPadding 使用 SM4 算法,在 ECB 模式下,使用 PKCS#7 填充来加密数据 ECB 模式下不需要 IV (初始化向量),因此其是一个无用字段。 注意:SM4ECBEncrypt 和 SM4EncryptECBWithPKCSPadding 是同一个函数的别名 Example: ``` codec.SM4EncryptECBWithPKCSPadding("1234123412341234", "123412341234123456", nil) ```

func SM4EncryptOFBWithPKCSPadding added in v1.3.3

func SM4EncryptOFBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

SM4EncryptOFBWithPKCSPadding 使用 SM4 算法,在 OFB 模式下,使用 PKCS#7 填充来加密数据 OFB 模式下需要 IV (初始化向量),若为空则会使用 key 的前 16 字节作为 IV。 注意:SM4OFBEncrypt 和 SM4EncryptOFBWithPKCSPadding 是同一个函数的别名 Example: ``` codec.SM4EncryptOFBWithPKCSPadding("1234123412341234", "123412341234123456", "1234123412341234") ```

func SM4GCMDec

func SM4GCMDec(key []byte, data interface{}, iv []byte) ([]byte, error)

Sm4GCMDecrypt 使用 SM4 算法,在 GCM 模式下解密数据 GCM 模式下需要 IV (初始化向量),若为空则会使用 key 的前 16 字节作为 IV。 Example: ``` codec.Sm4GCMDecrypt("1234123412341234", "123412341234123456", "1234123412341234") ```

func SM4GCMEnc

func SM4GCMEnc(key []byte, data interface{}, iv []byte) ([]byte, error)

Sm4GCMEncrypt 使用 SM4 算法,在 GCM 模式下加密数据 GCM 模式下需要 IV (初始化向量),若为空则会使用 key 的前 16 字节作为 IV。 Example: ``` codec.Sm4GCMEncrypt("1234123412341234", "123412341234123456", "1234123412341234") ```

func SanitizeUTF8

func SanitizeUTF8(v interface{}) error

SanitizeUTF8 escapes invalid UTF-8 characters in a struct or slice.

func Sha1

func Sha1(i interface{}) string

func Sha224

func Sha224(i interface{}) string

func Sha256

func Sha256(i interface{}) string

func Sha384

func Sha384(i interface{}) string

func Sha512

func Sha512(i interface{}) string

func ShrinkString

func ShrinkString(r any, size int) string

func ShrinkStringDefault

func ShrinkStringDefault(r any) string

func ShrinkTextBlock

func ShrinkTextBlock(r any, size int) string

func StrConvQuoteHex

func StrConvQuoteHex(s string) string

func StrConvUnquoteForce added in v1.2.8

func StrConvUnquoteForce(s string) []byte

func StringArrayUtf8SafeEscape

func StringArrayUtf8SafeEscape(strArray []string) []string

func StringUtf8SafeEscape

func StringUtf8SafeEscape(str string) string

func TripleDESDecryptCBCWithZeroPadding added in v1.3.3

func TripleDESDecryptCBCWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

TripleDESCBCDecrypt 是一个便捷函数,用于使用 Triple DES 算法,在 CBC 模式下,使用 零填充来解密数据。 它接受一个密钥(key)、需要解密的数据(data to decrypt)和一个初始化向量(iv)。 密钥的长度必须是 24 个字节(即 3 * 8 字节),并且 iv 可以是 nil 或者 8 个字节长。 如果 iv 为 nil,它将被固定为密钥,或者用零填充到 8 个字节。 TripleDESCBCDecrypt TripleDESDecrypt 是同一个函数。 example: ``` codec.TripleDESCBCDecrypt([]byte("123456789012345678901234"), ciphertext, "12345678") ```

func TripleDESEncryptCBCWithZeroPadding added in v1.3.3

func TripleDESEncryptCBCWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)

TripleDESCBCEncrypt 是一个便捷函数,用于使用 Triple DES 算法,在 CBC 模式下,使用 零填充来加密数据。 它接受一个密钥(key)、需要加密的数据(data to encrypt)和一个初始化向量(iv)。 密钥的长度必须是 24 个字节(即 3 * 8 字节),并且 iv 可以是 nil 或者 8 个字节长。 如果 iv 为 nil,它将被固定为密钥. TripleDESCBCDecrypt TripleDESEncrypt 是同一个函数。 example: ``` codec.TripleDESCBCEncrypt([]byte("123456789012345678901234"), "hello world", "12345678") ```

func TripleDES_ECBDec added in v1.2.4

func TripleDES_ECBDec(key []byte, data []byte) ([]byte, error)

TripleDESECBDecrypt 是一个便捷函数,用于使用 Triple DES 算法,在 ECB 模式下,使用 零填充来解密数据。 它接受一个密钥(key)、需要解密的数据(data to decrypt)(ecb 模式下 iv 无用) 密钥的长度必须是 24 个字节(即 3 * 8 字节)。 example: ``` codec.TripleDESECBDecrypt([]byte("123456789012345678901234"), ciphertext) ```

func TripleDES_ECBEnc added in v1.2.4

func TripleDES_ECBEnc(key []byte, data []byte) ([]byte, error)

TripleDESECBEncrypt 是一个便捷函数,用于使用 Triple DES 算法,在 ECB 模式下,使用 零填充来加密数据。 它接受一个密钥(key)、需要加密的数据(data to encrypt)(ecb 模式下 iv 无用) 密钥的长度必须是 24 个字节(即 3 * 8 字节)。 example: ``` codec.TripleDESECBEncrypt([]byte("123456789012345678901234"), "hello world") ```

func TripleDesDec added in v1.3.3

func TripleDesDec(key []byte, data []byte, iv []byte, mode string) ([]byte, error)

func TripleDesEnc added in v1.3.3

func TripleDesEnc(key []byte, data []byte, iv []byte, mode string) ([]byte, error)

func UTF8AndControlEscapeForEditorView added in v1.3.3

func UTF8AndControlEscapeForEditorView(i any) string

UTF8AndControlEscapeForEditorView will remove some unfriendly chars for editor

func UTF8SafeEscape added in v1.3.3

func UTF8SafeEscape(i any) string

func UrlUnicodeDecode added in v1.2.9

func UrlUnicodeDecode(s string) string

func Utf8ToGB18030

func Utf8ToGB18030(s []byte) ([]byte, error)

func Utf8ToGbk

func Utf8ToGbk(s []byte) ([]byte, error)

func Utf8ToHZGB2312

func Utf8ToHZGB2312(s []byte) ([]byte, error)

func ZeroPadding

func ZeroPadding(origin []byte, blockSize int) []byte

func ZeroUnPadding

func ZeroUnPadding(originData []byte) []byte

Types

type AutoDecodeResult

type AutoDecodeResult struct {
	Type        string
	TypeVerbose string
	Origin      string
	Result      string
}

func AutoDecode

func AutoDecode(i interface{}) []*AutoDecodeResult

type CmacBuilder added in v1.3.3

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

func New added in v1.3.3

func New(newCipher NewCipherFunc, key []byte) (*CmacBuilder, error)

New returns a new CMAC hash using the given cipher instantiation function and key.

func (*CmacBuilder) BlockSize added in v1.3.3

func (c *CmacBuilder) BlockSize() int

func (*CmacBuilder) Reset added in v1.3.3

func (c *CmacBuilder) Reset()

Reset the the CMAC

func (*CmacBuilder) Size added in v1.3.3

func (c *CmacBuilder) Size() int

func (*CmacBuilder) Sum added in v1.3.3

func (c *CmacBuilder) Sum(m []byte) []byte

Sum returns the CMAC appended to m. m may be nil. Write may be called after Sum.

func (*CmacBuilder) Write added in v1.3.3

func (c *CmacBuilder) Write(m []byte) (n int, err error)

Write accumulates the bytes in m in the cmac computation.

type EncodedFunc added in v1.3.3

type EncodedFunc func(any) string

type FileReader

type FileReader interface {
	io.Reader
	io.Seeker
	Stat() (fs.FileInfo, error)
}

FileReader 定义了统一的文件读取接口,os.File 和 memfile.File 都实现了这个接口

type KeyDerivationFunc

type KeyDerivationFunc func(password, salt []byte) ([]byte, []byte, error)

func NewBytesToKeyGenerator

func NewBytesToKeyGenerator(hashFunc func() hash.Hash, iterations int) KeyDerivationFunc

func NewPBKDF2Generator

func NewPBKDF2Generator(hashFunc func() hash.Hash, iterations int) KeyDerivationFunc

type MIMEResult

type MIMEResult struct {
	MIMEType    string
	IsText      bool
	NeedCharset bool
	Charset     string
}

func MatchMIMEType

func MatchMIMEType(raw any) (*MIMEResult, error)

MatchMIMEType will match via bytes note: if the raw input is overlarge, check the first n(4k) bytes to detect question: fix the tail, if the raw input is text (not structured file)

func (*MIMEResult) IsChineseCharset

func (t *MIMEResult) IsChineseCharset() bool

func (*MIMEResult) TryUTF8Convertor

func (t *MIMEResult) TryUTF8Convertor(raw []byte) ([]byte, bool)

type NewCipherFunc added in v1.3.3

type NewCipherFunc func(key []byte) (cipher.Block, error)

NewCipherFunc instantiates a block cipher

type PrescanResult

type PrescanResult struct {
	Encoding encoding.Encoding
	Name     string
}

type SymmetricCryptFunc added in v1.3.3

type SymmetricCryptFunc func(key []byte, i interface{}, iv []byte) ([]byte, error)

func AESDecFactory added in v1.3.3

func AESDecFactory(paddingFunc func([]byte, int) []byte, unpaddingFunc func([]byte) []byte, mode string) SymmetricCryptFunc

func AESEncFactory added in v1.3.3

func AESEncFactory(paddingFunc func([]byte, int) []byte, mode string) SymmetricCryptFunc

func DESDecFactory added in v1.3.3

func DESDecFactory(unpaddingFunc func([]byte) []byte, mode string) SymmetricCryptFunc

func DESEncFactory added in v1.3.3

func DESEncFactory(paddingFunc func([]byte, int) []byte, mode string) SymmetricCryptFunc

func SM4DecFactory added in v1.3.3

func SM4DecFactory(unpaddingFunc func([]byte) []byte, mode string) SymmetricCryptFunc

func SM4EncFactory added in v1.3.3

func SM4EncFactory(paddingFunc func([]byte, int) []byte, mode string) SymmetricCryptFunc

func TripleDESDecFactory added in v1.3.3

func TripleDESDecFactory(unpaddingFunc func([]byte) []byte, mode string) SymmetricCryptFunc

func TripleDESEncFactory added in v1.3.3

func TripleDESEncFactory(paddingFunc func([]byte, int) []byte, mode string) SymmetricCryptFunc

Directories

Path Synopsis
doc command

Jump to

Keyboard shortcuts

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