summaryrefslogtreecommitdiff
path: root/encrypt_key.js
blob: 2a361773697811aadf04c1a1b2b2a3120063db8a (plain)
1
2
3
4
5
6
7
8
9
function encrypt_private_key(password, private_key) {
  let public_key = private_key.substring(64,128);
  let priv = sodium.from_hex(private_key.substring(0,64));
  if (password.length > 0) {
    for (i=0; i<priv.length; i++)
      priv[i] ^= password[i % password.length].charCodeAt(0);
  }
  return sodium.to_hex(priv) + public_key;
}