ethkeystore

package
v0.783.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package ethkeystore decrypts an Ethereum V3 keystore — the encrypted JSON wallet file Geth, MyEtherWallet, MetaMask exports, and most Ethereum tooling produce — recovering the 32-byte private key with the operator's passphrase. A captured keystore file is prime crypto-forensics / IR / pentest loot: it is an offline-crackable wrapper around an Ethereum private key, the ETH counterpart to a BIP-39 seed or a WIF key. Pure offline transform; no network or device.

Wrap-vs-native judgement

Native orchestration over trusted primitives. The Web3 Secret Storage scheme is a public spec: a scrypt or PBKDF2-HMAC-SHA256 key derivation, an AES-128-CTR cipher, and a Keccak-256 MAC. The KDFs and Keccak come from golang.org/x/crypto (already a project dependency); AES/CTR are stdlib; the keystore JSON parse, the MAC check, and the field assembly are our own. No new runtime dependency, no shell-out. Address derivation (private key → public key → address) needs a secp256k1 implementation that is not a current dependency, so it is deliberately deferred — the recovered private key is the loot, and any wallet can import it.

Verifiable / no confidently-wrong output

Anchored to the canonical Web3 Secret Storage PBKDF2 test vector (passphrase "testpassword" → private key 7a28b5ba57c53603b0b07b56bba752f7784bf506fa95edc395f5cf6c7514fe9d). The MAC is the gate: Keccak-256(derivedKey[16:32] ‖ ciphertext) must equal the stored MAC. When it does not (wrong passphrase or a corrupt file) the private key is NOT surfaced — a confidently-wrong key is worse than none. A hostile scrypt N (128·N·r over 1 GiB) is rejected rather than allowed to exhaust memory; an unsupported cipher/KDF or malformed JSON is rejected.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	Version       int    `json:"version"`
	Cipher        string `json:"cipher"`
	KDF           string `json:"kdf"`
	Address       string `json:"address,omitempty"` // the file's own "address" field, if present (not derived)
	MACValid      bool   `json:"mac_valid"`
	PrivateKeyHex string `json:"private_key_hex,omitempty"`
	Note          string `json:"note,omitempty"`
}

Result is the decryption outcome.

func Decrypt

func Decrypt(jsonStr, passphrase string) (*Result, error)

Decrypt parses a V3 keystore JSON and recovers the private key with the passphrase. A malformed file or unsupported parameters return an error; a MAC mismatch (wrong passphrase / corrupt file) returns a Result with MACValid false and no private key.

Jump to

Keyboard shortcuts

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