text

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TextAesDecrypt

func TextAesDecrypt(cipherText, key string) (string, error)

TextAesDecrypt 使用AES-CFB模式解密一个经过URL安全Base64编码的字符串。 它接受一个密文字符串和一个密钥,返回解密后的明文字符串和可能的错误。

func TextAesEncrypt

func TextAesEncrypt(plainText, key string) (string, error)

TextAesEncrypt 使用AES-CFB模式加密文本。 它接受一个明文字符串和一个密钥(16、24或32字节), 返回一个经过URL安全的Base64编码的密文字符串和可能的错误。

func TextDecrypt

func TextDecrypt(priv *PrivateKey, ciphertext []byte) ([]byte, error)

TextDecrypt 使用私钥解密密文。

func TextEncrypt

func TextEncrypt(pub *PublicKey, plaintext []byte) ([]byte, error)

TextEncrypt 使用公钥对明文进行加密。 注意:这是一个基础的RSA实现,没有使用填充方案(如OAEP), 在生产环境中,推荐使用 `crypto/rsa` 包以获得更高的安全性。

func TextVerify

func TextVerify(plaintext []byte, decryptedHash []byte) bool

TextVerify 验证明文的哈希值是否与解密后的哈希值匹配。 这个函数适用于签名验证场景,即用公钥解密签名,然后与原文哈希比较。

Types

type KeyPair

type KeyPair struct {
	PublicKey  *PublicKey
	PrivateKey *PrivateKey
}

密钥对

func TextGetKeyPair

func TextGetKeyPair(bits int) (*KeyPair, error)

TextGetKeyPair 生成指定位数的RSA密钥对。

type PrivateKey

type PrivateKey struct {
	N *big.Int // 同公钥的N
	D *big.Int // 解密指数
}

type PublicKey

type PublicKey struct {
	N *big.Int // 大素数乘积
	E *big.Int // 加密指数
}

Jump to

Keyboard shortcuts

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