diff options
author | E99p1ant <i@github.red> | 2022-06-05 13:34:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-05 13:34:21 +0800 |
commit | a328e7ccc4f94e19cddfe5894636228663f5c7fa (patch) | |
tree | 34d827770f004a40eb8dc1feb44109e63452d5a0 /internal/cryptoutil/sha.go | |
parent | 155cae1de8916fc3fde78f350763034b7422caee (diff) |
access_token: encrypt access token with SHA256 (#7008)
* access_token: encrypt access token with SHA256
* revert list access token
* fix lint
* generate schemadoc
* add database migrations
* fix tests
* fix tests
* add test case for access token golden
* fix test in postgres
* `Sha256` -> `SHA256`
* Use GORM for migration
* task generate-schemadoc
* Use unique
* change migration name
* allow read
* task generate-schemadoc
* add changelog
* fix lint error
* update changelog
* remove Debug
* add comments
Co-authored-by: Joe Chen <jc@unknwon.io>
Diffstat (limited to 'internal/cryptoutil/sha.go')
-rw-r--r-- | internal/cryptoutil/sha.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/internal/cryptoutil/sha.go b/internal/cryptoutil/sha.go new file mode 100644 index 00000000..d829d526 --- /dev/null +++ b/internal/cryptoutil/sha.go @@ -0,0 +1,25 @@ +// Copyright 2020 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package cryptoutil + +import ( + "crypto/sha1" + "crypto/sha256" + "encoding/hex" +) + +// SHA1 encodes string to hexadecimal of SHA1 checksum. +func SHA1(str string) string { + h := sha1.New() + _, _ = h.Write([]byte(str)) + return hex.EncodeToString(h.Sum(nil)) +} + +// SHA256 encodes string to hexadecimal of SHA256 checksum. +func SHA256(str string) string { + h := sha256.New() + _, _ = h.Write([]byte(str)) + return hex.EncodeToString(h.Sum(nil)) +} |