Skip to content

Commit 15582d0

Browse files
committed
Encryption fix
1 parent d4feea6 commit 15582d0

4 files changed

Lines changed: 8 additions & 10 deletions

File tree

‎app/util/encryption.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ func HashFNV128UUID(s string) uuid.UUID {
115115

116116
// HashSHA256 returns a Base64-encoded string representing the SHA-256 hash of the argument.
117117
func HashSHA256(s string) string {
118-
h := sha256.New()
119-
ret := h.Sum([]byte(s))
120-
return base64.URLEncoding.EncodeToString(ret)
118+
h := sha256.Sum256([]byte(s))
119+
return base64.URLEncoding.EncodeToString(h[:])
121120
}
122121

123122
func getKey(logger Logger) []byte {

‎app/util/encryption_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ var hashTests = []struct {
1313
hash32 uint32
1414
hashSHA string
1515
}{
16-
{plaintext: "Hello, world!", hash32: 3985698964, hashSHA: "SGVsbG8sIHdvcmxkIeOwxEKY_BwUmvv0yJlvuSQnrkHkZJuTTKSVmRt4UrhV"},
17-
{plaintext: "Goodbye, cruel world!", hash32: 55824456, hashSHA: "R29vZGJ5ZSwgY3J1ZWwgd29ybGQh47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU="},
16+
{plaintext: "Hello, world!", hash32: 3985698964, hashSHA: "MV9b23bQeMQ7isAGTkoBZGErH853yGk0W_yUx1iU7dM="},
17+
{plaintext: "Goodbye, cruel world!", hash32: 55824456, hashSHA: "Rpwk-Ulwczqp08GLqIuBalVyzchihsMBB-P_y574jgU="},
1818
}
1919

2020
func TestEncryptDecrypt(t *testing.T) {

‎module/core/app/util/encryption.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ func HashFNV128UUID(s string) uuid.UUID {
115115

116116
// HashSHA256 returns a Base64-encoded string representing the SHA-256 hash of the argument.
117117
func HashSHA256(s string) string {
118-
h := sha256.New()
119-
ret := h.Sum([]byte(s))
120-
return base64.URLEncoding.EncodeToString(ret)
118+
h := sha256.Sum256([]byte(s))
119+
return base64.URLEncoding.EncodeToString(h[:])
121120
}
122121

123122
func getKey(logger Logger) []byte {

‎module/core/app/util/encryption_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ var hashTests = []struct {
1313
hash32 uint32
1414
hashSHA string
1515
}{
16-
{plaintext: "Hello, world!", hash32: 3985698964, hashSHA: "SGVsbG8sIHdvcmxkIeOwxEKY_BwUmvv0yJlvuSQnrkHkZJuTTKSVmRt4UrhV"},
17-
{plaintext: "Goodbye, cruel world!", hash32: 55824456, hashSHA: "R29vZGJ5ZSwgY3J1ZWwgd29ybGQh47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU="},
16+
{plaintext: "Hello, world!", hash32: 3985698964, hashSHA: "MV9b23bQeMQ7isAGTkoBZGErH853yGk0W_yUx1iU7dM="},
17+
{plaintext: "Goodbye, cruel world!", hash32: 55824456, hashSHA: "Rpwk-Ulwczqp08GLqIuBalVyzchihsMBB-P_y574jgU="},
1818
}
1919

2020
func TestEncryptDecrypt(t *testing.T) {

0 commit comments

Comments
 (0)