xcrypto

package
v0.0.0-...-fcc14e7 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPKCS7BlockSizeExceeded = errors.New("pkcs7: block size exceeded")

ErrPKCS7BlockSizeExceeded is an error that indicates that the block size exceeds the maximum length.

View Source
var ErrPKCS7IncorrectPadding = errors.New("pkcs7: incorrect padding")

ErrPKCS7IncorrectPadding is an error that indicates the padding is incorrect.

View Source
var ErrPKCS7PaddingLengthExceeded = errors.New("pkcs7: padding length exceeded")

ErrPKCS7PaddingLengthExceeded is an error that indicates that the length of the padding exceeds the total length.

Functions

func PKCS7Padding

func PKCS7Padding(src []byte, blockSize int) (dst []byte, err error)

PKCS7Padding pads a byte array using the PKCS#7 padding method.

The src parameter is the source byte array. The blockSize parameter is the block size. The dst parameter is the destination byte array. The err return value is an error.

func PKCS7Unpadding

func PKCS7Unpadding(src []byte) (dst []byte, err error)

PKCS7Unpadding removes the padding bytes from a byte array that was padded using the PKCS#7 padding method.

The src parameter is the source byte array. The dst parameter is the destination byte array. The err return value is an error.

Types

type AESUseCBCWithPKCS7

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

AESUseCBCWithPKCS7 This will be filled using PKCS7 and finally encrypted using AES CBC mode

func NewAESUseCBCWithPKCS7

func NewAESUseCBCWithPKCS7(key, iv []byte) *AESUseCBCWithPKCS7

NewAESUseCBCWithPKCS7 creates a new AESUseCBCWithPKCS7 structure.

The key parameter is the key. The iv parameter is the initialization vector. The function returns a pointer to a new AESUseCBCWithPKCS7 structure.

func (*AESUseCBCWithPKCS7) Decrypt

func (w *AESUseCBCWithPKCS7) Decrypt(src []byte) (dst []byte, err error)

Decrypt will be padded using PKCS7 and finally decrypted using AES CBC mode

func (*AESUseCBCWithPKCS7) Encrypt

func (w *AESUseCBCWithPKCS7) Encrypt(src []byte) (dst []byte, err error)

Encrypt will be padded using PKCS7 and finally encrypted using AES CBC mode

type Crypto

type Crypto interface {
	Encrypt(plain []byte) ([]byte, error)
	Decrypt(encrypt []byte) ([]byte, error)
}

Crypto is an encryption and decryption interface for simple encapsulation

type WXCrypto

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

WXCrypto 开放平台的消息加密解密技术方案基于 AES 加解密算法来实现,具体如下:

EncodingAESKey: 即消息加解密 Key,长度固定为 43 个字符,从 a-z,A-Z,0-9 共 62 个字符中选取。由开发者在创建公众号插件时填写,后也可申请修改。
AESKey: AESKey=Base64_Decode(EncodingAESKey + "="),EncodingAESKey 尾部填充一个字符的 "=", 用 Base64_Decode 生成 32 个字节的 AESKey;
AES 采用 CBC 模式,秘钥长度为 32 个字节(256 位),数据采用 PKCS#7 填充; PKCS#7:K 为秘钥字节数(采用 32),
Buf 为待加密的内容,N 为其字节数。Buf 需要被填充为 K 的整数倍。在 Buf 的尾部填充(K - N%K)个字节,每个字节的内容 是(K - N%K)。

see: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/Technical_Plan.html

func NewWXCrypto

func NewWXCrypto(encodingAESKey, appID string) (*WXCrypto, error)

NewWXCrypto ...

func (*WXCrypto) Decrypt

func (w *WXCrypto) Decrypt(encrypt []byte) ([]byte, error)

Decrypt 对输入的加密内容进行解密

func (*WXCrypto) Encrypt

func (w *WXCrypto) Encrypt(plain []byte) ([]byte, error)

Encrypt 对输入的明文进行加密

AESKey = Base64_Decode(EncodingAESKey + "=");
FullStr = random(16B) + msg_len(4B) + msg + appid;
msg_encrypt = Base64_Encode( AES_Encrypt( FullStr, AESKey ) );

Jump to

Keyboard shortcuts

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