Google node js端到端加密

Google End to end encryption for node js

我正在用 nodejs 做一些事情,我希望使用

来实现一些东西

https://github.com/google/end-to-end

但是当我得到编译版本时,它似乎不适用于 nodejs,但它确实适用于浏览器

是否有

的 nodeJs 实现

https://github.com/google/end-to-end

可用吗?

是的,有一种方法可以让你在nodejs中使用它。这有点 hack,但可以通过使用闭包方式加载它来实现。

首先构建它,以便生成 deps.js

cd end-to-end;
./do.sh build_library

然后你可以覆盖导入函数来完成加载库的工作。

require('./lib/closure-library/closure/goog/bootstrap/nodejs.js')

global.CLOSURE_IMPORT_SCRIPT = function(src) {
  var E2E_PATH = './';
  var CLOSURE_SOURCE = './lib/closure-library/closure/goog/';
  try {
    require(CLOSURE_SOURCE + src);
  } catch (err) {
    require(E2E_PATH + src);
  }
  return true;
}

require('./build/deps.js');
goog.require('e2e.openpgp.asciiArmor');

console.log(e2e.openpgp.asciiArmor.encode('MESSAGE', e2e.stringToByteArray('test')));

更新:我添加了一个包来执行此操作:https://www.npmjs.com/package/e2enode