Documentation ¶
Index ¶
- func BytesToMd5(data []byte) string
- func FnvSum64(key string) uint64
- func HashCode(key string) uint32
- func Md5Bytes(data []byte) string
- func Md5String(data string) string
- func NewECBDecrypter(b cipher.Block) cipher.BlockMode
- func NewECBEncrypt(b cipher.Block) cipher.BlockMode
- func ReadKey(filename string) ([]byte, error)
- func Sha1(s string) (string, error)
- func SignWithSha1(sep string, s ...string) (string, error)
- func StringToMd5(data string) string
- type CipherECB
- type Crypt
- func (ct *Crypt) Decrypt(signature, timestamp, nonce, encrypt string) ([]byte, error)
- func (ct *Crypt) DecryptMsg(signature, timestamp, nonce, encrypt string) ([]byte, string, error)
- func (ct *Crypt) Encrypt(msg, timestamp, nonce string) (string, string, error)
- func (ct *Crypt) GenerateXmlMsg(msg, timestamp, nonce string) string
- type PKCS
- type PKCS1
- type PKCS7
- type Padding
- func (p Padding) ISO10126Padding(text []byte, blockSize int) []byte
- func (p Padding) ISO10126UnPadding(src []byte) []byte
- func (p Padding) ISO7816_4Padding(text []byte, blockSize int) []byte
- func (p Padding) ISO7816_4UnPadding(src []byte) []byte
- func (p Padding) ISO97971Padding(text []byte, blockSize int) []byte
- func (p Padding) ISO97971UnPadding(src []byte) []byte
- func (p Padding) PKCS1Padding(text []byte, blockSize int, bt string) []byte
- func (p Padding) PKCS1UnPadding(src []byte) []byte
- func (p Padding) PKCS5Padding(text []byte) []byte
- func (p Padding) PKCS5UnPadding(src []byte) []byte
- func (p Padding) PKCS7Padding(text []byte, blockSize int) []byte
- func (p Padding) PKCS7UnPadding(src []byte) []byte
- func (p Padding) RandomBytes(length uint) []byte
- func (p Padding) TBCPadding(text []byte, blockSize int) []byte
- func (p Padding) TBCUnPadding(src []byte) []byte
- func (p Padding) X923Padding(text []byte, blockSize int) []byte
- func (p Padding) X923UnPadding(src []byte) []byte
- func (p Padding) ZeroPadding(text []byte, blockSize int) []byte
- func (p Padding) ZeroUnPadding(src []byte) []byte
- type RsaKey
- type Sm4
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesToMd5 ¶
BytesToMd5 bytes to md5 Deprecated: this function Md5Bytes
func NewECBDecrypter ¶ added in v1.8.33
NewECBDecrypter returns a BlockMode which decrypts in electronic code book mode, using the given Block.
func NewECBEncrypt ¶ added in v1.8.57
NewECBEncrypt returns a BlockMode which encrypts in electronic code book mode, using the given Block.
func StringToMd5 ¶
StringToMd5 string to md5 Deprecated: this function Md5String
Types ¶
type CipherECB ¶ added in v1.8.33
type CipherECB struct {
// contains filtered or unexported fields
}
CipherECB 模式加密
type Crypt ¶
Crypt *
- 1.第三方回复加密消息给公众平台;
- 2.第三方收到公众平台发送的消息,验证消息的安全性,并对消息进行解密。
func NewCrypt ¶
NewCrypt *
- 构造函数
- @param $token string 公众平台上,开发者设置的token
- @param $encodingAesKey string 公众平台上,开发者设置的EncodingAESKey
- @param $appId string 公众平台的appId
func (*Crypt) Decrypt ¶
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) Encrypt ¶
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 ¶
GenerateXmlMsg *
- 生成xml消息
- @param string $encrypt 加密后的消息密文
- @param string $signature 安全签名
- @param string $timestamp 时间戳
- @param string $nonce 随机字符串
type PKCS ¶
type PKCS1 ¶
type PKCS1 struct { }
PKCS1 for rsa
type PKCS7 ¶
type PKCS7 struct { }
PKCS7 for aes
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
ISO10126Padding 填充至符合块大小的整数倍,填充值最后一个字节为填充的数量数,其他字节填充随机字节。
func (Padding) ISO10126UnPadding ¶ added in v1.8.33
func (Padding) ISO7816_4Padding ¶ added in v1.8.33
ISO7816_4Padding 填充至符合块大小的整数倍,填充值第一个字节为0x80,其他字节填0x00。
func (Padding) ISO7816_4UnPadding ¶ added in v1.8.33
func (Padding) ISO97971Padding ¶ added in v1.8.33
ISO/IEC 9797-1 Padding Method 2
func (Padding) ISO97971UnPadding ¶ added in v1.8.33
func (Padding) PKCS1Padding ¶ added in v1.8.33
填充格式如下: 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 (Padding) PKCS5Padding ¶ added in v1.8.33
PKCS7Padding的子集,块大小固定为8字节
func (Padding) PKCS5UnPadding ¶ added in v1.8.33
func (Padding) PKCS7Padding ¶ added in v1.8.33
明文补码算法 填充至符合块大小的整数倍,填充值为填充数量数
func (Padding) PKCS7UnPadding ¶ added in v1.8.33
明文减码算法
func (Padding) TBCPadding ¶ added in v1.8.33
TBCPadding(Trailling-Bit-Compliment) 填充至符合块大小的整数倍,原文最后一位为1时填充0x00,最后一位为0时填充0xFF。
func (Padding) TBCUnPadding ¶ added in v1.8.33
func (Padding) X923Padding ¶ added in v1.8.33
X923Padding 填充至符合块大小的整数倍,填充值最后一个字节为填充的数量数,其他字节填0
func (Padding) X923UnPadding ¶ added in v1.8.33
func (Padding) ZeroPadding ¶ added in v1.8.33
数据长度不对齐时使用0填充,否则不填充