Encrypting data with a public key in Node.js

前端 未结 6 843
不思量自难忘°
不思量自难忘° 2020-11-29 16:13

I need to encrypt a string using a public key (.pem file), and then sign it using a private key (also a .pem).

I am loading the .pem files fine:

public         


        
6条回答
  •  無奈伤痛
    2020-11-29 17:15

    TL;DR: URSA is your best bet. It's really funky that this doesn't come standard with Node.js' crypto.

    Every other solutions I found either doesn't work in Windows or aren't actually encryption libraries. URSA, recommended by Louie, looks like the best bet. If you don't care about Windows, you're even more golden.

    Note on Ursa: I had to install OpenSSL along with something called "Visual C++ 2008 Redistributables" in order to get the npm install to work. Get that junk here: http://slproweb.com/products/Win32OpenSSL.html

    The breakdown:

    • Annoying additional manual installation steps for Windows
    • https://github.com/Obvious/ursa - probably the best of the lot
    • Not compatible with Windows
    • https://npmjs.org/package/rsautl - says BADPLATFORM
    • https://github.com/katyo/node-rsa - node-waf isn't available on Windows
    • https://github.com/paspao/simple_rsa_encrypt - unistd.h isn't on windows
    • https://npmjs.org/package/pripub - large amounts of linker errors, also not on GitHub

    Not encryption libraries

    • https://github.com/substack/secure-peer
    • https://github.com/substack/rsa-json - just generates keys, but doesn't use them
    • https://github.com/substack/rsa-unpack - just unpacks PEM strings

    This is literally all I could find.

提交回复
热议问题