encrypt

package
v1.2.13 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AesDecrypt added in v1.2.10

func AesDecrypt(encrypted string, secret string) (decrypted string, err error)

AesDecrypt 使用 AES 加密算法解密消息

  • encrypted: 加密后的消息
  • secret: 密钥,长度必须是 16、24 或 32 位
  • decrypted: 解密后的消息
  • err: 错误信息

没有出错重试机制,出错直接返回 err

func AesEncrypt added in v1.2.10

func AesEncrypt(message string, secret string) (encrypted string, err error)

AesEncrypt 使用 AES 加密算法加密消息

  • message: 明文消息
  • secret: 密钥,长度必须是 16、24 或 32 位
  • encrypted: 加密后的消息
  • err: 错误信息

没有出错重试机制,出错直接返回 err

func BcryptCheck

func BcryptCheck(password, hashed string) bool

BcryptCheck 使用 bcrypt 加密算法校验密码

  • password: 明文密码
  • hashed: 加密后的密码
  • bool: 校验结果

func BcryptEncode

func BcryptEncode(password string) (encoded string, err error)

BcryptEncode 使用 bcrypt 加密算法加密密码

  • password: 明文密码
  • encoded: 加密后的密码
  • err: 错误信息

没有出错重试机制,出错直接返回 err

func HashEntryMD5

func HashEntryMD5[T any](entry T) string

HashEntryMD5 使用 MD5 算法计算结构体的哈希值

func HashMD5

func HashMD5(message string) string

HashMD5 使用 MD5 算法计算消息的哈希值

func RsaDecrypt added in v1.2.10

func RsaDecrypt(privateKey, encrypted string) (message string, err error)

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

func RsaEncrypt(publicKey, message string) (encrypted string, err error)

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

func RsaKeyGenerate(length int) (privateKey, publicKey string, err error)

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.

Jump to

Keyboard shortcuts

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