title: How do encrypt a secret key using a password with tweetnacl-js?
body: <p><a href="https://github.com/dchest/tweetnacl-js" rel="nofollow">https://github.com/dchest/tweetnacl-js</a> comes highly recommended to me.</p>
  
  <p>I have a project where the team want to display their keypair encoded as base64 on an ID. Of course they don't want to just display the secret key, but instead store an encrypted version of it. Something like this...</p>
  
  <pre><code>// do the encryption
  let keyPair = tweetnacl.sign.keyPair();
  let publicKey = tweetnacl.util.encodeBase64(keyPair.publicKey);
  let signature = tweetnacl.util.encodeBase64(tweetnacl.sign.detached(tweetnacl.util.decodeUTF8(certData), keyPair.secretKey));
  let secretKey = tweetnacl.util.encodeBase64(keyPair.secretKey);
  let encryptedSecretKey = CryptoJS.AES.encrypt(secretKey, this.props.data.password).toString();
  </code></pre>
  
  <p>I've been advised against using CryptoJS. Is there a better way to do this using tweetnacl only?</p>
  
  <p>Thanks.</p>