codec

package
v1.3.6-beta5 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: AGPL-3.0 Imports: 52 Imported by: 2

Documentation

Index

Constants

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

Variables

View Source
var (
	EscapeHtmlString   = html.EscapeString
	UnescapeHtmlString = html.UnescapeString
	StrConvQuote       = func(s string) string {
		raw := []byte(s)
		var buf bytes.Buffer
		buf.WriteString("\"")
		for _, b := range raw {
			switch true {
			case b >= 'a' && b <= 'z':
				fallthrough
			case b >= 'A' && b <= 'Z':
				fallthrough
			case b >= '0' && b <= '9':
				buf.WriteByte(b)
			default:
				buf.WriteString(fmt.Sprintf(`\x%02x`, b))
			}
		}
		buf.WriteString("\"")
		return buf.String()
	}
)
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 AESDecryptCBCWithPKCSPadding = AESDecFactory(PKCS5UnPadding, CBC)
View Source
var AESDecryptCBCWithZeroPadding = AESDecFactory(ZeroUnPadding, CBC)
View Source
var AESDecryptECBWithPKCSPadding = AESDecFactory(PKCS5UnPadding, ECB)
View Source
var AESDecryptECBWithZeroPadding = AESDecFactory(ZeroUnPadding, ECB)
View Source
var AESEncryptCBCWithPKCSPadding = AESEncFactory(PKCS5Padding, CBC)
View Source
var AESEncryptCBCWithZeroPadding = AESEncFactory(ZeroPadding, CBC)
View Source
var AESEncryptECBWithPKCSPadding = AESEncFactory(PKCS5Padding, ECB)
View Source
var AESEncryptECBWithZeroPadding = AESEncFactory(ZeroPadding, ECB)
View Source
var AESGCMEncryptWithNonceSize16 = AESGCMEncrypt
View Source
var DESDecryptCBCWithPKCSPadding = DESDecFactory(PKCS5UnPadding, CBC)
View Source
var DESDecryptCBCWithZeroPadding = DESDecFactory(ZeroUnPadding, 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 DESEncryptCBCWithZeroPadding = DESEncFactory(ZeroPadding, CBC)
View Source
var DESEncryptECBWithPKCSPadding = DESEncFactory(PKCS5Padding, ECB)
View Source
var DESEncryptECBWithZeroPadding = DESEncFactory(ZeroPadding, 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 SM4DecryptCBCWithPKCSPadding = SM4DecFactory(PKCS5UnPadding, CBC)
View Source
var SM4DecryptCBCWithZeroPadding = SM4DecFactory(ZeroUnPadding, CBC)
View Source
var SM4DecryptCFBWithPKCSPadding = SM4DecFactory(PKCS5UnPadding, CFB)
View Source
var SM4DecryptCFBWithZeroPadding = SM4DecFactory(ZeroUnPadding, CFB)
View Source
var SM4DecryptCTRWithPKCSPadding = SM4DecFactory(PKCS5UnPadding, CTR)
View Source
var SM4DecryptCTRWithZeroPadding = SM4DecFactory(ZeroUnPadding, CTR)
View Source
var SM4DecryptECBWithPKCSPadding = SM4DecFactory(PKCS5UnPadding, ECB)
View Source
var SM4DecryptECBWithZeroPadding = SM4DecFactory(ZeroUnPadding, ECB)
View Source
var SM4DecryptOFBWithPKCSPadding = SM4DecFactory(PKCS5UnPadding, OFB)
View Source
var SM4DecryptOFBWithZeroPadding = SM4DecFactory(ZeroUnPadding, OFB)
View Source
var SM4EncryptCBCWithPKCSPadding = SM4EncFactory(PKCS5Padding, CBC)

Construct functions corresponding to various encryption modes

View Source
var SM4EncryptCBCWithZeroPadding = SM4EncFactory(ZeroPadding, CBC)
View Source
var SM4EncryptCFBWithPKCSPadding = SM4EncFactory(PKCS5Padding, CFB)
View Source
var SM4EncryptCFBWithZeroPadding = SM4EncFactory(ZeroPadding, CFB)
View Source
var SM4EncryptCTRWithPKCSPadding = SM4EncFactory(PKCS5Padding, CTR)
View Source
var SM4EncryptCTRWithZeroPadding = SM4EncFactory(ZeroPadding, CTR)
View Source
var SM4EncryptECBWithPKCSPadding = SM4EncFactory(PKCS5Padding, ECB)
View Source
var SM4EncryptECBWithZeroPadding = SM4EncFactory(ZeroPadding, ECB)
View Source
var SM4EncryptOFBWithPKCSPadding = SM4EncFactory(PKCS5Padding, OFB)
View Source
var SM4EncryptOFBWithZeroPadding = SM4EncFactory(ZeroPadding, OFB)
View Source
var StrConvUnquote = strconv.Unquote
View Source
var TripleDESDecryptCBCWithPKCSPadding = TripleDESDecFactory(PKCS5UnPadding, CBC)
View Source
var TripleDESDecryptCBCWithZeroPadding = TripleDESDecFactory(ZeroUnPadding, 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 TripleDESEncryptCBCWithZeroPadding = TripleDESEncFactory(ZeroPadding, CBC)
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)

func AESDecWithPassphrase

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

func AESEnc added in v1.3.3

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

func AESEncWithPassphrase

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

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 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 DESECBDec

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

func DESECBEnc

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

func DESEnc added in v1.3.3

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

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(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 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 SM3

func SM3(raw interface{}) []byte

func SM4Dec added in v1.3.3

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

func SM4Enc added in v1.3.3

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

func SM4GCMDec

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

func SM4GCMEnc

func SM4GCMEnc(key []byte, data interface{}, iv []byte) ([]byte, error)
func sm4encBase(data interface{}, key []byte, iv []byte, sm4ordinary func(key, in []byte, encode bool, iv []byte) ([]byte, error)) ([]byte, error) {
	return sm4ordinary(key, interfaceToBytes(data), true, iv)
}
func sm4decBase(data interface{}, key []byte, iv []byte, sm4ordinary func(key, in []byte, encode bool, iv []byte) ([]byte, error)) ([]byte, error) {
	return sm4ordinary(key, interfaceToBytes(data), false, iv)
}
func SM4CFBEnc(key []byte, data interface{}, iv []byte) ([]byte, error) {
	return sm4encBase(data, key, iv, sm4.Sm4CFB)
}
func SM4CBCEnc(key []byte, data interface{}, iv []byte) ([]byte, error) {
	return sm4encBase(data, key, iv, sm4.Sm4Cbc)
}
func SM4ECBEnc(key []byte, data interface{}, iv []byte) ([]byte, error) {
	return sm4encBase(data, key, iv, sm4.Sm4Ecb)
}
func SM4OFBEnc(key []byte, data interface{}, iv []byte) ([]byte, error) {
	return sm4encBase(data, key, iv, sm4.Sm4OFB)
}
func SM4CFBDec(key []byte, data interface{}, iv []byte) ([]byte, error) {
	return sm4decBase(data, key, iv, sm4.Sm4CFB)
}
func SM4CBCDec(key []byte, data interface{}, iv []byte) ([]byte, error) {
	return sm4decBase(data, key, iv, sm4.Sm4Cbc)
}
func SM4ECBDec(key []byte, data interface{}, iv []byte) ([]byte, error) {
	return sm4decBase(data, key, iv, sm4.Sm4Ecb)
}
func SM4OFBDec(key []byte, data interface{}, iv []byte) ([]byte, error) {
	return sm4decBase(data, key, iv, sm4.Sm4OFB)
}

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 StrConvUnquoteForce added in v1.2.8

func StrConvUnquoteForce(s string) []byte

func TripleDES_ECBDec added in v1.2.4

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

func TripleDES_ECBEnc added in v1.2.4

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

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 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) 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(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

Jump to

Keyboard shortcuts

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