mirror of
https://github.com/go-gitea/gitea.git
synced 2025-08-18 14:44:06 +09:00
Add simple master key provider for secret encryption
This commit is contained in:
@ -9,6 +9,7 @@ import (
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"io"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
@ -67,3 +68,23 @@ func NewSecretKey() (string, error) {
|
||||
|
||||
return secretKey, nil
|
||||
}
|
||||
|
||||
// NewMasterKey generate a new value intended to be used by MASTER_KEY.
|
||||
func NewMasterKey() ([]byte, error) {
|
||||
secretBytes := make([]byte, 32)
|
||||
_, err := io.ReadFull(rand.Reader, secretBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return secretBytes, nil
|
||||
}
|
||||
|
||||
func randomInt(max *big.Int) (int, error) {
|
||||
rand, err := rand.Int(rand.Reader, max)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return int(rand.Int64()), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user