Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions nodejs/decrypt-dh.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
'use strict';

var crypto = require('crypto');
var ece = require('./ece.js');
import crypto from 'node:crypto';
import * as ece from './ece.js';

if (process.argv.length < 6) {
console.warn('Usage: ' + process.argv.slice(0, 2).join(' ') +
' <auth-secret> <receiver-private> <receiver-public> <message> [JSON args]');
process.exit(2);
}

var receiver = crypto.createECDH('prime256v1');
const receiver = crypto.createECDH('prime256v1');
// node crypto is finicky about accessing the public key
// 1. it can't generate the public key from the private key
// 2. it barfs when you try to access the public key, even after you set it
// This hack squelches the complaints at the cost of a few wasted cycles
receiver.generateKeys();
receiver.setPublicKey(Buffer.from(process.argv[4], 'base64url'));
receiver.setPrivateKey(Buffer.from(process.argv[3], 'base64url'));
var keymap = {};
const keymap = {};

var params = {
const params = {
version: 'aes128gcm',
authSecret: process.argv[2],
privateKey: receiver
};

if (process.argv.length > 7) {
var extra = JSON.parse(process.argv[7]);
const extra = JSON.parse(process.argv[7]);
Object.keys(extra).forEach(function(k) {
params[k] = extra[k];
});
}
keymap[params.keyid] = receiver;

console.log("Params: " + JSON.stringify(params, null, 2));
var result = ece.decrypt(Buffer.from(process.argv[5], 'base64url'), params);
const result = ece.decrypt(Buffer.from(process.argv[5], 'base64url'), params);

console.log(result.toString('base64url'));
console.log(result.toString('utf-8'));
12 changes: 5 additions & 7 deletions nodejs/decrypt.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
'use strict';

var crypto = require('crypto');
var ece = require('./ece.js');
import crypto from 'node:crypto';
import * as ece from './ece.js';

if (process.argv.length < 4) {
console.warn('Usage: ' + process.argv.slice(0, 2).join(' ') +
' <key> <message> [JSON args]');
process.exit(2);
}

var params = {
const params = {
version: 'aes128gcm',
key: process.argv[2]
};

if (process.argv.length > 4) {
var extra = JSON.parse(process.argv[4]);
const extra = JSON.parse(process.argv[4]);
Object.keys(extra).forEach(function(k) {
params[k] = extra[k];
});
}

console.log("Params: " + JSON.stringify(params, null, 2));
var result = ece.decrypt(Buffer.from(process.argv[3], 'base64url'), params);
const result = ece.decrypt(Buffer.from(process.argv[3], 'base64url'), params);

console.log(result.toString('base64url'));
console.log(result.toString('utf-8'));
Loading
Loading