mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-21 15:33:17 +01:00
Support SHA512 as hashing algorithm (#8)
This commit is contained in:
parent
9220a777bb
commit
c0b1fefec8
12
security/sha512.go
Normal file
12
security/sha512.go
Normal file
@ -0,0 +1,12 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"crypto/sha512"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func Sha512(s string) string {
|
||||
hash := sha512.New()
|
||||
hash.Write([]byte(s))
|
||||
return fmt.Sprintf("%x", hash.Sum(nil))
|
||||
}
|
12
security/sha512_test.go
Normal file
12
security/sha512_test.go
Normal file
@ -0,0 +1,12 @@
|
||||
package security
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSha512(t *testing.T) {
|
||||
input := "password"
|
||||
expectedHash := "b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86"
|
||||
hash := Sha512(input)
|
||||
if hash != expectedHash {
|
||||
t.Errorf("Expected hash to be '%s', but was '%s'", expectedHash, hash)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user