Coding · November 8, 2021

Create random secret key with Node

You can used a simple node command line to generate a random secret key to use as need.

How?

run node from your terminal. Then run the following command.

For Hex

require("crypto").randomBytes(64).toString("hex")

Sample output for Hex

218f5208d105f754025bb5cfa6b6aefdd40b0a6d52393f5dbf473aee9401403d45f9db8d7beaf051e592b2b6d5f673b9001727348d1799dd44e9eedd6f838008

For base64

require("crypto").randomBytes(64).toString("base64")

Sample output for base64

yfQemr5Cn9xU2phjb5ovKMY5r/k+UUziSDhgsAhPlcDTxlNiC6aZ4OadrcZ5oS1JLaiIWI6wJJO2yAg7W0RKGw==