Documentation ¶
Index ¶
- func AesDecrypt(encrypted string, secret string) (decrypted string, err error)
- func AesEncrypt(message string, secret string) (encrypted string, err error)
- func BcryptCheck(password, hashed string) bool
- func BcryptEncode(password string) (encoded string, err error)
- func HashEntryMD5[T any](entry T) string
- func HashMD5(message string) string
- func RsaDecrypt(privateKey, encrypted string) (message string, err error)
- func RsaEncrypt(publicKey, message string) (encrypted string, err error)
- func RsaKeyGenerate(length int) (privateKey, publicKey string, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AesDecrypt ¶ added in v1.2.10
AesDecrypt 使用 AES 加密算法解密消息
- encrypted: 加密后的消息
- secret: 密钥,长度必须是 16、24 或 32 位
- decrypted: 解密后的消息
- err: 错误信息
没有出错重试机制,出错直接返回 err
func AesEncrypt ¶ added in v1.2.10
AesEncrypt 使用 AES 加密算法加密消息
- message: 明文消息
- secret: 密钥,长度必须是 16、24 或 32 位
- encrypted: 加密后的消息
- err: 错误信息
没有出错重试机制,出错直接返回 err
func BcryptEncode ¶
BcryptEncode 使用 bcrypt 加密算法加密密码
- password: 明文密码
- encoded: 加密后的密码
- err: 错误信息
没有出错重试机制,出错直接返回 err
func RsaDecrypt ¶ added in v1.2.10
RsaDecrypt decrypts encrypted data using the provided RSA private key.
- privateKey: RSA private key, pem format
- encrypted: encrypted data, pem format
- message: decrypted data
- err: error message
example:
privateKey, _, generateKeyErr := RsaKeyGenerate(2048) if generateKeyErr != nil { t.Error(generateKeyErr) } encrypted, encryptErr := RsaEncrypt(publicKey, "i love u") if encryptErr != nil { t.Error(encryptErr) } decrypted, decryptErr := RsaDecrypt(privateKey, encrypted) if decryptErr != nil { t.Error(decryptErr) }
func RsaEncrypt ¶ added in v1.2.10
RsaEncrypt encrypts the given message using the RSA public key.
- publicKey: RSA public key, pem format
- message: message to be encrypted
- encrypted: encrypted data, pem format
- err: error message
example:
privateKey, publicKey, generateKeyErr := RsaKeyGenerate(2048) if generateKeyErr != nil { t.Error(generateKeyErr) } encrypted, encryptErr := RsaEncrypt(publicKey, "i love u") if encryptErr != nil { t.Error(encryptErr) }
func RsaKeyGenerate ¶ added in v1.2.10
RsaKeyGenerate generates RSA private key and public key.
- length: length of the key, minimum 386, recommended 2048 and above
- privateKey: RSA private key, pem format
- publicKey: RSA public key, pem format
- err: error message
example:
privateKey, publicKey, err := RsaKeyGenerate(2048)
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.