tool

package
v1.0.3020 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2024 License: Apache-2.0 Imports: 40 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// 编码
	// Encode(out io.Writer, b *Block) error
	Encode = pem.Encode

	// 编码
	// EncodeToMemory(b *Block) []byte
	EncodeToMemory = pem.EncodeToMemory

	// 解码
	// Decode(data []byte) (p *Block, rest []byte)
	Decode = pem.Decode
)
View Source
var PemBlockTypeMap = map[string]string{
	"pri_key":    "PRIVATE KEY",
	"en_pri_key": "ENCRYPTED PRIVATE KEY",
	"pub_key":    "PUBLIC KEY",

	"ec_pri_key":  "EC PRIVATE KEY",
	"dsa_pri_key": "DSA PRIVATE KEY",
	"rsa_pri_key": "RSA PRIVATE KEY",
}

BlockType 列表

Functions

func BE2LE_16 added in v1.0.2036

func BE2LE_16(inp []byte) []byte

func BE2LE_16_Bytes added in v1.0.2036

func BE2LE_16_Bytes(in []byte) []byte

func BE2LE_32 added in v1.0.2036

func BE2LE_32(inp []byte) []byte

func BE2LE_32_Bytes added in v1.0.2036

func BE2LE_32_Bytes(in []byte) []byte

func BE2LE_64 added in v1.0.2036

func BE2LE_64(inp []byte) []byte

func BE2LE_64_Bytes added in v1.0.2036

func BE2LE_64_Bytes(in []byte) []byte

func Base64Decode added in v1.0.2002

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

func Base64Encode added in v1.0.2002

func Base64Encode(src []byte) string

func BmpString added in v1.0.2032

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

BmpString returns s encoded in UCS-2

func BmpStringZeroTerminated added in v1.0.2032

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

BmpStringZeroTerminated returns s encoded in UCS-2 with a zero terminator.

func BytesPadding added in v1.0.2039

func BytesPadding(text []byte, size int) []byte

func BytesSplit added in v1.0.1049

func BytesSplit(buf []byte, size int) [][]byte

根据指定长度分割字节

func BytesToString added in v1.0.1049

func BytesToString(buf []byte) string

字节转换为字符串

func CryptoHashSum added in v1.0.2003

func CryptoHashSum(typ string, slices ...[]byte) ([]byte, error)

签名后数据

func DecodeBMPString added in v1.0.2032

func DecodeBMPString(bmpString []byte) (string, error)

DecodeBMPString return utf-8 string

func EncodeDerToPem added in v1.0.1033

func EncodeDerToPem(data []byte, blockType string) []byte

der 证书编码为 pem 证书

func GenRandom added in v1.0.1050

func GenRandom(n int) ([]byte, error)

随机生成字符

func GetBlockTypeFromName added in v1.0.1033

func GetBlockTypeFromName(name string) string

获取 BlockType 类型

func GetCryptoHash added in v1.0.2003

func GetCryptoHash(typ string) (crypto.Hash, error)

类型

func HashNames added in v1.0.2003

func HashNames() []string

func HashSum added in v1.0.2003

func HashSum(typ string, slices ...[]byte) ([]byte, error)

func HexDecode added in v1.0.2002

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

func HexEncode added in v1.0.2002

func HexEncode(src []byte) string

func HexPadding added in v1.0.2002

func HexPadding(text string, size int) string

func LE2BE_16 added in v1.0.2036

func LE2BE_16(inp []byte) []byte

func LE2BE_16_Bytes added in v1.0.2036

func LE2BE_16_Bytes(in []byte) []byte

func LE2BE_32 added in v1.0.2036

func LE2BE_32(inp []byte) []byte

func LE2BE_32_Bytes added in v1.0.2036

func LE2BE_32_Bytes(in []byte) []byte

func LE2BE_64 added in v1.0.2036

func LE2BE_64(inp []byte) []byte

func LE2BE_64_Bytes added in v1.0.2036

func LE2BE_64_Bytes(in []byte) []byte

func NewError added in v1.0.1046

func NewError(errs ...error) error

构造函数

func ParsePemToDer added in v1.0.1033

func ParsePemToDer(data []byte) ([]byte, error)

解析 pem 证书为 der 证书

func Recover added in v1.0.2052

func Recover(fn func()) (err error)

recover and return error when throw panic

func Rotl16 added in v1.0.2047

func Rotl16(x, n uint16) uint16

func Rotl32 added in v1.0.2037

func Rotl32(x, n uint32) uint32

