crypto

package
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2024 License: BSD-2-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeSignature

func ComputeSignature(accessSecretKey, payload string, headers map[string]string) string

func GetSignatureKey

func GetSignatureKey(accessSecretKey, timeStamp, apiName, apiVersion string) []byte

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

func HmacSha256(data string, key []byte) []byte

HmacSha256 computes the HMAC-SHA256 of the given data using the provided key. It returns the resulting hash as a byte slice.

func Sha256

func Sha256(input string) []byte

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, accesSecretProvider 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. The computed signature is then returned as a string.

Types

type AccessSecretProvider

type AccessSecretProvider interface {
	GetAccessSecret(accessKeyId string) (string, error)
}

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 CryptoConfig struct {
	KmsUri     string
	KeysetData string
	HmacKey    string
}

type CryptoUtil

type CryptoUtil struct {
	// contains filtered or unexported fields
}

func NewCryptoUtil

func NewCryptoUtil(cfg *CryptoConfig) *CryptoUtil

func (*CryptoUtil) CompareHash

func (h *CryptoUtil) CompareHash(ctx context.Context, plainName, storedHash []byte) (bool, error)

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

func (u *CryptoUtil) CreateAlias(ctx context.Context, plain []byte) ([]byte, error)

CreateAlias creates an alias for the given plain text. It returns the hashed value of the plain text.

func (*CryptoUtil) Decrypt

func (u *CryptoUtil) Decrypt(ctx context.Context, cipeherText string) ([]byte, error)

Decrypt decrypts the given cipher text. It returns the decrypted value of the cipher text.

func (*CryptoUtil) DecryptWithKey

func (u *CryptoUtil) DecryptWithKey(ctx context.Context, key, cipeherText string) ([]byte, error)

DecryptWithKey decrypts the given cipher text with the given key. It returns the decrypted value of the cipher text.

func (*CryptoUtil) Encrypt

func (u *CryptoUtil) Encrypt(ctx context.Context, plainText []byte) (string, error)

Encrypt encrypts the given plain text. It returns the encrypted value of the plain text.

func (*CryptoUtil) EncryptWithKey

func (u *CryptoUtil) EncryptWithKey(ctx context.Context, key, plainText string) (string, error)

EncryptWithKey encrypts the given plain text with the given key. It returns the encrypted value of the plain text.

func (*CryptoUtil) GenerateAesKey

func (u *CryptoUtil) GenerateAesKey(ctx context.Context, key string) (string, error)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL