How to use the box function from tweetnacl
Find comprehensive JavaScript tweetnacl.box code examples handpicked from public code repositorys.
315 316 317 318 319 320 321 322 323 324 325 326
function getKeyPair() { // return new Promise((resolve) => setTimeout(resolve, ms)); const [privateSpendKey, privateViewKey] = js_wallet.getPrimaryAddressPrivateKeys() let secretKey = hexToUint(privateSpendKey) let keyPair = nacl.box.keyPair.fromSecretKey(secretKey) return keyPair } function getMsgKey() {
11
19
5
57 58 59 60 61 62 63 64 65 66
* @param {String} obj.privateKey - private key of the receiver (current user) * @param {String} plaintext - UTF8 plaintext */ var decryptAsymmetric = function (_a) { var ciphertext = _a.ciphertext, nonce = _a.nonce, publicKey = _a.publicKey, privateKey = _a.privateKey; return nacl.box.open(util.decodeBase64(ciphertext), util.decodeBase64(nonce), util.decodeBase64(publicKey), util.decodeBase64(privateKey)); }; exports.decryptAsymmetric = decryptAsymmetric; /** * Return symmetrically encrypted [plaintext] using [key].
2
7
2
+ 17 other calls in file
GitHub: rashmiranjanbhoi/RepoC
176 177 178 179 180 181 182 183 184 185
pub = pub.slice(1); var priv = this._priv; assert.strictEqual(pub.length, 32); assert.strictEqual(priv.length, 32); var secret = nacl.box.before(new Uint8Array(pub), new Uint8Array(priv)); return (Buffer.from(secret)); }
0
0
1
308 309 310 311 312 313 314 315 316 317 318 319 320
} function calculateX25519Public(k) { assert.buffer(k); var kp = nacl.box.keyPair.fromSeed(new Uint8Array(k)); return (Buffer.from(kp.publicKey)); } function addRSAMissing(key) {
0
0
0
+ 7 other calls in file
90 91 92 93 94 95 96 97 98 99
if (this.type === 'ed25519' && newType === 'curve25519') { priv = this.part.k.data; if (priv[0] === 0x00) priv = priv.slice(1); pair = nacl.box.keyPair.fromSecretKey(new Uint8Array(priv)); pub = Buffer.from(pair.publicKey); return (new PrivateKey({ type: 'curve25519',
0
0
0
+ 7 other calls in file
26 27 28 29 30 31 32 33 34 35
var privKey = keystore.exportPrivateKey(myPubKey, pwDerivedKey, hdPathString); var privKeyUInt8Array = nacl_decodeHex(privKey); var pubKeyUInt8Array = nacl_decodeHex(theirPubKey); var nonce = nacl.randomBytes(nacl.box.nonceLength); var encryptedMessage = nacl.box(msgUint8Array, nonce, pubKeyUInt8Array, privKeyUInt8Array); var output = { alg: 'curve25519-xsalsa20-poly1305', nonce: nacl.util.encodeBase64(nonce),
0
0
2
+ 5 other calls in file
164 165 166 167 168 169 170 171 172 173
throw new Error('KeyStore._computePubkeyFromPrivKey: Only "curve25519" supported.') } var privKeyBase64 = (new Buffer(privKey, 'hex')).toString('base64') var privKeyUInt8Array = nacl.util.decodeBase64(privKeyBase64); var pubKey = nacl.box.keyPair.fromSecretKey(privKeyUInt8Array).publicKey; var pubKeyBase64 = nacl.util.encodeBase64(pubKey); var pubKeyHex = (new Buffer(pubKeyBase64, 'base64')).toString('hex'); return pubKeyHex;
0
0
0
44 45 46 47 48 49 50 51 52 53
throw new Error("Missing privateKey parameter"); } // assemble decryption parameters const encryptedMessage = naclUtil.decodeBase64(encryptedData); const nonce = encryptedMessage.subarray(0, nacl.box.nonceLength); const publicKey = encryptedMessage.subarray(nacl.box.nonceLength, nacl.box.nonceLength + nacl.box.publicKeyLength); const ciphertext = encryptedMessage.subarray(nacl.box.nonceLength + nacl.box.publicKeyLength); // decrypt
0
0
0
+ 7 other calls in file
tweetnacl.box is the most popular function in tweetnacl (320 examples)