codec

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: AGPL-3.0 Imports: 18 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRSA = NewRSA(`default`)
View Source
var DefaultSM2 = NewSM2(`default`)

Functions

func DefaultKey

func DefaultKey() *sm2.PrivateKey

DefaultKey 默认私钥

func DefaultPublicKeyBytes

func DefaultPublicKeyBytes() []byte

DefaultPublicKeyBytes 默认公钥

func DefaultPublicKeyHex

func DefaultPublicKeyHex() string

DefaultPublicKeyHex 默认公钥hex字符串

func DefaultSM2DecryptHex

func DefaultSM2DecryptHex(cipher string, noBase64 ...bool) (string, error)

DefaultSM2DecryptHex 默认密钥解密hex字符串

func DefaultSM2EncryptHex

func DefaultSM2EncryptHex(cipher string, noBase64 ...bool) (string, error)

DefaultSM2EncryptHex 默认密钥加密并返回hex字符串

func HexEncodeToString

func HexEncodeToString(b []byte) string

HexEncodeToString hex编码为字符串

func PEMtoPrivateKey

func PEMtoPrivateKey(raw []byte, pwd []byte) (*sm2.PrivateKey, error)

PEMtoPrivateKey PEM文件内容转私钥

func PEMtoPublicKey

func PEMtoPublicKey(raw []byte, pwd []byte) (*sm2.PublicKey, error)

PEMtoPublicKey PEM文件内容转公钥

func PrivateKeyToPEM

func PrivateKeyToPEM(privateKey *sm2.PrivateKey, pwd []byte) ([]byte, error)

PrivateKeyToPEM 私钥转PEM文件内容

func PublicKeyToBytes

func PublicKeyToBytes(publicKey *sm2.PublicKey) ([]byte, error)

PublicKeyToBytes marshals a public key to the bytes

func PublicKeyToHexString

func PublicKeyToHexString(publicKey *sm2.PublicKey) string

PublicKeyToHexString 公钥转hex字符串

func PublicKeyToPEM

func PublicKeyToPEM(publickKey *sm2.PublicKey, pwd []byte) ([]byte, error)

PublicKeyToPEM 公钥转PEM文件内容

func RSADecrypt

func RSADecrypt(input []byte) ([]byte, error)

RSADecrypt 私钥解密

func RSADefaultKey

func RSADefaultKey() *codec.RSA

RSAKey 默认私钥

func RSADefaultPublicKeyBase64

func RSADefaultPublicKeyBase64() string

func RSADefaultPublicKeyBytes

func RSADefaultPublicKeyBytes() []byte

func RSAEncrypt

func RSAEncrypt(input []byte) ([]byte, error)

RSAEncrypt 私钥加密

func RSAPublicKeyToBytes

func RSAPublicKeyToBytes(publicKey *rsa.PublicKey) ([]byte, error)

RSAPublicKeyToBytes marshals a public key to the bytes

func RSAReset

func RSAReset()

func RSASignMd5

func RSASignMd5(data []byte) ([]byte, error)

RSASignMd5 使用RSAWithMD5算法签名

func RSASignSha1

func RSASignSha1(data []byte) ([]byte, error)

RSASignSha1 使用RSAWithSHA1算法签名

func RSASignSha256

func RSASignSha256(data []byte) ([]byte, error)

RSASignSha256 使用RSAWithSHA256算法签名

func ReadKey

func ReadKey(keyFile string, pwds ...[]byte) (privateKey *sm2.PrivateKey, err error)

ReadKey 读取私钥公钥

func SM2Decrypt

func SM2Decrypt(priv *sm2.PrivateKey, cipher []byte) ([]byte, error)

SM2Decrypt 解密

func SM2DecryptHex

func SM2DecryptHex(priv *sm2.PrivateKey, cipher string, noBase64 ...bool) (string, error)

SM2DecryptHex 解密

func SM2Encrypt

func SM2Encrypt(pubKey *sm2.PublicKey, msg []byte) ([]byte, error)

SM2Encrypt 加密

func SM2EncryptHex

func SM2EncryptHex(publicKey *sm2.PublicKey, cipher string, noBase64 ...bool) (string, error)

SM2EncryptHex 加密

func SM2GenKey

func SM2GenKey() (*sm2.PrivateKey, error)

SM2GenKey 生成私钥和公钥

func SM2Reset

func SM2Reset()

func SM2VerifySign

func SM2VerifySign(priv *sm2.PrivateKey, msg []byte) bool

SM2VerifySign 验签

func SaveKey

func SaveKey(privateKey *sm2.PrivateKey, keyFile string, pwds ...[]byte) error

SaveKey 保存私钥公钥

Types

type Codec

type Codec interface {
	Encode(raw string, keys ...string) string
	Decode(encrypted string, keys ...string) string
}

type RSA

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

func NewRSA

func NewRSA(name string, bits ...int) *RSA

func (*RSA) Decrypt

func (r *RSA) Decrypt(input []byte) ([]byte, error)

Decrypt 私钥解密

func (*RSA) DefaultKey

func (r *RSA) DefaultKey() *codec.RSA

DefaultKey 默认私钥

func (*RSA) DefaultPublicKeyBase64

func (r *RSA) DefaultPublicKeyBase64() string

func (*RSA) DefaultPublicKeyBytes

func (r *RSA) DefaultPublicKeyBytes() []byte

func (*RSA) Encrypt

func (r *RSA) Encrypt(input []byte) ([]byte, error)

Encrypt 私钥加密

func (*RSA) Reset

func (r *RSA) Reset()

func (*RSA) SignMd5

func (r *RSA) SignMd5(data []byte) ([]byte, error)

SignMd5 使用RSAWithMD5算法签名

func (*RSA) SignSha1

func (r *RSA) SignSha1(data []byte) ([]byte, error)

SignSha1 使用RSAWithSHA1算法签名

func (*RSA) SignSha256

func (r *RSA) SignSha256(data []byte) ([]byte, error)

SignSha256 使用RSAWithSHA256算法签名

type SM2

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

func NewSM2

func NewSM2(name string) *SM2

func (*SM2) DefaultDecryptHex

func (s *SM2) DefaultDecryptHex(cipher string, noBase64 ...bool) (string, error)

DefaultSM2DecryptHex 默认密钥解密hex字符串

func (*SM2) DefaultEncryptHex

func (s *SM2) DefaultEncryptHex(cipher string, noBase64 ...bool) (string, error)

DefaultSM2EncryptHex 默认密钥加密并返回hex字符串

func (*SM2) DefaultKey

func (s *SM2) DefaultKey() *sm2.PrivateKey

DefaultKey 默认私钥

func (*SM2) DefaultPublicKeyBytes

func (s *SM2) DefaultPublicKeyBytes() []byte

DefaultPublicKeyBytes 默认公钥

func (*SM2) DefaultPublicKeyHex

func (s *SM2) DefaultPublicKeyHex() string

DefaultPublicKeyHex 默认公钥hex字符串

func (*SM2) ReadKey

func (s *SM2) ReadKey(keyFile string, pwds ...[]byte) (privateKey *sm2.PrivateKey, err error)

ReadKey 读取私钥公钥

func (*SM2) Reset

func (s *SM2) Reset()

func (*SM2) SaveKey

func (s *SM2) SaveKey(privateKey *sm2.PrivateKey, keyFile string, pwds ...[]byte) error

SaveKey 保存私钥公钥

Jump to

Keyboard shortcuts

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