Documentation
¶
Index ¶
- func ConstantTimeEqual(a, b []byte) bool
- func GenerateRandomBytes(length int) ([]byte, error)
- func GenerateRandomKey(length int) string
- type Encrypter
- type SignedMessage
- type SignedURL
- type Signer
- func (s *Signer) Hash(message string) string
- func (s *Signer) HashHMAC(message string) string
- func (s *Signer) Sign(message string) string
- func (s *Signer) SignHMAC(message string) string
- func (s *Signer) SignURL(url string) *SignedURL
- func (s *Signer) SignWithTimestamp(message string, timestamp int64) *SignedMessage
- func (s *Signer) Verify(message, signature string) bool
- func (s *Signer) VerifyHMAC(message, signature string) bool
- func (s *Signer) VerifySignedMessage(sm *SignedMessage, maxAge int64) bool
- func (s *Signer) VerifyURL(url, signature string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConstantTimeEqual ¶
ConstantTimeEqual performs constant-time comparison of two byte slices.
func GenerateRandomBytes ¶
GenerateRandomBytes generates cryptographically secure random bytes.
func GenerateRandomKey ¶
GenerateRandomKey generates a cryptographically secure random key.
Types ¶
type Encrypter ¶
type Encrypter struct {
// contains filtered or unexported fields
}
Encrypter manages data encryption and decryption.
func NewEncrypter ¶
NewEncrypter creates a new encrypter instance. Keys are hashed with SHA-256 to produce a consistent 32-byte key, preventing collision from zero-padding short keys.
type SignedMessage ¶
type SignedMessage struct {
Payload string `json:"payload"`
Signature string `json:"signature"`
Timestamp int64 `json:"timestamp"`
}
SignedMessage represents a signed message with timestamp.
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
Signer provides message signing and verification.
func (*Signer) SignWithTimestamp ¶
func (s *Signer) SignWithTimestamp(message string, timestamp int64) *SignedMessage
SignWithTimestamp signs a message with a timestamp.
func (*Signer) VerifyHMAC ¶
VerifyHMAC verifies a message signature using HMAC-SHA512.
func (*Signer) VerifySignedMessage ¶
func (s *Signer) VerifySignedMessage(sm *SignedMessage, maxAge int64) bool
VerifySignedMessage verifies a signed message with timestamp.