crypto

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AesDecrypt

func AesDecrypt(cipherText string, keys []byte) (string, error)

AesDecrypt aes

func AesDecryptBytes

func AesDecryptBytes(encrypted, keys []byte) ([]byte, error)

AesDecryptBytes aes

func AesDecryptStr

func AesDecryptStr(cipherText, keysStr string) (string, error)

AesDecryptStr aes

func AesEncrypt

func AesEncrypt(plainText string, keys []byte) (string, error)

AesEncrypt aes

func AesEncryptBytes

func AesEncryptBytes(plainTextBytes, keys []byte) ([]byte, error)

AesEncryptBytes aes

func AesEncryptStr

func AesEncryptStr(plainText string) (string, string, error)

AesEncryptStr aes

func AesEncryptStr2

func AesEncryptStr2(cipherText, keysStr string) (string, error)

AesEncryptStr2 aes

func AliyunSign

func AliyunSign(stringToSign, accessKeySecret, secretSuffix string) string

AliyunSign ...

func AliyunSignature

func AliyunSignature(signedParams map[string]string, method string, secret string) string

AliyunSignature ... *

func Base64DecodeString

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

Base64DecodeString returns the bytes represented by the base64 string s. RFC 4648.

func Base64DecodeStringURL

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

Base64DecodeStringURL returns the bytes represented by the base64 string s.

func Base64EncodeToString

func Base64EncodeToString(src []byte) string

Base64EncodeToString returns the base64 encoding of src. RFC 4648.

func Base64EncodeToStringURL

func Base64EncodeToStringURL(src []byte) string

Base64EncodeToStringURL returns the base64 encoding of src.

func BytesNetworkOrder2Number

func BytesNetworkOrder2Number(bytesInNetworkOrder []byte) int

BytesNetworkOrder2Number 4个字节的网络字节序bytes数组还原成一个数字

func CODE

func CODE(length int) string

CODE code

func CompareHashAndPassword

func CompareHashAndPassword(hashedPassword, password []byte) error

CompareHashAndPassword compares a bcrypt hashed password with its possible plaintext equivalent. Returns nil on success, or an error on failure.

func DecodeBaseX32

func DecodeBaseX32(code string) (int64, error)

DecodeBaseX32 64解码

func DecodeBaseX64

func DecodeBaseX64(code string) (int64, error)

DecodeBaseX64 64解码

func EncodeBaseX32

func EncodeBaseX32(code int64) string

EncodeBaseX32 64位编码

func EncodeBaseX62

func EncodeBaseX62(code int64) string

EncodeBaseX62 ... z被定义位转义字符

func EncodeBaseX64

func EncodeBaseX64(code int64) string

EncodeBaseX64 64位编码

func FixPreStrLen

func FixPreStrLen(pstr string, plen int) string

FixPreStrLen 获取固定长度内容,不够前段补齐0

func FixPreStrLen2

func FixPreStrLen2(pstr string, plen int) string

FixPreStrLen2 获取固定长度内容,不够前段补齐0, 超长, 保留原始数据

func FixRandomAes32

func FixRandomAes32(str string) string

FixRandomAes32 random aes 32

func FixSufStrLen

func FixSufStrLen(pstr string, plen int) string

FixSufStrLen 获取固定长度内容,不够前段补齐0

func GenerateFromPassword

func GenerateFromPassword(password []byte, cost int) ([]byte, error)

GenerateFromPassword returns the bcrypt hash of the password at the given cost. If the cost given is less than MinCost, the cost will be set to DefaultCost, instead. Use CompareHashAndPassword, as defined in this package, to compare the returned hashed password with its cleartext version.

func MD5Hash

func MD5Hash(b []byte) string

MD5Hash MD5哈希值

func MD5HashString

func MD5HashString(s string) string

MD5HashString MD5哈希值

func MaskDecrypt

func MaskDecrypt(buffers []byte, randoms []byte) []byte

MaskDecrypt 简单的解密算法

func MaskEncrypt

func MaskEncrypt(buffers []byte, randoms []byte) []byte

MaskEncrypt 简单的加密算法, 破坏其本身字符串的特征, 当用于对同一个MD5值进行处理

func Number2BytesInNetworkOrder

func Number2BytesInNetworkOrder(number int) []byte

Number2BytesInNetworkOrder 将一个数字转换成生成4个字节的网络字节序bytes数组

func PKCS7Padding

