qxCrypto

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AES128KeyLen = 16
	AES192KeyLen = 24
	AES256KeyLen = 32
	AESGCMIvLen  = 12
	AESCCMIvLen  = 24
	AEsCBCIvLen  = 16
	AESCTRIvLen  = 16
)

Variables

View Source
var (
	ErrorInvalidECDSAPrivateKeyPEMFormat = errors.New("invalid public key PEM format")
	ErrorInvalidECDSAPublicKeyPEMFormat  = errors.New("invalid public key PEM format")
	ErrorPublicKeyNotECDSA               = errors.New("public key not ECDSA type")
)
View Source
var (
	ErrorInvalidRsaPrivateKeyPEMFormat = errors.New("invalid public key PEM format")
	ErrorInvalidRsaPublicKeyPEMFormat  = errors.New("invalid public key PEM format")
	ErrorPublicKeyNotRsa               = errors.New("public key not rsa type")
)

Functions

func AESDecryptByCBC

func AESDecryptByCBC(cipherTextBase64 string, keyBase, ivBase string) ([]byte, error)

**AES-CBC 解密**

func AESDecryptByCCM

func AESDecryptByCCM(cipherTextBase64 string, keyBase, ivBase string) ([]byte, error)

**AES-CCM 解密**

func AESDecryptByCTR

func AESDecryptByCTR(cipherTextBase64 string, keyBase, ivBase string) ([]byte, error)

**AES-CTR 解密**

func AESDecryptByGCM

func AESDecryptByGCM(cipherTextBase64 string, keyBase, ivBase string) ([]byte, error)

**AES-GCM 解密**

func AESEncryptByCBC

func AESEncryptByCBC(plainText []byte, keyBase, ivBase string) (string, error)

**AES-CBC 加密**

func AESEncryptByCCM

func AESEncryptByCCM(plainText []byte, keyBase, ivBase string) (string, error)

**AES-CCM 加密**

func AESEncryptByCTR

func AESEncryptByCTR(plainText []byte, keyBase, ivBase string) (string, error)

**AES-CTR 加密**

func AESEncryptByGCM

func AESEncryptByGCM(plainText []byte, keyBase, ivBase string) (string, error)

**AES-GCM 加密**

func CBCPkcs7Pad

func CBCPkcs7Pad(data []byte, blockSize int) []byte

**PKCS7 填充**

func CBCPkcs7Unpad

func CBCPkcs7Unpad(data []byte) []byte

**PKCS7 去填充**

func ECDSAGenerateECCCertificate

func ECDSAGenerateECCCertificate(curve elliptic.Curve, subject pkix.Name) (keyPem, certPem []byte, err error)

note: 生成 ECC 证书

func ECDSAGenerateKeys

func ECDSAGenerateKeys(curve elliptic.Curve) (privateKey *ecdsa.PrivateKey, publicKey *ecdsa.PublicKey, err error)

note: 生成 ECDSA 公私钥

func GenAESKeyAndIv

func GenAESKeyAndIv(KeyLen int, IvLen int) (keyBase, ivBase string, err error)

func GenRsaKey2Bt

func GenRsaKey2Bt(btLen int) (privateKeyBt, publicKeyBt []byte, err error)

note: 生成 RSA 公私钥并解析到bt

func GenRsaKey2Str

func GenRsaKey2Str(btLen int) (privateKeyStr, publicKeyStr *string, err error)

note: 生成 RSA 公私钥并解析到字符串

func HMACSha256

func HMACSha256(data string, key string) (hexStr string, baseStr string)

func HMACSha512

func HMACSha512(data string, key string) (hexStr string, baseStr string)

func ParseECDSAPrivateKeyFromPEM

func ParseECDSAPrivateKeyFromPEM(privateKeyPEM string) (*ecdsa.PrivateKey, error)

**解析 ECDSA 公钥 **

func ParseECDSAPublicKeyFromCert

func ParseECDSAPublicKeyFromCert(certPEM string) (*ecdsa.PublicKey, error)

func ParseRSAPrivateKey

func ParseRSAPrivateKey(pemData string) (*rsa.PrivateKey, error)

解析 PEM 格式的私钥

func ParseRSAPublicKey

func ParseRSAPublicKey(pemData string) (*rsa.PublicKey, error)

解析 PEM 格式的公钥

func RSADecrypt

func RSADecrypt(method hash.Hash, encryptedBase64 string, privateKey *rsa.PrivateKey) ([]byte, error)

RSA + SHA-512 进行解密

func RSADecryptBySha256 added in v0.0.16

func RSADecryptBySha256(encryptedBase64 string, privateKey *rsa.PrivateKey) ([]byte, error)

RSA + SHA-256 进行解密

func RSADecryptBySha512 added in v0.0.16

func RSADecryptBySha512(encryptedBase64 string, privateKey *rsa.PrivateKey) ([]byte, error)

RSA + SHA-512 进行解密

func RSAEncrypt

func RSAEncrypt(method hash.Hash, plainText []byte, publicKey *rsa.PublicKey) (string, error)

RSA + SHA-512 进行加密

func RSAEncryptBySha256 added in v0.0.16

func RSAEncryptBySha256(plainText []byte, publicKey *rsa.PublicKey) (string, error)

RSA + SHA-256 进行加密

func RSAEncryptBySha512 added in v0.0.16

func RSAEncryptBySha512(plainText []byte, publicKey *rsa.PublicKey) (string, error)

RSA + SHA-512 进行加密

func RSAGenerateKeys

func RSAGenerateKeys(bits int) (privateKey *rsa.PrivateKey, publicKey *rsa.PublicKey, err error)

note: 生成 RSA 公私钥

func RSAParsePrivateKey2Bt

func RSAParsePrivateKey2Bt(privateKey *rsa.PrivateKey) (prvKeyBt []byte, err error)

note: 解析私钥到字节

func RSAParsePublicKey2Bt

func RSAParsePublicKey2Bt(publicKey *rsa.PublicKey) (pubKeyBt []byte, err error)

note: 解析公钥到字节

func RanByte added in v0.0.28

func RanByte(btLen int) ([]byte, error)

func RandStr added in v0.0.28

func RandStr(n int) string

func Sha256

func Sha256(data string) (hexStr string, baseStr string)

func Sha512

func Sha512(data string) (hexStr string, baseStr string)

Types

This section is empty.

Jump to

Keyboard shortcuts

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