This script uses AES-256-CBC (Advanced Encryption Standard, 256-bit key, CBC mode) as the core encryption algorithm to encrypt and decrypt private keys.
The encryption key (ENCRYPTION_KEY) is neither directly stored nor randomly generated, but derived from a user-provided password and a randomly generated salt using PBKDF2 (Password-Based Key Derivation Function 2).
Before using this project, install the required Node.js dependencies: Run the following command to install all dependencies:
npm installnode JM.js- Prepare the
privateKey.txtfile (one private key per line). - The program will prompt you to enter an encryption password.
- Encrypted private keys and the salt will be automatically saved to the
.envfile.
node PJ.js- The program reads the encrypted data from the
.envfile. - Enter your password to decrypt.
- Successfully decrypted private keys will be displayed for wallet initialization.
-
Read private keys from
privateKey.txt. -
Generate encryption key:
- Prompt user to enter a password.
- Use PBKDF2 (Password + Salt) to derive a 32-byte key.
-
Encrypt each private key:
- Output encoding: Hexadecimal.
- Format:
<encrypted_hex>:<iv_hex>
-
Store encrypted data:
SALT=<salt_hex>saved to.envENCRYPTED_KEY_<index>=<encrypted_hex>:<iv_hex>saved to.env
-
Read
SALTand encrypted private keys from.env. -
Enter password (minimum 8 characters).
-
Use PBKDF2 to derive encryption key (100,000 iterations, SHA-256).
-
Decrypt using AES-256-CBC:
- Extract
<encrypted_hex>and<iv_hex>. - Output the decrypted private key.
- Extract
- AES-256-CBC encryption
- PBKDF2 key derivation
- Encrypted keys and salt stored in
.envfile - Supports multi-key encryption and decryption
此脚本使用 AES-256-CBC(高级加密标准,256 位密钥,CBC 模式) 作为核心加密算法来加密和解密私钥。
加密密钥(ENCRYPTION_KEY)并非直接存储或随机生成,而是使用 PBKDF2(基于密码的密钥派生函数 2),由用户提供的密码和随机生成的盐值派生而来。
在使用前请先安装以下 Node.js 依赖:
通过 npm install 一键安装所有依赖:
npm installnode JM.js- 准备好
privateKey.txt文件(每行一个私钥)。 - 程序会提示输入加密密码。
- 加密后的私钥与盐值会自动保存至
.env文件中。
node PJ.js- 程序从
.env文件读取加密数据。 - 输入密码进行解密。
- 成功解密后输出原始私钥,供钱包初始化使用。
-
从
privateKey.txt读取私钥。 -
生成加密密钥:
- 提示输入密码。
- 使用 PBKDF2(密码 + 盐值)派生出 32 字节密钥。
-
加密每个私钥:
- 输出编码:十六进制。
- 格式:
<encrypted_hex>:<iv_hex>
-
存储加密数据:
SALT=<salt_hex>保存至.envENCRYPTED_KEY_<index>=<encrypted_hex>:<iv_hex>保存至.env
-
从
.env读取SALT和加密私钥。 -
输入密码(最少 8 位字符)。
-
使用 PBKDF2 进行密钥派生(100,000 次迭代,SHA-256)。
-
使用 AES-256-CBC 解密:
- 提取
<encrypted_hex>和<iv_hex>。 - 成功输出私钥。
- 提取
- AES-256-CBC 加密
- PBKDF2 密钥派生
- 加密密钥和盐值存储在
.env文件中 - 支持多密钥加解密