Documentation
¶
Overview ¶
Package xcodec 编解码器
Index ¶
- Variables
- func Convert(from any, to any) error
- func FlateCompress(src []byte) ([]byte, error)
- func FlateDecompress(src []byte) ([]byte, error)
- func GZipCompress(src []byte) ([]byte, error)
- func GZipDecompress(src []byte) ([]byte, error)
- func JSONString(obj any) string
- func ZLibCompress(src []byte) ([]byte, error)
- func ZLibDecompress(src []byte) ([]byte, error)
- type AesBlock
- type AesOFB
- type Base32
- type Base64
- type Cipher
- type Ciphers
- type Codec
- type DecodeFunc
- type Decoder
- type DecryptFunc
- type Decrypter
- type Decrypter2
- type Decrypters
- type EncodeFunc
- type Encoder
- type EncryptFunc
- type Encrypter
- type Encrypter2
- type Encrypters
- type HEX
- type Int64Cipher
- func (n *Int64Cipher) Decode(str string) (int64, error)
- func (n *Int64Cipher) DecodeInt64Bytes(str []byte) (int64, error)
- func (n *Int64Cipher) DecodeInt64String(str string) (int64, error)
- func (n *Int64Cipher) Encode(num int64) (string, error)
- func (n *Int64Cipher) EncodeInt64(num int64) string
- func (n *Int64Cipher) EncodeInt64Byte(num int64) []byte
- type TranscoderFunc
- type TranscoderFuncs
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func FlateCompress ¶
func FlateDecompress ¶
func GZipCompress ¶
func GZipDecompress ¶
func JSONString ¶
func ZLibCompress ¶
func ZLibDecompress ¶
Types ¶
type AesBlock ¶
type AesBlock struct { // Key 秘钥,必填,若长度为 16, 24, 32 则直接使用,否则使用 md5 值 Key string // IV 初始化向量,可选,当不为空时,长度应为 16 // 当为空时,会基于 key 生成 IV string // contains filtered or unexported fields }
AesBlock AES 加解密
func (*AesBlock) Encrypt ¶
Example ¶
package main import ( "fmt" "github.com/xanygo/anygo/xcodec" ) func main() { ac := &xcodec.AesBlock{ Key: "demo", } str1, _ := ac.Encrypt([]byte("hello")) fmt.Printf("Encrypt= %q\n", str1) str2, _ := ac.Decrypt(str1) fmt.Printf("Decrypt= %q\n", str2) }
Output: Encrypt= "\xc8\xc4?\xa2\xf3\x00Ͳ\xc1~\xb1\xb7\x96\xe3\xe4\x82" Decrypt= "hello"
type AesOFB ¶
type AesOFB struct { // Key 必填,加密秘钥,若长度为 16, 24, 32 会直接使用,否则会使用 md5 值 Key string // IV 初始化向量,可选,当不为空时,长度应为 16 // 当为空时,会基于 key 生成 IV string // contains filtered or unexported fields }
func (*AesOFB) Encrypt ¶
Example ¶
package main import ( "fmt" "github.com/xanygo/anygo/xcodec" ) func main() { ac := &xcodec.AesOFB{ Key: "demo", } str1, _ := ac.Encrypt([]byte("hello")) fmt.Printf("Encrypt= %q\n", str1) str2, _ := ac.Decrypt(str1) fmt.Printf("Decrypt= %q\n", str2) }
Output: Encrypt= "2\xa0\x1c\x90\xb4" Decrypt= "hello"
type Cipher ¶
func NewCipher ¶
func NewCipher(enc EncryptFunc, dec DecryptFunc) Cipher
type Ciphers ¶
type Ciphers []Cipher
Ciphers 多个 Cipher 的组合。 可以联合在一起链式工作,在 Encrypt 的时候,会依次正序调用。在 Decrypt 的时候,会依次倒序调用。
type Codec ¶
func NewCodec ¶
func NewCodec(name string, e EncodeFunc, d DecodeFunc) Codec
type DecodeFunc ¶
type Decoder ¶
func DecoderWithTranscoder ¶
func DecoderWithTranscoder(dec Decoder, trans TranscoderFunc) Decoder
type DecryptFunc ¶
type Decrypter2 ¶
type Decrypters ¶
type Decrypters []Decrypter
type EncodeFunc ¶
type Encoder ¶
func EncoderWithTranscoder ¶
func EncoderWithTranscoder(enc Encoder, trans TranscoderFunc) Encoder
type EncryptFunc ¶
type Encrypter2 ¶
type Encrypters ¶
type Encrypters []Encrypter
type Int64Cipher ¶
type Int64Cipher struct { // Cipher 必填 加密套件 Cipher Cipher // Int64Encoder 可选编码器,默认为 xbase.Base62 Int64Encoder *xbase.Encoding }
Int64Cipher 将 int64 加密为字符串的算法
func (*Int64Cipher) DecodeInt64Bytes ¶
func (n *Int64Cipher) DecodeInt64Bytes(str []byte) (int64, error)
func (*Int64Cipher) DecodeInt64String ¶
func (n *Int64Cipher) DecodeInt64String(str string) (int64, error)
func (*Int64Cipher) Encode ¶
func (n *Int64Cipher) Encode(num int64) (string, error)
Example ¶
package main import ( "fmt" "github.com/xanygo/anygo/xcodec" ) func main() { ac := &xcodec.Int64Cipher{ Cipher: &xcodec.AesOFB{ Key: "demo", }, } nums := []int64{0, 1, 1000, 10000, 99999999} for _, num := range nums { str1, _ := ac.Encode(num) fmt.Printf("Encode(%d) = %q\n", num, str1) num1, _ := ac.Decode(str1) fmt.Printf("Decode(%q) = %d\n\n", str1, num1) } }
Output: Encode(0) = "i1" Decode("i1") = 0 Encode(1) = "j1" Decode("j1") = 1 Encode(1000) = "kY6" Decode("kY6") = 1000 Encode(10000) = "E4P5" Decode("E4P5") = 10000 Encode(99999999) = "v24ZYJ2" Decode("v24ZYJ2") = 99999999
func (*Int64Cipher) EncodeInt64 ¶
func (n *Int64Cipher) EncodeInt64(num int64) string
func (*Int64Cipher) EncodeInt64Byte ¶
func (n *Int64Cipher) EncodeInt64Byte(num int64) []byte
type TranscoderFunc ¶
type TranscoderFuncs ¶
func (TranscoderFuncs) Transcoding ¶
func (ts TranscoderFuncs) Transcoding(data []byte) (result []byte, err error)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.