SHA hash in NodeJS

const crypto = require(“crypto”);const filename = process.argv[2];const fs = require(“fs”); const hash = crypto.createHash(“sha256”); const input = fs.createReadStream(filename);input.on(“readable”, () => { const data =; if (data) { hash.update(data); } else { console.log(`${hash.digest(“hex”)} ${filename}`); }}); Reference

Basic RSA in .NET

Here’s a very basic example of RSA encryption in .NET: string priv, pub;string plain = “hello world” ;byte[] plainBytes = Encoding.UTF8.GetBytes(plain);byte[] encBytes;using (var rsa = new RSACryptoServiceProvider(2048)) { priv = rsa.ToXmlString(true); Console.WriteLine(priv); Console.WriteLine(); pub = rsa.ToXmlString(false); Console.WriteLine(pub); encBytes = rsa.Encrypt(plainBytes, true);} using (var rsa = new RSACryptoServiceProvider(2048)) { rsa.FromXmlString(priv); byte[] decBytes = rsa.Decrypt(encBytes, true); Console.WriteLine(Encoding.UTF8.GetString(decBytes));} […]

Calculate Hash in .NET

With .NET, you can calculate a file hash, or the hash of any stream, using the HashAlgorithm.ComputeHash method. Here’s a sample application showing how to choose one of four algorithms and formats. To see how the SendTo functionality works, check out the previous video. View code on GitHub


Cryptography, and especially public key cryptography, is a complicated and difficult topic. I recommend digging into the docs and blogs from trusted security experts. To get you started, here’s an example showing creating keys, encrypting, decrypting, and signing a message. Protecting your private keys is probably the most important piece of the process, so make […]