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

Cracking short RSA keys

Your teacher gave you: Public Key: (10142789312725007, 5) which means n = 10142789312725007 e = 5 where n is the modulus and e is the public exponent. In addition, you’re given Private Key: (10142789312725007, 8114231289041741) meaning that d = 8114231289041741 where d is the decryption exponent that should remain secret. You can “break” RSA by … Read more

Setting up OpenSSH for Windows using public key authentication

Following are setup steps for OpenSSH shipped with Windows 10 v.1803 (April 2018 update. See comments to this post, it might not work with 1809). Server setup (elevated powershell): Install OpenSSH server: Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0. Start agent and sshd services: Start-Service ssh-agent; Start-Service sshd (this will generate host keys and default configuration automatically in … Read more

Unable to load config info from /usr/local/ssl/openssl.cnf on Windows

After installing OpenSSL I was required to create a new environment variable: Name: OPENSSL_CONF Value: C:\Program Files\OpenSSL\openssl.cnf In powershell: $env:OPENSSL_CONF = “${env:ProgramFiles}\OpenSSL\openssl.cnf” This value differs from previous installation versions (as seen in a previous edit of this post). Also, don’t forget to add the openssl binary folder ${env:ProgramFiles}\OpenSSL to your Path.