func Rotl64 added in v1.0.2047

func Rotl64(x, n uint64) uint64

func Rotr16 added in v1.0.2047

func Rotr16(x, n uint16) uint16

func Rotr32 added in v1.0.2037

func Rotr32(x, n uint32) uint32

func Rotr64 added in v1.0.2047

func Rotr64(x, n uint64) uint64

func StringToBytes added in v1.0.1049

func StringToBytes(str string) []byte

字符串转换为字节

Types

type Block added in v1.0.1033

type Block = pem.Block

Block

type Cipher

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

*

  • 加密方式 *
  • @create 2022-7-26
  • @author deatil

func NewCipher

func NewCipher() Cipher

构造函数

func (Cipher) AddFunc

func (this Cipher) AddFunc(name string, block CipherFunc) Cipher

添加

func (Cipher) GetFunc

func (this Cipher) GetFunc(name string) CipherFunc

类型

func (Cipher) WithFunc

func (this Cipher) WithFunc(funcs CipherFuncMap) Cipher

覆盖

type CipherFunc

type CipherFunc = func([]byte) (cipher.Block, error)

CipherFunc

type CipherFuncMap

type CipherFuncMap = map[string]CipherFunc

CipherFunc map 列表

type Config added in v1.0.1046

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

*

  • 配置 *
  • @create 2023-2-13
  • @author deatil

func NewConfig added in v1.0.1046

func NewConfig() *Config

func (*Config) All added in v1.0.1046

func (this *Config) All() map[string]any

func (*Config) Clean added in v1.0.1049

func (this *Config) Clean()

func (*Config) Get added in v1.0.1046

func (this *Config) Get(name string) any

func (*Config) GetBool added in v1.0.1046

func (this *Config) GetBool(name string) bool

func (*Config) GetBoolSlice added in v1.0.1046

func (this *Config) GetBoolSlice(name string) []bool

func (*Config) GetBytes added in v1.0.1046

func (this *Config) GetBytes(name string) []byte

func (*Config) GetDuration added in v1.0.1046

func (this *Config) GetDuration(name string) time.Duration

func (*Config) GetDurationSlice added in v1.0.1046

func (this *Config) GetDurationSlice(name string) []time.Duration

func (*Config) GetFloat32 added in v1.0.1046

func (this *Config) GetFloat32(name string) float32

func (*Config) GetFloat64 added in v1.0.1046

func (this *Config) GetFloat64(name string) float64

func (*Config) GetInt added in v1.0.1046

func (this *Config) GetInt(name string) int

func (*Config) GetInt16 added in v1.0.1046

func (this *Config) GetInt16(name string) int16

func (*Config) GetInt32 added in v1.0.1046

func (this *Config) GetInt32(name string) int32

func (*Config) GetInt64 added in v1.0.1046

func (this *Config) GetInt64(name string) int64

func (*Config) GetInt8 added in v1.0.1046

func (this *Config) GetInt8(name string) int8

func (*Config) GetIntSlice added in v1.0.1046

func (this *Config) GetIntSlice(name string) []int

func (*Config) GetSlice added in v1.0.1046

func (this *Config) GetSlice(name string) []any

func (*Config) GetString added in v1.0.1046

func (this *Config) GetString(name string) string

func (*Config) GetStringMap added in v1.0.1046

func (this *Config) GetStringMap(name string) map[string]any

func (*Config) GetStringMapBool added in v1.0.1046

func (this *Config) GetStringMapBool(name string) map[string]bool

func (*Config) GetStringMapInt added in v1.0.1046

func (this *Config) GetStringMapInt(name string) map[string]int

func (*Config) GetStringMapInt64 added in v1.0.1046

func (this *Config) GetStringMapInt64(name string) map[string]int64

func (*Config) GetStringMapString added in v1.0.1046

func (this *Config) GetStringMapString(name string) map[string]string

func (*Config) GetStringMapStringSlice added in v1.0.1046

func (this *Config) GetStringMapStringSlice(name string) map[string][]string

func (*Config) GetStringSlice added in v1.0.1046

func (this *Config) GetStringSlice(name string) []string

func (*Config) GetTime added in v1.0.1046

func (this *Config) GetTime(name string) time.Time

func (*Config) GetUint added in v1.0.1046

func (this *Config) GetUint(name string) uint

func (*Config) GetUint16 added in v1.0.1046

func (this *Config) GetUint16(name string) uint16

func (*Config) GetUint32 added in v1.0.1046

