cryptography

package
v0.4.10 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ECDSACreateKey

func ECDSACreateKey(cfg ECDSACreateKeyCfg) (privPEM string, pubPEM string, err error)

ECDSACreateKey generates an ECDSA key pair and returns - privPEM: PEM-encoded EC PRIVATE KEY (SEC1 / ASN.1) - pubPEM: PEM-encoded PUBLIC KEY (SubjectPublicKeyInfo / X.509) This keeps them interoperable with common tooling (OpenSSL, Go x509, etc.).

func ECDSASignFile

func ECDSASignFile(priv *ecdsa.PrivateKey, inputPath string) (string, error)

ECDSASignFile creates a detached signature for a file. It returns a PEM-like armored signature that embeds: - Hash: SHA-256 of file content - Signature: DER-encoded ECDSA signature, Base64-encoded

Note: For simplicity, we fix the hash to SHA-256. You can parameterize it if needed, but ensure verifier matches the same hash.

func ECDSAVerifyFile

func ECDSAVerifyFile(pub *ecdsa.PublicKey, inputPath string, armoredSignature string) error

ECDSAVerifyFile verifies a detached ECDSA signature against the file.

func EmailToWKD

func EmailToWKD(email string) string

func InterfaceToChecksum

func InterfaceToChecksum(inputInterface interface{}) (string, error)

func LoadArmoredKeyRing

func LoadArmoredKeyRing(armoredData string) (openpgp.EntityList, error)

LoadArmoredKeyRing reads an ASCII-armored key (public or private) and returns an openpgp.EntityList.

func LoadBinaryKeyRing

func LoadBinaryKeyRing(binaryData []byte) (openpgp.EntityList, error)

LoadBinaryKeyRing reads binary (non-armored) OpenPGP keys.

func LoadKeyRingAuto

func LoadKeyRingAuto(data []byte) (openpgp.EntityList, error)

LoadKeyRingAuto detects armored or binary PGP key material and loads it.

func PGPCreateKey

func PGPCreateKey(cfg PGPCreateKeyCfg) (string, string, error)

func PGPSignFile

func PGPSignFile(entityList openpgp.EntityList, inputPath string) (string, error)

PGPSignFile creates a detached ASCII-armored signature for a file. It outputs a .asc (detached) signature, similar to "pgp --detach-sign".

func PGPVerifyFile

func PGPVerifyFile(entityList openpgp.EntityList, inputPath string, signature bytes.Buffer) error

PGPVerifyFile verifies a detached signature against a given file using a public key. Returns nil if valid, error if not.

func ParseECDSAPrivateKeyFromPEM

func ParseECDSAPrivateKeyFromPEM(pemStr string) (*ecdsa.PrivateKey, error)

ParseECDSAPrivateKeyFromPEM parses a PEM-encoded "EC PRIVATE KEY".

func ParseECDSAPublicKeyFromPEM

func ParseECDSAPublicKeyFromPEM(pemStr string) (*ecdsa.PublicKey, error)

ParseECDSAPublicKeyFromPEM parses a PEM-encoded "PUBLIC KEY" (SPKI).

func Sha256SumBatch

func Sha256SumBatch(paths []string) (string, error)

sha256SumBatch computes SHA-256 checksums for multiple files and returns a string in the typical "checksums.txt" format.

func Sha256SumFile

func Sha256SumFile(path string) (string, error)

sha256SumFile computes the SHA-256 checksum for a given file path. It returns the checksum as a hex-encoded string.

func Sha256SumVerify

func Sha256SumVerify(path string, checksum string) error

Types

type ECDSACreateKeyCfg

type ECDSACreateKeyCfg struct {
	// Metadata fields included for parity with PGP config; they are not embedded
	// into the ECDSA keys themselves (no native user ID in raw ECDSA keys).
	Comment string
	Email   string
	Name    string

	// Curve selection
	Curve ECDSACurve
}

func DefaultECDSACreateKeyCfg

func DefaultECDSACreateKeyCfg() *ECDSACreateKeyCfg

func (*ECDSACreateKeyCfg) WithComment

func (c *ECDSACreateKeyCfg) WithComment(comment string) *ECDSACreateKeyCfg

func (*ECDSACreateKeyCfg) WithCurve

func (c *ECDSACreateKeyCfg) WithCurve(curve ECDSACurve) *ECDSACreateKeyCfg

func (*ECDSACreateKeyCfg) WithEmail

func (c *ECDSACreateKeyCfg) WithEmail(email string) *ECDSACreateKeyCfg

func (*ECDSACreateKeyCfg) WithName

func (c *ECDSACreateKeyCfg) WithName(name string) *ECDSACreateKeyCfg

type ECDSACurve

type ECDSACurve string
const (
	ECDSACurveP256 ECDSACurve = "P-256"
	ECDSACurveP384 ECDSACurve = "P-384"
	ECDSACurveP521 ECDSACurve = "P-521"
)

type KeyInfo

type KeyInfo struct {
	Format    string // "PGP", "X509", or "SSH"
	Kind      string // "Public" or "Private"
	Algorithm string // "RSA", "ECDSA", "Ed25519", etc.
	Detail    string // curve name, bits, encrypted, etc.
}

func DetectSignatureInformation

func DetectSignatureInformation(data []byte) (*KeyInfo, error)

type PGPCreateKeyCfg

type PGPCreateKeyCfg struct {
	Comment          string
	Email            string
	Name             string
	OutputPrivateKey string
	OutputPublicKey  string
	Hash             crypto.Hash
	Cipher           packet.CipherFunction
	CompressionAlgo  packet.CompressionAlgo
	RSABits          int
}

func DefaultPGPCreateKeyCfg

func DefaultPGPCreateKeyCfg() *PGPCreateKeyCfg

func (*PGPCreateKeyCfg) WithComment

func (c *PGPCreateKeyCfg) WithComment(comment string) *PGPCreateKeyCfg

func (*PGPCreateKeyCfg) WithEmail

func (c *PGPCreateKeyCfg) WithEmail(email string) *PGPCreateKeyCfg

func (*PGPCreateKeyCfg) WithName

func (c *PGPCreateKeyCfg) WithName(name string) *PGPCreateKeyCfg

Jump to

Keyboard shortcuts

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