algorithm

package
v1.8.47 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2023 License: Zlib Imports: 19 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToMd5

func BytesToMd5(data []byte) string

func FileNameToMd5 added in v1.8.20

func FileNameToMd5(filename string) string

func FileToMd5

func FileToMd5(src io.Reader) string

func FileToMd5Byte

func FileToMd5Byte(src io.Reader) []byte

func FnvSum64 added in v0.5.36

func FnvSum64(key string) uint64

FnvSum64 gets the string and returns its uint64 hash value.

func HashCode added in v1.0.58

func HashCode(key string) uint32

func NewECBDecrypter added in v1.8.33

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

NewECBDecrypter returns a BlockMode which decrypts in electronic code book mode, using the given Block.

func NewECBEncrypter added in v1.8.33

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

NewECBEncrypter returns a BlockMode which encrypts in electronic code book mode, using the given Block.

func ReadKey added in v1.1.25

func ReadKey(filename string) ([]byte, error)

func Sha1

func Sha1(s string) (string, error)

func SignWithSha1

func SignWithSha1(sep string, s ...string) (string, error)

func StringToMd5

func StringToMd5(data string) string

Types

type CipherECB added in v1.8.33

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

ecb 模式加密

func NewECB added in v1.8.33

func NewECB(cipherFunc func(key []byte) (cipher.Block, error)) CipherECB

func (CipherECB) Decrypt added in v1.8.33

func (ecb CipherECB) Decrypt(ciphertext, key []byte, iv []byte) ([]byte, error)

Decrypt 解密

func (CipherECB) Encrypt added in v1.8.33

func (ecb CipherECB) Encrypt(plaintext, key []byte, iv []byte) ([]byte, error)

Encrypt 加密

type Crypt

type Crypt struct {
	Token  string
	AesKey []byte
}

Crypt *

  • 1.第三方回复加密消息给公众平台;
  • 2.第三方收到公众平台发送的消息,验证消息的安全性,并对消息进行解密。

func NewCrypt

func NewCrypt(token, aesKey string) *Crypt

NewCrypt *

  • 构造函数
  • @param $token string 公众平台上,开发者设置的token
  • @param $encodingAesKey string 公众平台上,开发者设置的EncodingAESKey
  • @param $appId string 公众平台的appId

func (*Crypt) Decrypt

func (ct *Crypt) Decrypt(signature, timestamp, nonce, encrypt string) ([]byte, error)

Decrypt *

  • 检验消息的真实性,并且获取解密后的明文.
  • <ol>
  • <li>利用收到的密文生成安全签名,进行签名验证</li>
  • <li>若验证通过,则提取xml中的加密消息</li>
  • <li>对消息进行解密</li>
  • </ol> *
  • @param signature string 签名串,对应URL参数的msg_signature
  • @param timestamp string 时间戳 对应URL参数的timestamp
  • @param nonce string 随机串,对应URL参数的nonce
  • @param encrypt string 密文 *

func (*Crypt) DecryptMsg

func (ct *Crypt) DecryptMsg(signature, timestamp, nonce, encrypt string) ([]byte, string, error)

DecryptMsg *

  • @return @string 正文 @string appid @error

func (*Crypt) Encrypt

func (ct *Crypt) Encrypt(msg, timestamp, nonce string) (string, string, error)

Encrypt *

  • 将公众平台回复用户的消息加密打包.
  • <ol>
  • <li>对要发送的消息进行AES-CBC加密</li>
  • <li>生成安全签名</li>
  • <li>将消息密文和安全签名打包成xml格式</li>
  • </ol> *
  • @param msg string 公众平台待回复用户的消息,xml格式的字符串
  • @param timeStamp string 时间戳,可以自己生成,也可以用URL参数的timestamp
  • @param nonce string 随机串,可以自己生成,也可以用URL参数的nonce *

func (*Crypt) GenerateXmlMsg

func (ct *Crypt) GenerateXmlMsg(msg, timestamp, nonce string) string

