Files
wehub-resource-sync 498b235461
Build and test / Build and test AMD64 Ubuntu 22.04 (push) Failing after 0s
Publish Builder / amazonlinux2023 (push) Failing after 1s
Build and test / UT for Go (push) Has been skipped
Publish KRTE Images / KRTE (push) Failing after 1s
Build and test / Integration Test (push) Has been skipped
Build and test / Upload Code Coverage (push) Has been skipped
Publish Builder / rockylinux9 (push) Failing after 1s
Publish Builder / ubuntu22.04 (push) Failing after 0s
Publish Builder / ubuntu24.04 (push) Failing after 0s
Publish Gpu Builder / publish-gpu-builder (push) Failing after 1s
Publish Test Images / PyTest (push) Failing after 0s
Build and test / UT for Cpp (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:17 +08:00

55 lines
1.1 KiB
Go

package crypto
import (
"crypto/md5" // #nosec
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"golang.org/x/crypto/bcrypt"
)
func SHA256(src string, salt string) string {
h := sha256.New()
h.Write([]byte(src + salt))
sum := h.Sum(nil)
s := hex.EncodeToString(sum)
return s
}
// PasswordEncrypt encrypt password
func PasswordEncrypt(pwd string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(pwd), bcrypt.MinCost)
if err != nil {
return "", err
}
return string(bytes), err
}
func Base64Decode(pwd string) (string, error) {
bytes, err := base64.StdEncoding.DecodeString(pwd)
if err != nil {
return "", err
}
return string(bytes), err
}
func Base64Encode(pwd string) string {
return base64.StdEncoding.EncodeToString([]byte(pwd))
}
func MD5(str string) string {
// #nosec
data := md5.Sum([]byte(str))
return hex.EncodeToString(data[:])[8:24]
}
func GranteeID(str string) string {
// #nosec G401 -- RBAC grantee IDs need stable 128-bit identifiers, not password hashing.
data := md5.Sum([]byte(str))
return hex.EncodeToString(data[:])
}