func (this *Config) GetUint32(name string) uint32

func (*Config) GetUint64 added in v1.0.1046

func (this *Config) GetUint64(name string) uint64

func (*Config) GetUint8 added in v1.0.1046

func (this *Config) GetUint8(name string) uint8

func (*Config) Has added in v1.0.1046

func (this *Config) Has(name string) bool

func (*Config) Len added in v1.0.1049

func (this *Config) Len() int

func (*Config) Names added in v1.0.1049

func (this *Config) Names() []string

func (*Config) Remove added in v1.0.1049

func (this *Config) Remove(name string) *Config

删除

func (*Config) Set added in v1.0.1046

func (this *Config) Set(name string, data any) *Config

设置

func (*Config) String added in v1.0.1046

func (this *Config) String() string

func (*Config) WithData added in v1.0.1046

func (this *Config) WithData(data map[string]any) *Config

设置

type Encoding

type Encoding struct{}

*

  • 编码 *
  • @create 2022-4-17
  • @author deatil

func NewEncoding

func NewEncoding() Encoding

构造函数

func (Encoding) Base64Decode

func (this Encoding) Base64Decode(s string) ([]byte, error)

Base64 解码

func (Encoding) Base64Encode

func (this Encoding) Base64Encode(src []byte) string

Base64 编码

func (Encoding) BytesPadding added in v1.0.2048

func (this Encoding) BytesPadding(text []byte, size int) []byte

BytesPadding

func (Encoding) HexDecode

func (this Encoding) HexDecode(s string) ([]byte, error)

Hex 解码

func (Encoding) HexEncode

func (this Encoding) HexEncode(src []byte) string

Hex 编码

func (Encoding) HexPadding

func (this Encoding) HexPadding(text string, size int) string

补码

type ErrorEvent added in v1.0.2022

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

*

  • 错误事件 *
  • @create 2023-8-11
  • @author deatil

func NewErrorEvent added in v1.0.2022

func NewErrorEvent() ErrorEvent

构造函数

func (ErrorEvent) On added in v1.0.2022

func (this ErrorEvent) On(fn ErrorFunc) ErrorEvent

添加

func (ErrorEvent) Trigger added in v1.0.2022

func (this ErrorEvent) Trigger(errs []error)

执行

type ErrorFunc added in v1.0.2022

type ErrorFunc = func([]error)

错误方法

type Errors added in v1.0.1026

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

*

  • 错误记录 *
  • @create 2022-8-10
  • @author deatil

func NewErrors added in v1.0.1026

func NewErrors(errs []error) *Errors

构造函数

func (*Errors) All added in v1.0.1026

func (this *Errors) All() []error

获取全部

func (*Errors) Append added in v1.0.1026

func (this *Errors) Append(errs ...error) *Errors

添加

func (*Errors) Count added in v1.0.1027

func (this *Errors) Count() int

总数

func (*Errors) Error added in v1.0.1026

func (this *Errors) Error() string

实现 error 接口

func (*Errors) First added in v1.0.1026

func (this *Errors) First() error

第一个

func (*Errors) Get added in v1.0.1026

func (this *Errors) Get(n int) error

获取其中一个

func (*Errors) IsNil added in v1.0.1046

func (this *Errors) IsNil() bool

func (*Errors) Last added in v1.0.1026

func (this *Errors) Last() error

最后一个

func (*Errors) Prepend added in v1.0.1026

func (this *Errors) Prepend(errs ...error) *Errors

前置添加

func (*Errors) Range added in v1.0.1045

func (this *Errors) Range(fn func(int, error))

循环

func (*Errors) Reset added in v1.0.1026

func (this *Errors) Reset() *Errors

清空

func (*Errors) String added in v1.0.1026

func (this *Errors) String() string

返回全部错误字符

func (*Errors) Unwrap added in v1.0.1043

func (this *Errors) Unwrap() []error

func (*Errors) WithErrors added in v1.0.1026

func (this *Errors) WithErrors(errs []error) *Errors

设置

type Hash

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

*

  • 摘要 *
  • @create 2022-4-16
  • @author deatil

func AddHash added in v1.0.2003

func AddHash(name string, h HashFunc) *Hash

func NewHash

func NewHash() *Hash

构造函数

func (*Hash) AddHash

func (this *Hash) AddHash(name string, h HashFunc) *Hash

添加

func (*Hash) GetHash

func (this *Hash) GetHash(typ string) (HashFunc, error)

类型

func (*Hash) Names added in v1.0.2003

