Avatar CS Knowledge Wiki

Ethereum Wallet Encryption

原文链接:https://www.yuque.com/yangguangfanxing/zuyi8o/dumdplx13g4fna0t

原文链接:https://www.yuque.com/yangguangfanxing/zuyi8o/dumdplx13g4fna0t ↗

To illustrate the application of the AES cipher in action, we shall look into one real-world example: the standard encrypted wallet file format for the Ethereum blockchain. We shall see how AES-128-CTR cipher is combined with Scrypt and MAC to securely implement authenticated symmetric key encryption by text-based password.

Ethereum UTC / JSON Wallets#

In public blockchain networks (like Bitcoin and Ethereum) the private keys of the blockchain asset holders are stored in special keystores, called crypto wallets. Typically these crypto-wallets are files on the local hard disk, encrypted by a password.

In the Ethereum blockchain crypto wallets are internally stored in a special encrypted format known as “UTC / JSON Wallet (Keystore File) ↗” or “Web3 Secret Storage Definition ↗”. This is the wallet file format, used in geth ↗ and Parity ↗ (the leading protocol implementations for Ethereum), in MyEtherWallet ↗ (popular online client-side Ethereum wallet), in MetaMask ↗ (widely used in-browser Ethereum wallet), in the ethers.js ↗ and Nethereum ↗ libraries and in many other Ethereum-related technologies and tools.

The Ethereum UTC / JSON keystores keep the encrypted private key (or wallet seed words) as JSON text document, specifying the encrypted data, encryption algorithms and their parameters.

UTC / JSON Keystore - Example#

Let’s look into a sample UTC / JSON keystore file, which holds a password-protected 256-bit private key.

The above JSON document is a classical example of authenticated symmetric encryption.

What Is Inside the UTC / JSON File?#

Typically a UTC / JSON keystore holds the following data:

  • Key-derivation function (KDF) used to transform the text-based wallet encryption password into an AES symmetric key, used to encrypt the wallet contents. Usually the KDF function is “scrypt”.
  • The KDF parameters - the parameters used in the KDF function to derive the password (e.g. iterations count, salt, etc.)
  • The ciphertext - the encrypted wallet content (typically holds an encrypted 256-bit private key).
  • Symmetric cipher algorithm + its parameters, e.g. AES-128-CTR + initial vector (IV).
  • MAC - message authentication code used (MAC) to check the message integrity after it is decrypted (to know whether the wallet decryption password was correct or not).
  • Ethereum calculates the MAC by calculating keccak-256 hash of the concatenations of the second-leftmost 16 bytes of the derived key together with the full ciphertext.
  • Additional metadata: wallet format version, wallet unique id (uuid) and the blockchain address, controlled by this wallet.

By default the key-derivation function is scrypt and uses weak scrypt parameters (n=8192 cost factor, r=8 block size, p=1 parallelization), so it is recommended to use long and complex passwords to avoid brute-force wallet decryption attacks.

MyEtherWallet: Play with UTC / JSON Keystore Files#

To learn better the file format behind the Ethereum UTC / JSON keystore files, play with MyEtherWallet.

Follow the steps below to create a new random Ethereum crypto wallet and view its encrypted JSON content:

  • Open the MyEtherWallet web site: https://myetherwallet.com ↗.
  • Choose a password and create a new wallet.
  • Download the Keystore File (UTC / JSON).
  • See what’s inside the downloaded file.
  • Try to make some changes, try to decrypt it with wrong password and other changes.
  • Enjoy learning by playing.
Knowledge map

知识图谱

当前文档、同目录指南与引用关系。

准备中 全局图谱

正在构建知识图谱...

拖动节点 · 滚动缩放 · 点击打开

帮助与支持

这篇文档有帮助吗?

请给我们反馈以改进文档质量
(点击按钮后会打开邮箱)

帮助改进文档

所有文档均开源,发现问题或不清楚的地方?提交 PR 来帮助改进。

编辑此页面 了解如何贡献 →

需要更多帮助?

加入社区或直接联系获取支持

文件管理器 /
位置 /
内容
Knowledge explorer

知识图谱

全部知识 准备图谱...
文章 文档 标签 分类

正在加载知识网络...

拖动节点 · 滚动缩放 · 单击查看详情 · 双击打开页面
标签云 / Tag Cloud