25 lines
		
	
	
		
			431 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			431 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| 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))
 | |
| }
 |