func (this *Hash) Names() []string

列席名称列表

func (*Hash) Sum added in v1.0.2003

func (this *Hash) Sum(typ string, slices ...[]byte) ([]byte, error)

签名后数据

type HashFunc added in v1.0.2003

type HashFunc = func() hash.Hash

HashFunc

func GetHash added in v1.0.2003

func GetHash(typ string) (HashFunc, error)

type Padding

type Padding struct{}

*

  • 补码 *
  • @create 2022-4-17
  • @author deatil

func NewPadding

func NewPadding() Padding

构造函数

func (Padding) ISO10126Padding

func (this Padding) ISO10126Padding(text []byte, blockSize int) []byte

ISO10126Padding 填充至符合块大小的整数倍,填充值最后一个字节为填充的数量数,其他字节填充随机字节。

func (Padding) ISO10126UnPadding

func (this Padding) ISO10126UnPadding(src []byte) ([]byte, error)

func (Padding) ISO7816_4Padding

func (this Padding) ISO7816_4Padding(text []byte, blockSize int) []byte

ISO7816_4Padding 填充至符合块大小的整数倍,填充值第一个字节为0x80,其他字节填0x00。

func (Padding) ISO7816_4UnPadding

func (this Padding) ISO7816_4UnPadding(src []byte) ([]byte, error)

func (Padding) ISO97971Padding added in v1.0.1026

func (this Padding) ISO97971Padding(text []byte, blockSize int) []byte

ISO/IEC 9797-1 Padding Method 2 填充至符合块大小的整数倍,填充值第一个字节为0x80,其他字节填0x00。

func (Padding) ISO97971UnPadding added in v1.0.1026

func (this Padding) ISO97971UnPadding(src []byte) ([]byte, error)

func (Padding) PBOC2Padding added in v1.0.2027

func (this Padding) PBOC2Padding(text []byte, blockSize int) []byte

PBOC2.0的MAC运算数据填充规范 若原加密数据的最末字节可能是0x80,则不推荐使用该模式

func (Padding) PBOC2UnPadding added in v1.0.2027

func (this Padding) PBOC2UnPadding(src []byte) ([]byte, error)

func (Padding) PKCS1Padding

func (this Padding) PKCS1Padding(text []byte, blockSize int, bt string) []byte

填充格式如下: Padding = 00 + BT + PS + 00 + D 00为固定字节 BT为处理模式 PS为填充字节,填充数量为 k - 3 - D ,k表示密钥长度, D表示原文长度。 PS的最小长度为8个字节。填充的值根据BT值来定: BT = 00时,填充全0x00 BT = 01时,填充全0xFF BT = 02时,随机填充,但不能为00。

func (Padding) PKCS1UnPadding

func (this Padding) PKCS1UnPadding(src []byte) ([]byte, error)

func (Padding) PKCS5Padding

func (this Padding) PKCS5Padding(text []byte) []byte

PKCS7Padding的子集,块大小固定为8字节

func (Padding) PKCS5UnPadding

func (this Padding) PKCS5UnPadding(src []byte) ([]byte, error)

func (Padding) PKCS7Padding

func (this Padding) PKCS7Padding(text []byte, blockSize int) []byte

明文补码算法 填充至符合块大小的整数倍,填充值为填充数量数

func (Padding) PKCS7UnPadding

func (this Padding) PKCS7UnPadding(src []byte) ([]byte, error)

明文减码算法

func (Padding) RandomBytes

func (this Padding) RandomBytes(length uint) []byte

随机字节

func (Padding) TBCPadding

func (this Padding) TBCPadding(text []byte, blockSize int) []byte

TBCPadding(Trailling-Bit-Compliment) 填充至符合块大小的整数倍,原文最后一位为1时填充0x00,最后一位为0时填充0xFF。

func (Padding) TBCUnPadding

func (this Padding) TBCUnPadding(src []byte) ([]byte, error)

func (Padding) X923Padding

func (this Padding) X923Padding(text []byte, blockSize int) []byte

X923Padding 填充至符合块大小的整数倍,填充值最后一个字节为填充的数量数,其他字节填0

func (Padding) X923UnPadding

func (this Padding) X923UnPadding(src []byte) ([]byte, error)

func (Padding) ZeroPadding

func (this Padding) ZeroPadding(text []byte, blockSize int) []byte

数据长度不对齐时使用0填充,否则不填充

func (Padding) ZeroUnPadding

func (this Padding) ZeroUnPadding(src []byte) ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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