Search code examples
javascriptnode.jsend-to-end

Google End to end encryption for node js


I am working on something in nodejs, I am looking to implement something using

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

But when i get compiled version,It doesn't seems to work on nodejs,But It does work on browsers

Is there is any nodeJs implementation of

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

available ?


Solution

  • Yes, there is a way for you to use it in nodejs. It's a bit of a hack, but doable by loading it using closure way.

    First build it so it generates a deps.js

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

    Then you can override the import function to do the job of loading the 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')));
    

    Update: I add a package to do this: https://www.npmjs.com/package/e2enode