crypto

package
v0.3.21 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultAESKeySize = AESKeySize32

	AESKeySize16 = 16
	AESKeySize24 = 24
	AESKeySize32 = 32
)
View Source
const (
	DefaultRSAKeySize = 1024
)
View Source
const (
	SM2PublicKeyPrefix = "04"
)

Variables

This section is empty.

Functions

func ConvertHexToSM2PrivateKey added in v0.3.21

func ConvertHexToSM2PrivateKey(hexPrivateKeyStr string) (*sm2.PrivateKey, error)

func ConvertHexToSM2PublicKey added in v0.3.21

func ConvertHexToSM2PublicKey(hexPublicKeyStr string) (*sm2.PublicKey, error)

func ConvertSM2PrivateKeyToHex added in v0.3.21

func ConvertSM2PrivateKeyToHex(privateKey *sm2.PrivateKey) string

func ConvertSM2PublicKeyToHex added in v0.3.21

func ConvertSM2PublicKeyToHex(publicKey *sm2.PublicKey) string

func DecryptWithRSAPrivateKeyString added in v0.3.21

func DecryptWithRSAPrivateKeyString(privateKeyStr, cipher string) (string, error)

DecryptWithRSAPrivateKeyString decrypts the data with private key string

func DecryptWithRSAPublicKeyString added in v0.3.21

func DecryptWithRSAPublicKeyString(publicKeyStr, cipher string) (string, error)

DecryptWithRSAPublicKeyString decrypts the data with public key string

func DecryptWithSM2PrivateKeyString added in v0.3.21

func DecryptWithSM2PrivateKeyString(privateKeyStr, cipher string) (string, error)

DecryptWithSM2PrivateKeyString decrypts the data with public key string

func EncryptWithRSAPrivateKeyString added in v0.3.21

func EncryptWithRSAPrivateKeyString(privateKeyStr, message string) (string, error)

EncryptWithRSAPrivateKeyString encrypts the data with private key string

func EncryptWithRSAPublicKeyString added in v0.3.21

func EncryptWithRSAPublicKeyString(publicKeyStr, message string) (string, error)

EncryptWithRSAPublicKeyString encrypts the data with public key string

func EncryptWithSM2PublicKeyString added in v0.3.21

func EncryptWithSM2PublicKeyString(publicKeyStr, message string) (string, error)

EncryptWithSM2PublicKeyString encrypts the data with public key string

Types

type AES added in v0.3.21

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

func NewAES added in v0.3.21

func NewAES() (*AES, error)

NewAES returns a new *AES

func NewAESWithKey added in v0.3.21

func NewAESWithKey(key string) *AES

NewAESWithKey returns a new *AES with given key

func NewAESWithKeySize added in v0.3.21

func NewAESWithKeySize(size int) (*AES, error)

NewAESWithKeySize returns a new *AES with given key size

func (*AES) Decrypt added in v0.3.21

func (a *AES) Decrypt(ciphertextBase64 string) (string, error)

func (*AES) Encrypt added in v0.3.21

func (a *AES) Encrypt(message string) (string, error)

type RSA

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

func NewEmptyRSA

func NewEmptyRSA() *RSA

NewEmptyRSA returns a new *RSA

func NewRSA

func NewRSA() (*RSA, error)

NewRSA returns a new *RSA

func NewRSAWithKeySize

func NewRSAWithKeySize(size int) (*RSA, error)

NewRSAWithKeySize returns a new *RSA with given key size

func NewRSAWithPrivateKey

func NewRSAWithPrivateKey(privateKey *rsa.PrivateKey) *RSA

NewRSAWithPrivateKey returns a new *RSA with given private key

func NewRSAWithPrivateKeyString

func NewRSAWithPrivateKeyString(privateKeyStr string) (*RSA, error)

NewRSAWithPrivateKeyString returns a new *RSA with given private key base64 string

func (*RSA) Decrypt

func (r *RSA) Decrypt(cipher string) (string, error)

Decrypt decrypts the base64 string

func (*RSA) DecryptWithPrivateKey

func (r *RSA) DecryptWithPrivateKey(cipher string) (string, error)

DecryptWithPrivateKey decrypts the cipher with private key

