API Security
Message Signing and Verification
API_KEY and API_KEY_SECRET
func generateAPIKeySecret(length int) (string, error) {
if length <= 0 {
return "", fmt.Errorf("length must be positive")
}
// Calculate the number of random bytes needed.
// Base64 encoding expands the data by 4/3, so we need to generate less bytes
// to get the desired length after encoding. We round up to ensure we get at least the desired length.
b := make([]byte, (length*3+3)/4)
_, err := rand.Read(b)
if err != nil {
return "", fmt.Errorf("error generating random bytes: %w", err)
}
return base64.StdEncoding.EncodeToString(b), nil
}Signing and Verification
Last updated