GenerateXmlMsg *

  • 生成xml消息
  • @param string $encrypt 加密后的消息密文
  • @param string $signature 安全签名
  • @param string $timestamp 时间戳
  • @param string $nonce 随机字符串

type PKCS

type PKCS interface {
	Encrypt(raw, key []byte) (string, error)
	Decrypt(raw string, key []byte) ([]byte, error)
}

func NewPKCS

func NewPKCS(ver int) PKCS

type PKCS1

type PKCS1 struct {
}

PKCS1 for rsa

func NewPKCS1

func NewPKCS1() *PKCS1

func (*PKCS1) Decrypt

func (pk *PKCS1) Decrypt(raw string, key []byte) ([]byte, error)

Decrypt PKCS interface

func (*PKCS1) Encrypt

func (pk *PKCS1) Encrypt(raw, key []byte) (string, error)

Encrypt PKCS interface

func (*PKCS1) Generate added in v1.8.3

func (*PKCS1) Generate(bits int, out *RsaKey) error

Generate RSA公钥私钥产生

type PKCS7

type PKCS7 struct {
}

PKCS7 for aes

func NewPKCS7

func NewPKCS7() *PKCS7

func (*PKCS7) Decrypt

func (pk *PKCS7) Decrypt(raw string, key []byte) ([]byte, error)

Decrypt PKCS interface

func (*PKCS7) DecryptIv

func (pk *PKCS7) DecryptIv(raw string, aesKey []byte, iv []byte) ([]byte, error)

DecryptIv 带IV

func (*PKCS7) Encrypt

func (pk *PKCS7) Encrypt(raw, key []byte) (string, error)

Encrypt PKCS interface

func (*PKCS7) EncryptIv added in v0.5.41

func (pk *PKCS7) EncryptIv(raw, aesKey []byte, iv []byte) (string, error)

EncryptIv 带IV

type Padding added in v1.8.33

type Padding struct{}

func NewPadding added in v1.8.33

func NewPadding() Padding

func (Padding) ISO10126Padding added in v1.8.33

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

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

func (Padding) ISO10126UnPadding added in v1.8.33

func (p Padding) ISO10126UnPadding(src []byte) []byte

func (Padding) ISO7816_4Padding added in v1.8.33

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

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

func (Padding) ISO7816_4UnPadding added in v1.8.33

func (p Padding) ISO7816_4UnPadding(src []byte) []byte

func (Padding) ISO97971Padding added in v1.8.33

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

ISO/IEC 9797-1 Padding Method 2

func (Padding) ISO97971UnPadding added in v1.8.33

func (p Padding) ISO97971UnPadding(src []byte) []byte

func (Padding) PKCS1Padding added in v1.8.33

func (p 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时,填充全00 BT = 01时,填充全FF BT = 02时,随机填充,但不能为00。

func (Padding) PKCS1UnPadding added in v1.8.33

func (p Padding) PKCS1UnPadding(src []byte) []byte

func (Padding) PKCS5Padding added in v1.8.33

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

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

func (Padding) PKCS5UnPadding added in v1.8.33

func (p Padding) PKCS5UnPadding(src []byte) []byte

func (Padding) PKCS7Padding added in v1.8.33

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

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

func (Padding) PKCS7UnPadding added in v1.8.33

func (p Padding) PKCS7UnPadding(src []byte) []byte

明文减码算法

func (Padding) RandomBytes added in v1.8.33

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

随机字节

func (Padding) TBCPadding added in v1.8.33

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

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

func (Padding) TBCUnPadding added in v1.8.33

func (p Padding) TBCUnPadding(src []byte) []byte

func (Padding) X923Padding added in v1.8.33

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

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

func (Padding) X923UnPadding added in v1.8.33

func (p Padding) X923UnPadding(src []byte) []byte

func (Padding) ZeroPadding added in v1.8.33

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

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

func (Padding) ZeroUnPadding added in v1.8.33

func (p Padding) ZeroUnPadding(src []byte) []byte

type RsaKey added in v1.8.3

type RsaKey struct {
	Pri io.Writer
	Pub io.Writer
}

Jump to

Keyboard shortcuts

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