func (*RSA) DecryptWithPublicKey

func (r *RSA) DecryptWithPublicKey(cipher string) (string, error)

DecryptWithPublicKey decrypts the cipher with public key

func (*RSA) Encrypt

func (r *RSA) Encrypt(message string) (string, error)

Encrypt encrypts the string and returns the base64 string

func (*RSA) EncryptWithPrivateKey

func (r *RSA) EncryptWithPrivateKey(message string) (string, error)

EncryptWithPrivateKey encrypts the message with private key

func (*RSA) EncryptWithPublicKey

func (r *RSA) EncryptWithPublicKey(message string) (string, error)

EncryptWithPublicKey encrypts the message with public key

func (*RSA) GetPrivateKey

func (r *RSA) GetPrivateKey() (string, error)

GetPrivateKey gets the private key base64 string

func (*RSA) GetPublicKey

func (r *RSA) GetPublicKey() (string, error)

GetPublicKey gets the public key base64 string

func (*RSA) SetPrivateKey

func (r *RSA) SetPrivateKey(privateKeyStr string) error

SetPrivateKey sets the private key with base64 string

func (*RSA) SetPublicKey

func (r *RSA) SetPublicKey(publicKeyStr string) error

SetPublicKey sets the public key with base64 string

type SM2 added in v0.3.21

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

func NewEmptySM2 added in v0.3.21

func NewEmptySM2() *SM2

NewEmptyRSA returns a new *SM2

func NewSM2 added in v0.3.21

func NewSM2() (*SM2, error)

NewSM2 returns a new *SM2

func NewSM2WithPrivateKey added in v0.3.21

func NewSM2WithPrivateKey(privateKey *sm2.PrivateKey) *SM2

NewSM2WithPrivateKey returns a new *SM2 with given private key

func NewSM2WithPrivateKeyHexString added in v0.3.21

func NewSM2WithPrivateKeyHexString(privateKeyStr string) (*SM2, error)

NewSM2WithPrivateKeyString returns a new *SM2 with given private key hex string

func NewSM2WithPublicKey added in v0.3.21

func NewSM2WithPublicKey(publicKey *sm2.PublicKey) *SM2

NewSM2WithPublicKey returns a new *SM2 with given public key

func NewSM2WithPublicKeyHexString added in v0.3.21

func NewSM2WithPublicKeyHexString(publicKeyStr string) (*SM2, error)

NewSM2WithPublicKeyString returns a new *SM2 with given public key hex string

func (*SM2) Decrypt added in v0.3.21

func (s *SM2) Decrypt(cipher string) (string, error)

Decrypt decrypts the data

func (*SM2) DecryptWithPrivateKey added in v0.3.21

func (s *SM2) DecryptWithPrivateKey(cipher string, mode int) (string, error)

DecryptWithPrivateKey decrypts the data with private key

func (*SM2) Encrypt added in v0.3.21

func (s *SM2) Encrypt(message string) (string, error)

Encrypt encrypts the data

func (*SM2) EncryptWithPublicKey added in v0.3.21

func (s *SM2) EncryptWithPublicKey(message string, mode int) (string, error)

EncryptWithPublicKey encrypts the data with public key

func (*SM2) GetPrivateKey added in v0.3.21

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

GetPrivateKey returns the private key

func (*SM2) GetPrivateKeyHexString added in v0.3.21

func (s *SM2) GetPrivateKeyHexString() string

GetPrivateKeyHexString returns the private key hex string

func (*SM2) GetPublicKey added in v0.3.21

func (s *SM2) GetPublicKey() *sm2.PublicKey

GetPublicKey returns the public key

func (*SM2) GetPublicKeyHexString added in v0.3.21

func (s *SM2) GetPublicKeyHexString() string

GetPublicKeyHexString returns the public key hex string

func (*SM2) SetPrivateKey added in v0.3.21

func (s *SM2) SetPrivateKey(privateKey *sm2.PrivateKey)

SetPrivateKey sets the private key

func (*SM2) SetPublicKey added in v0.3.21

func (s *SM2) SetPublicKey(publicKey *sm2.PublicKey)

SetPublicKey sets the public key

Jump to

Keyboard shortcuts

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