{"id":575,"date":"2024-10-14T17:12:19","date_gmt":"2024-10-14T11:42:19","guid":{"rendered":"https:\/\/www.bhuvankrishna.in\/blog\/?p=575"},"modified":"2024-10-14T17:12:58","modified_gmt":"2024-10-14T11:42:58","slug":"generate-random-key","status":"publish","type":"post","link":"https:\/\/www.bhuvankrishna.in\/blog\/2024\/10\/14\/generate-random-key\/","title":{"rendered":"Generate random key"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A lot of applications these days need some sort of master key to enhance security. Few simple methods to generate such a key<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">uuidgen method<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>$ uuidgen<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Run this command to generate a random 32 characters long key. Most of the OS&#8217;s should have this command if not install it. More options and methods using this command can be found <a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/workflow-command-line-basics-generating-uuids\">here<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Python method<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">There are many many ways in python. I stumbled upon this method for which I don&#8217;t have to install anything and run just 2 commands to get the key. The <a href=\"https:\/\/docs.python.org\/3\/library\/secrets.html\">secrets<\/a> method is very simple.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python3 or python\n>>>import secrets\n>>>secrets.tokens_urlsafe(32)\nPArL_fEVainFbBSjrYjUhAgP3WpU76jGX2wz9TlV5VE<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Openssl rand<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Try this one-liner if openssl is available<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl rand -base64 32<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">These are some of the few methods to generate a random key.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A lot of applications these days need some sort of master key to enhance security. Few simple methods to generate such a key uuidgen method Run this command to generate a random 32 characters long key. Most of the OS&#8217;s should have this command if not install it. More options and methods using this command\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.bhuvankrishna.in\/blog\/2024\/10\/14\/generate-random-key\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-575","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts\/575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/comments?post=575"}],"version-history":[{"count":3,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts\/575\/revisions"}],"predecessor-version":[{"id":578,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts\/575\/revisions\/578"}],"wp:attachment":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/media?parent=575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/categories?post=575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/tags?post=575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}