Documentation
¶
Index ¶
- Constants
- Variables
- func CompareScrypt(password, encodedHash string) error
- func ConsumeDAOKey(ctx context.Context, key *dao.KeyEntity, private bool) (*jwa.JWK, error)
- func DecryptMasterKey(ctx context.Context, data []byte, output any) error
- func EncryptMasterKey(ctx context.Context, data any) ([]byte, error)
- func GenerateScrypt(password string, params ScryptParams) (string, error)
- func MasterKeyContext(ctx context.Context) ([32]byte, error)
- func NewAgoraContext(parentCTX context.Context) (context.Context, error)
- func NewMasterKeyContext(ctx context.Context) (context.Context, error)
- func NewRandomURLString(length int) (string, error)
- func SendMail(ctx context.Context, message *mail.SGMailV3)
- type ScryptParams
Constants ¶
const (
MasterKeyEnv = "MASTER_KEY"
)
Variables ¶
var ( ErrInvalidHash = errors.New("the encoded hash is in an invalid format") ErrIncompatibleVersion = errors.New("the encoded hash is using an incompatible version of Argon2") ErrInvalidPassword = errors.New("the password is invalid") )
var ErrInvalidSecret = errors.New("invalid secret")
var ErrNoMasterKey = errors.New("missing master key")
var ScryptParamsDefault = ScryptParams{
SaltLength: 32,
Iterations: 1,
Memory: 64 * 1024,
Parallelism: 4,
KeyLength: 32,
}
var URLCharList = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
URLCharList is a list of URL-valid characters, for generating random strings.
Functions ¶
func CompareScrypt ¶
CompareScrypt compares a password with an encoded hash generated by GenerateScrypt. It returns true if the password matches the hash, and false otherwise.
This method is similar to bcrypt.CompareHashAndPassword, but based on the newer Argon2 algorithm.
func ConsumeDAOKey ¶
ConsumeDAOKey converts a key from DAO entity to aJWK object.
func DecryptMasterKey ¶
DecryptMasterKey decrypts the input using the master key.
func EncryptMasterKey ¶
EncryptMasterKey encrypts the input using the master key.
func GenerateScrypt ¶
func GenerateScrypt(password string, params ScryptParams) (string, error)
GenerateScrypt is a secure hash method, similar to bcrypt.GenerateFromPassword, but based on the newer Argon2 algorithm.
func NewRandomURLString ¶
Types ¶
type ScryptParams ¶
type ScryptParams struct {
// SaltLength is the length of the salt in bytes.
SaltLength uint
// Iterations is the number of iterations to use.
Iterations uint32
// Memory is the amount of memory used by the algorithm.
Memory uint32
// Parallelism is the number of threads to use.
Parallelism uint8
// KeyLength is the length of the derived key.
KeyLength uint32
}
ScryptParams contains the parameters used to generate a hash using the Argon2 algorithm.
You can use ScryptParamsDefault unless you have specific requirements.