How to activate ES6 in Visual Studio Code

I’ve been looking for this answer for several weeks. Here is how to do it. Go to File > Preferences > Settings (or press Ctrl + ,) Add the following code in the USER SETTINGS tab “jshint.options”: { “esversion”: 6 } I have JSHint installed, if you don’t, you can install it from Visual Studio Code directly. Sources https://stackoverflow.com/questions/29953293/is-there-a-way-to-turn-on-es6-es7-syntax-support-in-vscode

How to Sign data and Verify signature in Node.JS

Another example that occurred to me. Very useful. What will we need? Private key in PEM format Public key in PEM format To get those you will have use OpenSSL, please take a look at this post How to generate RSA public and private keys with OpenSSL. For this example I am using the following 2048 bit RSA key pair: …

How to generate RSA public and private keys with OpenSSL

Before anything, I assume that you already have OpenSSL installed in your PC. In case you don’t and you are a Windows you can download it from this URLs: http://slproweb.com/products/Win32OpenSSL.html http://gnuwin32.sourceforge.net/packages/openssl.htm I personally used the first one. After you are done with the installation follow this steps: Open a command line window and run the following command: openssl genrsa -out …

Elliptic Curve Diffie-Hellman and AES Example in Node.JS

Recently I learned how to generate shared secrets using ECDH in Node.JS, but I still had to know how to use this shared secret. Here is one application for it. Use the ECDH to generate a shared secret and then use that shared secret to cipher/decipher messages between both parties, in this case Joe and Zoe. Here is the code: …

How to generate Diffie Hellman key pair in Node.JS

Super easy using crypto library. You can create a file called¬†DiffieHellmanKeyPairGeneration.js for example and paste this code inside: console.log(‘\n- — ( Diffie Hellman Key Pair Generator ) — -‘); var crypto = require(‘crypto’); var bitSize = 2048; var dh = crypto.createDiffieHellman(bitSize); dh.generateKeys(); console.log(‘Private Key:\n’ + dh.getPrivateKey(‘base64’)); console.log(‘\n’); console.log(‘Public Key:\n’ + dh.getPublicKey(‘base64’)); console.log(‘— End —‘); Then run it, wait…wait…wait…wait…wait…wait…, and you …

How to list supported Ciphers, Hashes, and Curves for Crypto in Node.JS

Not a complicated task. Here is the code: var crypto = require(‘crypto’); console.log(); console.log(‘[ SUPPORTED CIPHERS ]\n’) console.log(crypto.getCiphers()); console.log(); console.log(‘[ SUPPORTED HASHES ]\n’) console.log(crypto.getHashes()); console.log(); console.log(‘[ SUPPORTED CURVES ]\n’) console.log(crypto.getCurves()); Your output should be similar to this: E:\Codes\NodeJS\Cryptography>node listAllAlgorithms.js [ SUPPORTED CIPHERS ] [ ‘CAST-cbc’, ‘aes-128-cbc’, ‘aes-128-cbc-hmac-sha1’, ‘aes-128-cbc-hmac-sha256’, ‘aes-128-ccm’, ‘aes-128-cfb’, ‘aes-128-cfb1’, ‘aes-128-cfb8’, ‘aes-128-ctr’, ‘aes-128-ecb’, ‘aes-128-gcm’, ‘aes-128-ofb’, ‘aes-128-xts’, ‘aes-192-cbc’, ‘aes-192-ccm’, ‘aes-192-cfb’, …

How to Encrypt / Decrypt with AES in Node.JS

Easy as pie! var crypto = require(‘crypto’); var AES128 = “aes128”; var AES192 = “aes192”; var AES256 = “aes256”; var password = ‘Austin’; var plainText = ‘Texas to the bone!’; // ———————————————— var cipher = crypto.createCipher(AES128, password); var decipher = crypto.createDecipher(AES128, password); console.log(‘AES-128:’); // Encrypting with AES128 var encText = cipher.update(plainText, ‘utf8’, ‘hex’); encText += cipher.final(‘hex’); console.log(encText); // Decrypting with …

How to Encode / Decode to / from base64 in Node.JS

Today I ran into this basic problem. A quick search on google gave me the answer, I tested it, it worked, and the rest is history. Here is the code. let plainText = “Hello World!”; console.log(“Plaint text = ” + plainText); // Encoding to base64 let base64 = new Buffer(plainText).toString(‘base64’); console.log(“Encoded to base64 = ” + base64); // Decoding from …

How to Encrypt / Decrypt with AES in Java 1.8

Here I have created a class that does it in two different ways, the first one is, when you create the key, and the other is when you are given the key, valid key sizes are 128, 192, and 256 for AES algorithm. There is some steps to follow before executing the code provied, if you don’t probably this class …

How to fold / unfold all regions in Visual Studio Code

With JSON files of around 900 lines, this option is very useful to have an organized view. I highly recommend to check the links, there is a lot of things you can do with Visual Studio Code, my version is 1.10.2, and the following shortcuts are working. Ctrl+K Ctrl+0 Fold (collapse) all regions Ctrl+K Ctrl+J Unfold (uncollapse) all regions Sources …