encryptUtil

package
v1.0.87 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AESIVKey = []byte("12345678901234567890123456789012") // 256位密钥
)

Functions

func CombinedDecryptionAndVerification added in v1.0.79

func CombinedDecryptionAndVerification(ciphertext, key, nonce, signature []byte, publicKey ed25519.PublicKey) ([]byte, error)

CombinedDecryptionAndVerification 组合解密和签名验证

func CombinedEncryption added in v1.0.79

func CombinedEncryption(data []byte, privateKey ed25519.PrivateKey) ([]byte, []byte, []byte, error)

CombinedEncryption 结合Ed25519签名和ChaCha20-Poly1305加密

func DecryptAES

func DecryptAES(key []byte, ct string) (string, error)

func DecryptEd25519 added in v1.0.79

func DecryptEd25519(ciphertextBase64, recipientPrivateKeyBase64 string) ([]byte, error)

DecryptEd25519 使用接收方的 Ed25519/X25519 私钥解密数据

参数:

  • ciphertextBase64: Base64 编码的密文
  • recipientPrivateKeyBase64: 接收方的私钥 (Base64 编码的 32 字节 Ed25519/X25519 私钥)

返回值:

  • []byte: 解密后的明文数据
  • error: 错误信息

func DecryptEd25519ChaCha added in v1.0.79

func DecryptEd25519ChaCha(nonce, ciphertext, signature []byte, encryptionKey []byte, signingPublicKey ed25519.PublicKey) ([]byte, error)

DecryptEd25519ChaCha decrypts and verifies data using ChaCha20-Poly1305 decryption with Ed25519 verification

func DecryptRSA

func DecryptRSA(encrypted []byte, privateKey *rsa.PrivateKey) []byte

func DecryptWithAge added in v1.0.79

func DecryptWithAge(encryptedData []byte, identity *age.X25519Identity) ([]byte, error)

DecryptWithAge 使用Age对数据进行解密

func DecryptWithChaCha20Poly1305 added in v1.0.79

func DecryptWithChaCha20Poly1305(nonce, ciphertext, key []byte) ([]byte, error)

DecryptWithChaCha20Poly1305 使用ChaCha20-Poly1305对数据进行解密

func EncryptAES

func EncryptAES(key []byte, plaintext string) (string, error)

func EncryptEd25519 added in v1.0.79

func EncryptEd25519(plaintext []byte, recipientPublicKeyBase64 string) (string, error)

EncryptEd25519 使用接收方的 Ed25519/X25519 公钥加密数据 返回 Base64 编码的密文

参数:

  • plaintext: 需要加密的明文数据
  • recipientPublicKeyBase64: 接收方的公钥 (Base64 编码的 32 字节 Ed25519/X25519 公钥)

返回值:

  • string: Base64 编码的密文
  • error: 错误信息

func EncryptEd25519ChaCha added in v1.0.79

func EncryptEd25519ChaCha(plaintext []byte, encryptionKey []byte, signingPrivateKey ed25519.PrivateKey) ([]byte, []byte, []byte, error)

EncryptEd25519ChaCha combines ChaCha20-Poly1305 encryption with Ed25519 signature

func EncryptRSA

func EncryptRSA(txt string) ([]byte, *rsa.PublicKey, *rsa.PrivateKey)

func EncryptWithAge added in v1.0.79

func EncryptWithAge(data []byte, recipient *age.X25519Recipient) ([]byte, error)

EncryptWithAge 使用Age对数据进行加密

func EncryptWithChaCha20Poly1305 added in v1.0.79

func EncryptWithChaCha20Poly1305(plaintext []byte, key []byte) ([]byte, []byte, error)

EncryptWithChaCha20Poly1305 使用ChaCha20-Poly1305对数据进行加密

func GenerateAgeKeyPair added in v1.0.79

func GenerateAgeKeyPair() (*age.X25519Identity, *age.X25519Recipient, error)

GenerateAgeKeyPair 生成Age加密的密钥对

func GenerateChaCha20Poly1305Key added in v1.0.79

func GenerateChaCha20Poly1305Key() ([]byte, error)

GenerateChaCha20Poly1305Key 生成ChaCha20-Poly1305密钥

func GenerateEd25519KeyPair added in v1.0.79

func GenerateEd25519KeyPair() (publicKeyBase64, privateKeyBase64 string, err error)

GenerateEd25519KeyPair 生成 Ed25519/X25519 密钥对 返回 Base64 编码的公钥和私钥

返回值:

  • publicKeyBase64: Base64 编码的公钥 (32 字节)
  • privateKeyBase64: Base64 编码的私钥 (32 字节)
  • error: 错误信息

func GetEd25519PrivateKeyBase64 added in v1.0.79

func GetEd25519PrivateKeyBase64(privateKey ed25519.PrivateKey) string

GetEd25519PrivateKeyBase64 获取Ed25519私钥的Base64编码字符串表示

func GetEd25519PrivateKeyHex added in v1.0.79

func GetEd25519PrivateKeyHex(privateKey ed25519.PrivateKey) string

GetEd25519PrivateKeyHex 获取Ed25519私钥的十六进制字符串表示

func GetEd25519PublicKeyBase64 added in v1.0.79

func GetEd25519PublicKeyBase64(publicKey ed25519.PublicKey) string

GetEd25519PublicKeyBase64 获取Ed25519公钥的Base64编码字符串表示

func GetEd25519PublicKeyHex added in v1.0.79

func GetEd25519PublicKeyHex(publicKey ed25519.PublicKey) string

GetEd25519PublicKeyHex 获取Ed25519公钥的十六进制字符串表示

func GetPublicKeyFromPrivate added in v1.0.80

func GetPublicKeyFromPrivate(privateKeyBase64 string) (string, error)

GetPublicKeyFromPrivate 从私钥提取公钥

func Md5

func Md5(txt string) string

func SaveEd25519PrivateKey added in v1.0.79

func SaveEd25519PrivateKey(privateKey ed25519.PrivateKey, filename string) error

SaveEd25519PrivateKey 将Ed25519私钥保存到PEM格式文件

func SaveEd25519PublicKey added in v1.0.79

func SaveEd25519PublicKey(publicKey ed25519.PublicKey, filename string) error

SaveEd25519PublicKey 将Ed25519公钥保存到PEM格式文件

func SaveRSAPrivateKey

func SaveRSAPrivateKey(private *rsa.PrivateKey)

func SaveRSAPublicKey

func SaveRSAPublicKey(public *rsa.PublicKey)

func Sha2

func Sha2(txt string) string

func SignWithEd25519 added in v1.0.79

func SignWithEd25519(message []byte, privateKey ed25519.PrivateKey) []byte

SignWithEd25519 使用Ed25519私钥对消息进行签名

func VerifyEd25519Signature added in v1.0.79

func VerifyEd25519Signature(publicKey ed25519.PublicKey, message []byte, signature []byte) bool

VerifyEd25519Signature 验证Ed25519签名

Types

This section is empty.

Jump to

Keyboard shortcuts

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