initial commit
This commit is contained in:
24
pkg/security/crypto.go
Normal file
24
pkg/security/crypto.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// NewSHA256 ...
|
||||
func NewSHA256(data []byte) []byte {
|
||||
if os.Getenv("SALT") == "" {
|
||||
log.Fatal("CRITICAL ERROR SALT was found to be empty")
|
||||
}
|
||||
prep := []byte(os.Getenv("SALT") + "-")
|
||||
|
||||
prep = append(prep, data...)
|
||||
hash := sha256.Sum256(prep)
|
||||
return hash[:]
|
||||
}
|
||||
|
||||
func NewSHA256asString(data []byte) string {
|
||||
return hex.EncodeToString(NewSHA256(data))
|
||||
}
|
||||
Reference in New Issue
Block a user