Documentation
¶
Index ¶
- Constants
- Variables
- func AESDec(key []byte, data []byte, iv []byte, mode string) ([]byte, error)
- func AESDecWithPassphrase(passphrase, data, salt []byte, KDF KeyDerivationFunc, aesMode string) ([]byte, error)
- func AESDecryptCBCWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func AESDecryptCBCWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func AESDecryptCFBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func AESDecryptCFBWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func AESDecryptECBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func AESDecryptECBWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func AESEnc(key []byte, data []byte, iv []byte, mode string) ([]byte, error)
- func AESEncWithPassphrase(passphrase, data, salt []byte, KDF KeyDerivationFunc, aesMode string) ([]byte, error)
- func AESEncryptCBCWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func AESEncryptCBCWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func AESEncryptCFBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func AESEncryptCFBWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func AESEncryptECBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func AESEncryptECBWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func AESGCMDecrypt(key []byte, data interface{}, nonce []byte) ([]byte, error)
- func AESGCMDecryptWithNonceSize(key []byte, data interface{}, nonceRaw []byte, nonceSize int) ([]byte, error)
- func AESGCMDecryptWithNonceSize12(key []byte, data interface{}, nonce []byte) ([]byte, error)
- func AESGCMDecryptWithNonceSize16(key []byte, data interface{}, nonce []byte) ([]byte, error)
- func AESGCMEncrypt(key []byte, data interface{}, nonceRaw []byte) ([]byte, error)
- func AESGCMEncryptWithNonceSize(key []byte, data interface{}, nonceRaw []byte, nonceSize int) ([]byte, error)
- func AESGCMEncryptWithNonceSize12(key []byte, data interface{}, nonceRaw []byte) ([]byte, error)
- func AllASCII(i any) bool
- func AnyToBytes(i interface{}) (result []byte)
- func AnyToString(i interface{}) (result string)
- func Atob(i string) bool
- func Atof(i string) float64
- func Atoi(i string) int
- func Atoi64(i string) int64
- func Base32Padding(i string) string
- func Base64Padding(i string) string
- func BlockCheck(iv, data []byte, blockSize int) error
- func CBCDecode(c cipher.Block, iv, data []byte) ([]byte, error)
- func CBCEncode(c cipher.Block, iv, data []byte) ([]byte, error)
- func CFBDecode(c cipher.Block, iv, data []byte) ([]byte, error)
- func CFBEncode(c cipher.Block, iv, data []byte) ([]byte, error)
- func CTRDecode(c cipher.Block, iv, data []byte) ([]byte, error)
- func CTREncode(c cipher.Block, iv, data []byte) ([]byte, error)
- func CharDetect(raw interface{}) ([]chardet.Result, error)
- func CharDetectBest(raw interface{}) (*chardet.Result, error)
- func Cmac(alg string, key []byte, message []byte) ([]byte, error)
- func DESDec(key []byte, data []byte, iv []byte, mode string) ([]byte, error)
- func DESDecryptCBCWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func DESECBDec(key []byte, data []byte) ([]byte, error)
- func DESECBEnc(key []byte, data []byte) ([]byte, error)
- func DESEnc(key []byte, data []byte, iv []byte, mode string) ([]byte, error)
- func DESEncryptCBCWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func DESEncryptECBWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func DecodeBase32(i string) ([]byte, error)
- func DecodeBase64(i string) ([]byte, error)
- func DecodeBase64Url(i interface{}) ([]byte, error)
- func DecodeHex(i string) ([]byte, error)
- func Decodebig5(s []byte) ([]byte, error)
- func Decodegbk(s []byte) ([]byte, error)
- func ECBDecode(c cipher.Block, data []byte) ([]byte, error)
- func ECBEncode(c cipher.Block, data []byte) ([]byte, error)
- func EncodeBase32(i interface{}) string
- func EncodeBase64(i interface{}) string
- func EncodeBase64Url(i interface{}) string
- func EncodeByType(t string, i interface{}) string
- func EncodeHtmlEntity(i interface{}) string
- func EncodeHtmlEntityEx(i interface{}, encodeType string, fullEncode bool) string
- func EncodeHtmlEntityHex(i interface{}) string
- func EncodeToHex(i interface{}) string
- func EncodeUrlCode(i interface{}) string
- func Encodebig5(s []byte) ([]byte, error)
- func Equal(mac1, mac2 []byte) bool
- func EscapeInvalidUTF8Byte(s []byte) string
- func FixIV(iv, key []byte, blockSize int) []byte
- func ForceQueryUnescape(s string) string
- func GB18030ToUtf8(s []byte) ([]byte, error)
- func GBKSafeString(s []byte) (string, error)
- func GbkToUtf8(s []byte) ([]byte, error)
- func GenerateSM2PrivateKeyHEX() ([]byte, []byte, error)
- func GenerateSM2PrivateKeyPEM() ([]byte, []byte, error)
- func HTTPChunkedDecode(raw []byte) ([]byte, error)
- func HTTPChunkedDecodeWithRestBytes(raw []byte) ([]byte, []byte)
- func HTTPChunkedDecoderWithRestBytes(raw io.Reader) ([]byte, []byte, io.Reader, error)
- func HTTPChunkedEncode(raw []byte) []byte
- func HZGB2312ToUtf8(s []byte) ([]byte, error)
- func HmacMD5(key, data interface{}) []byte
- func HmacSM3(key, data interface{}) []byte
- func HmacSha1(key, data interface{}) []byte
- func HmacSha256(key, data interface{}) []byte
- func HmacSha512(key, data interface{}) []byte
- func HtmlCharsetPrescan(content []byte, callback ...func(start, end int, matched PrescanResult)) (e encoding.Encoding, name string)
- func IsControl(r rune) bool
- func IsGBK(data []byte) bool
- func IsUTF8(i any) (bool, error)
- func IsUTF8File(filename string) (bool, error)
- func IsUtf8(data []byte) bool
- func Itoa(i int) string
- func JsonUnicodeDecode(i string) string
- func JsonUnicodeEncode(i string) string
- func MMH3Hash128(i interface{}) string
- func MMH3Hash128x64(i interface{}) string
- func MMH3Hash32(i interface{}) int64
- func Md5(i interface{}) string
- func MustPKCS5UnPadding(origData []byte) ([]byte, error)
- func OFBDecode(c cipher.Block, iv, data []byte) ([]byte, error)
- func OFBEncode(c cipher.Block, iv, data []byte) ([]byte, error)
- func PKCS5Padding(ciphertext []byte, blockSize int) []byte
- func PKCS5UnPadding(origData []byte) []byte
- func PKCS7PaddingFor8ByteBlock(src []byte) []byte
- func PKCS7UnPaddingFor8ByteBlock(src []byte) []byte
- func PathUnescape(s string) (string, error)
- func QueryEscape(s string) string
- func QueryUnescape(s string) (string, error)
- func RC4Decrypt(cipherKey []byte, cipherText []byte) ([]byte, error)
- func RC4Encrypt(cipherKey []byte, plainText []byte) ([]byte, error)
- func RandBytes(n int) []byte
- func RandomUpperAndLower(s string) string
- func ReadChunkedStream(r io.Reader) (io.Reader, io.Reader, error)
- func ReadHTTPChunkedDataWithFixed(raw []byte) (data []byte, fixedChunked []byte, rest []byte)
- func ReadHTTPChunkedDataWithFixedError(raw []byte) (data []byte, fixedChunked []byte, rest []byte, _ error)
- func SM2DecryptASN1(priKey []byte, data []byte) ([]byte, error)
- func SM2DecryptASN1WithPassword(priKey []byte, data []byte, password []byte) ([]byte, error)
- func SM2DecryptC1C2C3(priKey []byte, data []byte) ([]byte, error)
- func SM2DecryptC1C2C3WithPassword(priKey []byte, data []byte, password []byte) ([]byte, error)
- func SM2DecryptC1C3C2(priKey []byte, data []byte) ([]byte, error)
- func SM2DecryptC1C3C2WithPassword(priKey []byte, data []byte, password []byte) ([]byte, error)
- func SM2EncryptASN1(pubKey []byte, data []byte) ([]byte, error)
- func SM2EncryptC1C2C3(pubKey []byte, data []byte) ([]byte, error)
- func SM2EncryptC1C3C2(pubKey []byte, data []byte) ([]byte, error)
- func SM2GenerateTemporaryKeyPair() ([]byte, []byte, error)
- func SM2KeyExchange(keyLength int, idA, idB, priKey, pubKey, tempPriKey, tempPubKey []byte, ...) ([]byte, []byte, []byte, error)
- func SM2SignWithSM3(priKeyBytes []byte, data interface{}) ([]byte, error)
- func SM2SignWithSM3WithPassword(priKeyBytes []byte, data interface{}, password []byte) ([]byte, error)
- func SM2VerifyWithSM3(pubKeyBytes []byte, originData interface{}, sign []byte) error
- func SM3(raw interface{}) []byte
- func SM4Dec(key, data, iv []byte, mode string) ([]byte, error)
- func SM4DecryptCBCWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func SM4DecryptCFBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func SM4DecryptEBCWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func SM4DecryptECBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func SM4DecryptOFBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func SM4Enc(key, data, iv []byte, mode string) ([]byte, error)
- func SM4EncryptCBCWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func SM4EncryptCFBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func SM4EncryptEBCWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func SM4EncryptECBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func SM4EncryptOFBWithPKCSPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func SM4GCMDec(key []byte, data interface{}, iv []byte) ([]byte, error)
- func SM4GCMEnc(key []byte, data interface{}, iv []byte) ([]byte, error)
- func SanitizeUTF8(v interface{}) error
- func Sha1(i interface{}) string
- func Sha224(i interface{}) string
- func Sha256(i interface{}) string
- func Sha384(i interface{}) string
- func Sha512(i interface{}) string
- func ShrinkString(r any, size int) string
- func ShrinkStringDefault(r any) string
- func ShrinkTextBlock(r any, size int) string
- func StrConvQuoteHex(s string) string
- func StrConvUnquoteForce(s string) []byte
- func StringArrayUtf8SafeEscape(strArray []string) []string
- func StringUtf8SafeEscape(str string) string
- func TripleDESDecryptCBCWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func TripleDESEncryptCBCWithZeroPadding(key []byte, i interface{}, iv []byte) ([]byte, error)
- func TripleDES_ECBDec(key []byte, data []byte) ([]byte, error)
- func TripleDES_ECBEnc(key []byte, data []byte) ([]byte, error)
- func TripleDesDec(key []byte, data []byte, iv []byte, mode string) ([]byte, error)
- func TripleDesEnc(key []byte, data []byte, iv []byte, mode string) ([]byte, error)
- func UTF8AndControlEscapeForEditorView(i any) string
- func UTF8SafeEscape(i any) string
- func UrlUnicodeDecode(s string) string
- func Utf8ToGB18030(s []byte) ([]byte, error)
- func Utf8ToGbk(s []byte) ([]byte, error)
- func Utf8ToHZGB2312(s []byte) ([]byte, error)
- func ZeroPadding(origin []byte, blockSize int) []byte
- func ZeroUnPadding(originData []byte) []byte
- type AutoDecodeResult
- type CmacBuilder
- type EncodedFunc
- type FileReader
- type KeyDerivationFunc
- type MIMEResult
- type NewCipherFunc
- type PrescanResult
- type SymmetricCryptFunc
- func AESDecFactory(paddingFunc func([]byte, int) []byte, unpaddingFunc func([]byte) []byte, ...) SymmetricCryptFunc
- func AESEncFactory(paddingFunc func([]byte, int) []byte, mode string) SymmetricCryptFunc
- func DESDecFactory(unpaddingFunc func([]byte) []byte, mode string) SymmetricCryptFunc
- func DESEncFactory(paddingFunc func([]byte, int) []byte, mode string) SymmetricCryptFunc
- func SM4DecFactory(unpaddingFunc func([]byte) []byte, mode string) SymmetricCryptFunc
- func SM4EncFactory(paddingFunc func([]byte, int) []byte, mode string) SymmetricCryptFunc
- func TripleDESDecFactory(unpaddingFunc func([]byte) []byte, mode string) SymmetricCryptFunc
- func TripleDESEncFactory(paddingFunc func([]byte, int) []byte, mode string) SymmetricCryptFunc
Constants ¶
const DefaultBytesToKeyIterations = 1
const DefaultPBKDF2Iterations = 10000
Variables ¶
var ( EscapeHtmlString = html.EscapeString UnescapeHtmlString = html.UnescapeString StrConvUnquote = strconv.Unquote StrConvQuote = strconv.Quote )
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) )
var ( CBC = "CBC" ECB = "ECB" CFB = "CFB" OFB = "OFB" CTR = "CTR" )
var AESCBCDecrypt = AESDecryptCBCWithPKCSPadding
var AESCBCEncrypt = AESEncryptCBCWithPKCSPadding
var AESECBDecrypt = AESDecryptECBWithPKCSPadding
var AESECBEncrypt = AESEncryptECBWithPKCSPadding
var AESGCMEncryptWithNonceSize16 = AESGCMEncrypt
var DESDecryptCBCWithPKCSPadding = DESDecFactory(PKCS5UnPadding, CBC)
var DESDecryptECBWithPKCSPadding = DESDecFactory(PKCS5UnPadding, ECB)
var DESDecryptECBWithZeroPadding = DESDecFactory(ZeroUnPadding, ECB)
var DESEncryptCBCWithPKCSPadding = DESEncFactory(PKCS5Padding, CBC)
Des
var DESEncryptECBWithPKCSPadding = DESEncFactory(PKCS5Padding, ECB)
var DoubleDecodeUrl = func(i string) (string, error) { raw, err := url.QueryUnescape(i) if err != nil { return "", err } return url.QueryUnescape(raw) }
var DoubleEncodeUrl = func(i interface{}) string { return url.QueryEscape(EncodeUrlCode(i)) }
var PKCS7Padding = sm4.PKCS7Padding
var PKCS7UnPadding = sm4.PKCS7UnPadding
var PathEscape = url.PathEscape
var SM4DecryptCBCWithZeroPadding = SM4DecFactory(ZeroUnPadding, CBC)
var SM4DecryptCFBWithZeroPadding = SM4DecFactory(ZeroUnPadding, CFB)
var SM4DecryptCTRWithPKCSPadding = SM4DecFactory(PKCS5UnPadding, CTR)
var SM4DecryptCTRWithZeroPadding = SM4DecFactory(ZeroUnPadding, CTR)
var SM4DecryptECBWithZeroPadding = SM4DecFactory(ZeroUnPadding, ECB)
var SM4DecryptOFBWithZeroPadding = SM4DecFactory(ZeroUnPadding, OFB)
var SM4EncryptCBCWithZeroPadding = SM4EncFactory(ZeroPadding, CBC)
other func
var SM4EncryptCFBWithZeroPadding = SM4EncFactory(ZeroPadding, CFB)
var SM4EncryptCTRWithPKCSPadding = SM4EncFactory(PKCS5Padding, CTR)
var SM4EncryptCTRWithZeroPadding = SM4EncFactory(ZeroPadding, CTR)
var SM4EncryptECBWithZeroPadding = SM4EncFactory(ZeroPadding, ECB)
var SM4EncryptOFBWithZeroPadding = SM4EncFactory(ZeroPadding, OFB)
var SM4GCMDecrypt = SM4GCMDec
var SM4GCMEncrypt = SM4GCMEnc
var TripleDESDecryptCBCWithPKCSPadding = TripleDESDecFactory(PKCS5UnPadding, CBC)
var TripleDESDecryptECBWithPKCSPadding = TripleDESDecFactory(PKCS5UnPadding, ECB)
var TripleDESDecryptECBWithZeroPadding = TripleDESDecFactory(ZeroUnPadding, ECB)
var TripleDESEncryptCBCWithPKCSPadding = TripleDESEncFactory(PKCS5Padding, CBC)
TripleDes
var TripleDESEncryptECBWithPKCSPadding = TripleDESEncFactory(PKCS5Padding, ECB)
var TripleDESEncryptECBWithZeroPadding = TripleDESEncFactory(ZeroPadding, ECB)
Functions ¶
func AESDec ¶ added in v1.3.3
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
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
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 ¶
AESCFBDecryptWithPKCS7Padding 使用 AES 算法,在 CFB 模式下,使用 PKCS5 填充来解密数据。 密钥的长度必须是 16、24 或 32 字节(分别对应 AES-128、AES-192 或 AES-256)。 如果iv为 nil,则使用key的前16字节作为iv。
func AESDecryptCFBWithZeroPadding ¶
AESCFBDecryptWithZeroPadding 使用 AES 算法,在 CFB 模式下,使用 Zero 填充来解密数据。
func AESDecryptECBWithPKCSPadding ¶ added in v1.3.3
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
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
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
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
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 ¶
AESEncryptCFBWithPKCSPadding 使用 AES 算法,在 CFB 模式下,使用 PKCS5 填充来加密数据。 密钥的长度必须是 16、24 或 32 字节(分别对应 AES-128、AES-192 或 AES-256)。 如果iv为 nil,则使用key的前16字节作为iv。
func AESEncryptCFBWithZeroPadding ¶
AESCFBEncryptWithZeroPadding 使用 AES 算法,在 CFB 模式下,使用 Zero 填充来加密数据。
func AESEncryptECBWithPKCSPadding ¶ added in v1.3.3
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
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 AESGCMEncrypt ¶
//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 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 Base32Padding ¶
func Base64Padding ¶
func BlockCheck ¶ added in v1.3.3
func CharDetect ¶
func CharDetectBest ¶
func DESDecryptCBCWithZeroPadding ¶ added in v1.3.3
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 ¶
DESECBDecrypt 是一个便捷函数,用于使用 DES 算法,在 ECB 模式下,使用 零填充来解密数据。 它接受一个密钥(key)、需要解密的数据(data to decrypt)(ecb 模式下 iv 无用) 密钥的长度必须是 8 个字节。 example: ``` codec.DESECBDecrypt([]byte("12345678"), ciphertext) ```
func DESECBEnc ¶
DESECBEncrypt 是一个便捷函数,用于使用 DES 算法,在 ECB 模式下,使用 零填充来加密数据。 它接受一个密钥(key)、需要加密的数据(data to encrypt)(ecb 模式下 iv 无用) 密钥的长度必须是 8 个字节。 example: ``` codec.DESECBEncrypt([]byte("12345678"), "hello world") ```
func DESEncryptCBCWithZeroPadding ¶ added in v1.3.3
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
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 DecodeBase64 ¶
func DecodeBase64Url ¶
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 EncodeHtmlEntity ¶
func EncodeHtmlEntity(i interface{}) string
func EncodeHtmlEntityEx ¶ added in v1.3.1
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 Equal ¶ added in v1.3.3
Equal compares two MACs for equality without leaking timing information.
func EscapeInvalidUTF8Byte ¶
func ForceQueryUnescape ¶ added in v1.2.8
func GB18030ToUtf8 ¶
func GBKSafeString ¶
func HTTPChunkedDecode ¶
func HTTPChunkedDecodeWithRestBytes ¶ added in v1.2.6
func HTTPChunkedDecoderWithRestBytes ¶ added in v1.2.6
func HTTPChunkedEncode ¶
func HZGB2312ToUtf8 ¶
func HmacSha256 ¶
func HmacSha256(key, data interface{}) []byte
func HmacSha512 ¶
func HmacSha512(key, data interface{}) []byte
func HtmlCharsetPrescan ¶
func IsUTF8File ¶
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 JsonUnicodeDecode ¶
func JsonUnicodeEncode ¶
func MMH3Hash128 ¶
func MMH3Hash128(i interface{}) string
func MMH3Hash128x64 ¶
func MMH3Hash128x64(i interface{}) string
func MMH3Hash32 ¶
func MMH3Hash32(i interface{}) int64
func MustPKCS5UnPadding ¶ added in v1.2.2
func PKCS5Padding ¶
func PKCS5UnPadding ¶
func PKCS7PaddingFor8ByteBlock ¶ added in v1.3.3
func PKCS7UnPaddingFor8ByteBlock ¶ added in v1.3.3
func PathUnescape ¶
func QueryEscape ¶
func QueryUnescape ¶
func RandomUpperAndLower ¶
func ReadHTTPChunkedDataWithFixed ¶ added in v1.2.6
func ReadHTTPChunkedDataWithFixedError ¶ added in v1.3.3
func SM2GenerateTemporaryKeyPair ¶
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 ¶
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 ¶
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 SM4DecryptCBCWithPKCSPadding ¶ added in v1.3.3
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
SM4DecryptCFBWithPKCSPadding 使用 SM4 算法,在 CFB 模式下,使用 PKCS#7 填充来解密数据 CFB 模式下需要 IV (初始化向量),若为空则会使用 key 的前 16 字节作为 IV。 注意:SM4CFBDecrypt 和 SM4DecryptCFBWithPKCSPadding 是同一个函数的别名 Example: ``` codec.SM4DecryptCFBWithPKCSPadding("1234123412341234", "123412341234123456", "1234123412341234") ```
func SM4DecryptEBCWithPKCSPadding ¶
SM4DecryptECBWithPKCSPadding 使用 SM4 算法,在 ECB 模式下,使用 PKCS#7 填充来解密数据 Deprecated: 请使用 Sm4ECBDecrypt(EBC 是 ECB 的拼写错误)
func SM4DecryptECBWithPKCSPadding ¶ added in v1.3.3
SM4DecryptECBWithPKCSPadding 使用 SM4 算法,在 ECB 模式下,使用 PKCS#7 填充来解密数据 ECB 模式下不需要 IV (初始化向量),因此其是一个无用字段。 注意:SM4ECBDecrypt 和 SM4DecryptECBWithPKCSPadding 是同一个函数的别名 Example: ``` codec.SM4DecryptECBWithPKCSPadding("1234123412341234", "123412341234123456", nil) ```
func SM4DecryptOFBWithPKCSPadding ¶ added in v1.3.3
SM4DecryptOFBWithPKCSPadding 使用 SM4 算法,在 OFB 模式下,使用 PKCS#7 填充来解密数据 OFB 模式下需要 IV (初始化向量),若为空则会使用 key 的前 16 字节作为 IV。 注意:SM4OFBDecrypt 和 SM4DecryptOFBWithPKCSPadding 是同一个函数的别名 Example: ``` codec.SM4DecryptOFBWithPKCSPadding("1234123412341234", "123412341234123456", "1234123412341234") ```
func SM4EncryptCBCWithPKCSPadding ¶ added in v1.3.3
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
SM4EncryptCFBWithPKCSPadding 使用 SM4 算法,在 CFB 模式下,使用 PKCS#7 填充来加密数据 CFB 模式下需要 IV (初始化向量),若为空则会使用 key 的前 16 字节作为 IV。 注意:SM4CFBEncrypt 和 SM4EncryptCFBWithPKCSPadding 是同一个函数的别名 Example: ``` codec.SM4EncryptCFBWithPKCSPadding("1234123412341234", "123412341234123456", "1234123412341234") ```
func SM4EncryptEBCWithPKCSPadding ¶
SM4EncryptECBWithPKCSPadding 使用 SM4 算法,在 ECB 模式下,使用 PKCS#7 填充来加密数据 Deprecated: 请使用 Sm4ECBEncrypt(EBC 是 ECB 的拼写错误)
func SM4EncryptECBWithPKCSPadding ¶ added in v1.3.3
SM4EncryptECBWithPKCSPadding 使用 SM4 算法,在 ECB 模式下,使用 PKCS#7 填充来加密数据 ECB 模式下不需要 IV (初始化向量),因此其是一个无用字段。 注意:SM4ECBEncrypt 和 SM4EncryptECBWithPKCSPadding 是同一个函数的别名 Example: ``` codec.SM4EncryptECBWithPKCSPadding("1234123412341234", "123412341234123456", nil) ```
func SM4EncryptOFBWithPKCSPadding ¶ added in v1.3.3
SM4EncryptOFBWithPKCSPadding 使用 SM4 算法,在 OFB 模式下,使用 PKCS#7 填充来加密数据 OFB 模式下需要 IV (初始化向量),若为空则会使用 key 的前 16 字节作为 IV。 注意:SM4OFBEncrypt 和 SM4EncryptOFBWithPKCSPadding 是同一个函数的别名 Example: ``` codec.SM4EncryptOFBWithPKCSPadding("1234123412341234", "123412341234123456", "1234123412341234") ```
func SM4GCMDec ¶
Sm4GCMDecrypt 使用 SM4 算法,在 GCM 模式下解密数据 GCM 模式下需要 IV (初始化向量),若为空则会使用 key 的前 16 字节作为 IV。 Example: ``` codec.Sm4GCMDecrypt("1234123412341234", "123412341234123456", "1234123412341234") ```
func SM4GCMEnc ¶
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 ShrinkString ¶
func ShrinkStringDefault ¶
func ShrinkTextBlock ¶
func StrConvQuoteHex ¶
func StrConvUnquoteForce ¶ added in v1.2.8
func StringUtf8SafeEscape ¶
func TripleDESDecryptCBCWithZeroPadding ¶ added in v1.3.3
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
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
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
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 TripleDesEnc ¶ added in v1.3.3
func UTF8AndControlEscapeForEditorView ¶ added in v1.3.3
UTF8AndControlEscapeForEditorView will remove some unfriendly chars for editor
func UTF8SafeEscape ¶ added in v1.3.3
func UrlUnicodeDecode ¶ added in v1.2.9
func Utf8ToGB18030 ¶
func Utf8ToHZGB2312 ¶
func ZeroPadding ¶
func ZeroUnPadding ¶
Types ¶
type AutoDecodeResult ¶
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) 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.
type EncodedFunc ¶ added in v1.3.3
type FileReader ¶
FileReader 定义了统一的文件读取接口,os.File 和 memfile.File 都实现了这个接口
type KeyDerivationFunc ¶
func NewBytesToKeyGenerator ¶
func NewBytesToKeyGenerator(hashFunc func() hash.Hash, iterations int) KeyDerivationFunc
func NewPBKDF2Generator ¶
func NewPBKDF2Generator(hashFunc func() hash.Hash, iterations int) KeyDerivationFunc
type MIMEResult ¶
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
NewCipherFunc instantiates a block cipher
type PrescanResult ¶
type SymmetricCryptFunc ¶ added in v1.3.3
func AESDecFactory ¶ added in v1.3.3
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