Documentation
¶
Overview ¶
Package encrypt 提供AES ECB模式的加密解密功能
Package encrypt 提供RSA非对称加密解密和数字签名功能
Index ¶
- func AesEcbDecrypt(cryptText string, key string, isPad ...bool) (string, error)
- func AesEcbEncrypt(plainText string, key string, isPad ...bool) (string, error)
- func RsaDecrypt(privateKey *rsa.PrivateKey, cipherBytes []byte) ([]byte, error)
- func RsaDecryptFromBase64(privateKey *rsa.PrivateKey, cipherText string) (string, error)
- func RsaEncrypt(publicKey *rsa.PublicKey, plainText string) ([]byte, error)
- func RsaEncrypt2Base64(publicKey *rsa.PublicKey, plainText string) (string, error)
- func RsaGeneratePrivateKey(bits int) (*rsa.PrivateKey, error)
- func RsaReadPrivatePem(filePath string) (*rsa.PrivateKey, error)
- func RsaReadPublicPem(filePath string) (*rsa.PublicKey, error)
- func RsaSavePrivatePem(privateKey *rsa.PrivateKey, filePath string) error
- func RsaSavePublicPem(publicKey *rsa.PublicKey, filePath string) error
- func RsaSign(privateKey *rsa.PrivateKey, plaintext string) ([]byte, error)
- func RsaSign2Base64(privateKey *rsa.PrivateKey, plaintext string) (string, error)
- func RsaValidSign(publicKey *rsa.PublicKey, ciphertext string, signBytes []byte) error
- func RsaValidSignFromBase64(publicKey *rsa.PublicKey, ciphertext string, sign string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AesEcbDecrypt ¶
AesEcbDecrypt AES ECB模式解密 cryptText: base64编码的密文 key: 解密密钥,长度必须为16、24或32字节 isPad: 是否使用padding填充,默认为true 返回: 解密后的明文和错误信息
func AesEcbEncrypt ¶
AesEcbEncrypt AES ECB模式加密 plainText: 待加密的明文 key: 加密密钥,长度必须为16、24或32字节 isPad: 是否使用padding填充,默认为true 返回: base64编码的加密结果和错误信息
func RsaDecrypt ¶
func RsaDecrypt(privateKey *rsa.PrivateKey, cipherBytes []byte) ([]byte, error)
RsaDecrypt 使用RSA私钥解密数据 privateKey: RSA私钥对象 cipherBytes: 待解密的密文字节数组 返回: 解密后的明文字节数组和错误信息
func RsaDecryptFromBase64 ¶
func RsaDecryptFromBase64(privateKey *rsa.PrivateKey, cipherText string) (string, error)
RsaDecryptFromBase64 使用RSA私钥解密base64编码的密文 privateKey: RSA私钥对象 cipherText: base64编码的密文 返回: 解密后的明文和错误信息
func RsaEncrypt ¶
RsaEncrypt 使用RSA公钥加密数据 publicKey: RSA公钥对象 plainText: 待加密的明文 返回: 加密后的字节数组和错误信息
func RsaEncrypt2Base64 ¶
RsaEncrypt2Base64 使用RSA公钥加密数据并返回base64编码的密文 publicKey: RSA公钥对象 plainText: 待加密的明文 返回: base64编码的加密结果和错误信息
func RsaGeneratePrivateKey ¶
func RsaGeneratePrivateKey(bits int) (*rsa.PrivateKey, error)
RsaGeneratePrivateKey 生成指定长度的RSA私钥 bits: 密钥长度,建议使用2048或4096位 返回: RSA私钥对象和错误信息
func RsaReadPrivatePem ¶
func RsaReadPrivatePem(filePath string) (*rsa.PrivateKey, error)
RsaReadPrivatePem 从文件中读取PEM格式的RSA私钥 filePath: 私钥文件路径 返回: RSA私钥对象和错误信息
func RsaReadPublicPem ¶
RsaReadPublicPem 从文件中读取PEM格式的RSA公钥 filePath: 公钥文件路径 返回: RSA公钥对象和错误信息
func RsaSavePrivatePem ¶
func RsaSavePrivatePem(privateKey *rsa.PrivateKey, filePath string) error
RsaSavePrivatePem 将RSA私钥保存为PEM格式文件 privateKey: RSA私钥对象 filePath: 保存路径 返回: 错误信息
func RsaSavePublicPem ¶
RsaSavePublicPem 将RSA公钥保存为PEM格式文件 publicKey: RSA公钥对象 filePath: 保存路径 返回: 错误信息
func RsaSign ¶
func RsaSign(privateKey *rsa.PrivateKey, plaintext string) ([]byte, error)
RsaSign 使用RSA私钥对数据进行数字签名 privateKey: RSA私钥对象 plaintext: 待签名的明文 返回: 签名字节数组和错误信息
func RsaSign2Base64 ¶
func RsaSign2Base64(privateKey *rsa.PrivateKey, plaintext string) (string, error)
RsaSign2Base64 使用RSA私钥对数据进行数字签名并返回base64编码 privateKey: RSA私钥对象 plaintext: 待签名的明文 返回: base64编码的签名和错误信息
func RsaValidSign ¶
RsaValidSign 使用RSA公钥验证数字签名 publicKey: RSA公钥对象 ciphertext: 原始明文 signBytes: 签名字节数组 返回: 验证结果错误信息
Types ¶
This section is empty.