Encrypting data with a public key in Node.js

A library is not necessary. Enter crypto. Here’s a janky little module you could use to encrypt/decrypt strings with RSA keys: var crypto = require(“crypto”); var path = require(“path”); var fs = require(“fs”); var encryptStringWithRsaPublicKey = function(toEncrypt, relativeOrAbsolutePathToPublicKey) { var absolutePath = path.resolve(relativeOrAbsolutePathToPublicKey); var publicKey = fs.readFileSync(absolutePath, “utf8”); var buffer = Buffer.from(toEncrypt); var encrypted = … Read more

encryption/decryption with multiple keys

GnuPG does multi-key encryption in standard. The following command will encrypt doc.txt using the public key for Alice and the public key for Bob. Alice can decrypt using her private key. Bob can also decrypt using his private key. gpg –encrypt –recipient [email protected] \ –recipient [email protected] doc.txt This feature is detailed in the user guide … Read more

How to load the RSA public key from file in C#

You can create an RSACryptoServiceProvider from a PEM file using the following class (GetRSAProviderFromPemFile method). Warning: Don’t just copy code from StackOverflow without verification! Especially not crypto code! This code has bugs (see comments). You may want to write and run tests before using this in production (if you really have no better option). I … Read more