func PKCS7Padding(cipherText []byte, blockSize int) []byte

PKCS7Padding 使用PKCS7进行填充

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte, blockSize int) []byte

PKCS7UnPadding 删除PKCS7填充

func RandomAes32

func RandomAes32() string

RandomAes32 random aes 32

func RandomBytes

func RandomBytes(length int) []byte

RandomBytes random

func Reverse

func Reverse(str string) string

Reverse 字符串倒序

func SHA1Hash

func SHA1Hash(b []byte) string

SHA1Hash SHA1哈希值

func SHA1HashString

func SHA1HashString(s string) string

SHA1HashString SHA1哈希值

func UUID

func UUID(length int) string

UUID uuid

func UUID2

func UUID2(length int) string

UUID2 uuid

func WxGenMD5

func WxGenMD5(datas map[string]string, sign string) string

WxGenMD5 排序,加密, 用于红包数据签名

func WxGenSHA1

func WxGenSHA1(arr ...string) string

WxGenSHA1 排序,串接arr参数,生成sha1 digest

func WxGenSHA1And

func WxGenSHA1And(arr ...string) string

WxGenSHA1And 排序,串接arr参数,生成sha1 digest

func WxPKCS7Decode

func WxPKCS7Decode(decrypted []byte) []byte

WxPKCS7Decode 删除解密后明文的补位字符 param decrypted 解密后的明文 return 删除补位字符后的明文

func WxPKCS7Encode

func WxPKCS7Encode(count int) []byte

WxPKCS7Encode 获得对明文进行补位填充的字节. param count 需要进行填充补位操作的明文字节个数 return 补齐用的字节数组

Types

type WxAccessToken

type WxAccessToken struct {
	AccessToken string `json:"access_token"`
	ExpiresIn   string `json:"expires_in"`
}

WxAccessToken access token

type WxCrypto

type WxCrypto struct {
	AesKey         []byte
	Token          string
	AppID          string
	EncodingAesKey string
}

WxCrypto wechat 加密

func WxNewCrypto

func WxNewCrypto(appid, token, encodingAesKey string) *WxCrypto

WxNewCrypto 注意,来自微信的AesKey需要增加一个"="符号,推荐使用WxNewCrypto2处理

func WxNewCrypto2

func WxNewCrypto2(appid, token, encodingAesKey string) *WxCrypto

WxNewCrypto2 new

func (*WxCrypto) Decrypt

func (a *WxCrypto) Decrypt(cipherText string) (string, error)

Decrypt 对密文进行解密. param cipherText 需要解密的密文 return 解密得到的明文

func (*WxCrypto) DecryptCheckAppID

func (a *WxCrypto) DecryptCheckAppID(cipherText string, appIDCheck func(string) error) (string, error)

DecryptCheckAppID 对密文进行解密. param cipherText 需要解密的密文 param appidOrCorpid 获取解密内容回调,如果为空,会强制判断该内容是否和加密器中的ID相同 return 解密得到的明文

func (*WxCrypto) Encrypt

func (a *WxCrypto) Encrypt(plainText string) (string, error)

Encrypt 对明文进行加密 param plainText 需要加密的明文 return 加密后base64编码的字符串

type WxEncryptMessage

type WxEncryptMessage struct {
	ToUserName   string `json:",omitempty"` // ToUserName为公众号AppId或者企业号的CorpID
	AgentID      string `json:",omitempty"` // 为接收的应用id,可在应用的设置页面获取 只有企业号,该字段才有值
	Encrypt      string `json:",omitempty"` // 密文 encrypt为经过加密的密文(消息明文格式参见 接收普通消息,事件明文格式参见 接收事件)
	MsgSignature string `json:",omitempty"` // 密文签名
	TimeStamp    string `json:",omitempty"` // 密文时间戳
	Nonce        string `json:",omitempty"` // 密文随机码
}

WxEncryptMessage 加密文件存储

type WxEncryptSignature

type WxEncryptSignature struct {
	WxSignature
	MsgSignature string `query:"msg_signature"`
	EncryptType  string `query:"encrypt_type"`
}

WxEncryptSignature jsapi signature

type WxSignature

type WxSignature struct {
	Signature string `query:"signature"`
	Timestamp string `query:"timestamp"`
	Nonce     string `query:"nonce"`
	Echostr   string `query:"echostr"`
}

WxSignature signature

Jump to

Keyboard shortcuts

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