Documentation ¶
Overview ¶
Package crypto provides utilities for working with cryptographic operations such as key generation, signing, and verification.
Index ¶
- func CompressString(input string) ([]byte, error)
- func DecodeSignature(encodedSig string) ([]byte, error)
- func DecompressString(input []byte) (string, error)
- func Decrypt(encryptedText, password string) (string, error)
- func Encrypt(plainText, password string) (string, error)
- func GetEnvironmentVariable(varname string) string
- func HashString(data string) []byte
- func SaveEnvironmentVariable(varname string, data string) error
- type KeyPair
- type PrivateKey
- type PublicKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompressString ¶
func DecodeSignature ¶
StringToSignature decodes a hexadecimal encoded signature string into a byte slice.
func DecompressString ¶
func GetEnvironmentVariable ¶
func HashString ¶
hashString computes the SHA-256 hash of the input string and returns the result as a byte slice.
func SaveEnvironmentVariable ¶
Types ¶
type KeyPair ¶
type KeyPair struct { PrivateKey *PrivateKey PublicKey *PublicKey Address string }
KeyPair represents a client with a private key, public key, and address.
func KeyPairFromPK ¶
KeyPairFromPK creates a new KeyPair from a private key string.
func NewKeyPair ¶
func NewKeyPair() *KeyPair
NewKeyPair creates a new KeyPair with a generated private key.
type PrivateKey ¶
type PrivateKey struct {
// contains filtered or unexported fields
}
PrivateKey represents a cryptographic private key.
func DecodePrivateKey ¶
func DecodePrivateKey(encoded string) (*PrivateKey, error)
NewPrivateKeyFromStr creates a new PrivateKey instance from a hexadecimal encoded string.
func NewPrivateKey ¶
func NewPrivateKey() (*PrivateKey, error)
NewPrivateKey generates a new cryptographic private key.
func (*PrivateKey) EncodeSignature ¶
func (pk *PrivateKey) EncodeSignature(msg string) (string, error)
SignToString signs a message and returns the base64-encoded signature as a string.
func (*PrivateKey) PublicKey ¶
func (pk *PrivateKey) PublicKey() *PublicKey
PublicKey returns the corresponding public key.
func (*PrivateKey) Sign ¶
func (pk *PrivateKey) Sign(msg string) ([]byte, error)
Sign signs a message using the private key and returns the signature as a byte slice.
func (*PrivateKey) String ¶
func (pk *PrivateKey) String() string
String returns the hexadecimal representation of the private key with "0x" prefix.
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
PublicKey represents a cryptographic public key.
func DecodePublicKey ¶
NewPublicKeyFromStr creates a new PublicKey instance from a hexadecimal encoded string.
func RecoverPublicKeyFromSignature ¶
RecoverPublicKeyFromSignature recovers a public key from a message signature.