Desded.go 618 B

123456789101112131415161718192021
  1. package security
  2. import (
  3. "confrontation-training/constant"
  4. "encoding/base64"
  5. "github.com/forgoer/openssl"
  6. )
  7. func Encrypt(src string) string {
  8. encrypt, _ := openssl.Des3CBCEncrypt([]byte(src), []byte(constant.DefaultKey), []byte(constant.DefaultIv), openssl.PKCS5_PADDING)
  9. return base64.StdEncoding.EncodeToString(encrypt)
  10. }
  11. func Decrypt(src string) string {
  12. decodeString, err := base64.StdEncoding.DecodeString(src)
  13. if err != nil {
  14. return ""
  15. }
  16. decrypt, err := openssl.Des3CBCDecrypt(decodeString, []byte(constant.DefaultKey), []byte(constant.DefaultIv), openssl.PKCS5_PADDING)
  17. return string(decrypt)
  18. }