Sunday, November 24, 2024
HomeBitcoinsafety - Is there any main flaw on this seed-phrase encryption method?

safety – Is there any main flaw on this seed-phrase encryption method?


I wish to add some safety to my seed phrase storage for current wallets. I am not making an attempt to make it completely safe, simply need to make it way more troublesome to entry my fund if somebody finds my seed phrase storage.

I am contemplating this method:

  1. convert the seed phrase to entropy
  2. encrypt entropy with a password
  3. convert the encrypted-entropy to a brand new seed phrase (which is longer)
  4. retailer the encrypted seed phrase

Then, I do the reverse to retrieve the preliminary seed phrase when wanted.

I’ve included JS code to show it beneath. I used AES CEB with out preliminary vector, and empty key salt in order that I do not want them for decryption.

I ponder if there’s any main flaw in my method or my code.

I perceive making my seed phrase storage safer with a password makes it extra doubtless that I lose entry to my seed phrase storage if I overlook the password.


import crypto from "crypto";
import bip39 from "bip39-light";

const algorithm = "aes-256-ecb";
const initialVector = null;
const keySize = 32;
const keySalt = "";

const inputPassword = ""; // password goes right here
const inputMnemonic = ""; // 12 phrase seed phrase goes right here

// encrypt 12-word enter mnemonic to 24-word mnemonic
const encryptedMnemonic = encryptMnemonic(inputMnemonic, inputPassword);

// decrypt 24-word mnemonic again to 12-word mnemonic
const decryptedMnemonic = decryptMnemonic(encryptedMnemonic, inputPassword);

console.log({ inputMnemonic, encryptedMnemonic, decryptedMnemonic });

perform encryptMnemonic(mnemonic, password) {
  const key = crypto.scryptSync(password, keySalt, keySize);

  const entropy = bip39.mnemonicToEntropy(mnemonic);
    
  const cipher = crypto.createCipheriv(algorithm, key, initialVector);
  
  let encryptedEntropy = cipher.replace(entropy, "hex", "hex");
  encryptedEntropy += cipher.closing("hex");
  
  let encryptedMnemonic = bip39.entropyToMnemonic(encryptedEntropy);
  return encryptedMnemonic;
}

perform decryptMnemonic(mnemonic, password) {
  const key = crypto.scryptSync(password, keySalt, keySize);

  let encryptedEntropy = bip39.mnemonicToEntropy(mnemonic);
  
  const decipher = crypto.createDecipheriv(algorithm, key, initialVector);
  
  let decryptedEntropy = decipher.replace(encryptedEntropy, "hex", "hex");
  decryptedEntropy += decipher.closing("hex");
    
  let decryptedMnemonic = bip39.entropyToMnemonic(decryptedEntropy);
  return decryptedMnemonic;
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments