Documentation ¶
Index ¶
- func ComputeSignature(accessSecretKey, payload string, headers map[string]string) string
- func GetSignatureKey(accessSecretKey, timeStamp, apiName, apiVersion string) []byte
- func HmacSha256(data string, key []byte) []byte
- func Sha256(input string) []byte
- func VerifySignature(tokenHeader, securityHeader, payload string, ...) error
- type AccessSecretProvider
- type CryptoConfig
- type CryptoUtil
- func (h *CryptoUtil) CompareHash(ctx context.Context, plainName, storedHash []byte) (bool, error)
- func (u *CryptoUtil) CreateAlias(ctx context.Context, plain []byte) ([]byte, error)
- func (u *CryptoUtil) Decrypt(ctx context.Context, cipeherText string) ([]byte, error)
- func (u *CryptoUtil) DecryptWithKey(ctx context.Context, key, cipeherText string) ([]byte, error)
- func (u *CryptoUtil) Encrypt(ctx context.Context, plainText []byte) (string, error)
- func (u *CryptoUtil) EncryptWithKey(ctx context.Context, key, plainText string) (string, error)
- func (u *CryptoUtil) GenerateAesKey(ctx context.Context, key string) (string, error)
- type DbAccessSecretProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeSignature ¶
ComputeSignature generates a signature for the given payload and headers. It uses the access secret key, timestamp, API name, and API version to compute a unique signature. The computed signature is then returned as a string.
func GetSignatureKey ¶
GetSignatureKey generates a signature key using the provided parameters. It combines the access secret key, timestamp, API name, and API version to create a unique signature key.
func HmacSha256 ¶
HmacSha256 computes the HMAC-SHA256 of the given data using the provided key. It returns the resulting hash as a byte slice.
func Sha256 ¶
Sha256 computes the SHA256 hash of the input string. It returns the resulting hash as a byte slice.
func VerifySignature ¶
func VerifySignature(tokenHeader, securityHeader, payload string, accessSecretProvider AccessSecretProvider) error
VerifySignature verifies the signature of the given payload and headers. It uses the access secret key, timestamp, API name, and API version to compute a unique signature and compare it with the provided signature.
Types ¶
type AccessSecretProvider ¶
AccessSecretProvider is an interface for retrieving access secrets. Implementations of this interface should provide a method to get an access secret given an access key ID.
type CryptoConfig ¶
type CryptoUtil ¶
type CryptoUtil struct {
// contains filtered or unexported fields
}
func NewCryptoUtil ¶
func NewCryptoUtil(cfg *CryptoConfig) *CryptoUtil
func (*CryptoUtil) CompareHash ¶
CompareHash compares the plain text with the stored hash. It returns true if the plain text is the same as the stored hash.
func (*CryptoUtil) CreateAlias ¶
CreateAlias creates an alias for the given plain text. It returns the hashed value of the plain text.
func (*CryptoUtil) Decrypt ¶
Decrypt decrypts the given cipher text. It returns the decrypted value of the cipher text.
func (*CryptoUtil) DecryptWithKey ¶
DecryptWithKey decrypts the given cipher text with the given key. It returns the decrypted value of the cipher text.
func (*CryptoUtil) Encrypt ¶
Encrypt encrypts the given plain text. It returns the encrypted value of the plain text.
func (*CryptoUtil) EncryptWithKey ¶
EncryptWithKey encrypts the given plain text with the given key. It returns the encrypted value of the plain text.
func (*CryptoUtil) GenerateAesKey ¶
GenerateAesKey generates an AES key. It returns the AES key.
type DbAccessSecretProvider ¶
type DbAccessSecretProvider struct {
// contains filtered or unexported fields
}
func NewDbAccessSecretProvider ¶
func NewDbAccessSecretProvider(db *gorm.DB) *DbAccessSecretProvider
func (*DbAccessSecretProvider) GetAccessSecret ¶
func (p *DbAccessSecretProvider) GetAccessSecret(accessKeyId string) (string, error)
GetAccessSecret retrieves the access secret for a given access key ID. It first checks the in-memory cache, and if not found, queries the database. The retrieved secret is then cached for future use.