<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mohammed Imran</title>
    <description>The latest articles on Forem by Mohammed Imran (@m0hammedimran).</description>
    <link>https://forem.com/m0hammedimran</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F380395%2F91195bc1-3914-47ba-a219-b699cfaeef62.jpeg</url>
      <title>Forem: Mohammed Imran</title>
      <link>https://forem.com/m0hammedimran</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/m0hammedimran"/>
    <language>en</language>
    <item>
      <title>Easiest way to create secure and random strings for your JWT, session and cookie secrets.</title>
      <dc:creator>Mohammed Imran</dc:creator>
      <pubDate>Thu, 10 Mar 2022 12:04:29 +0000</pubDate>
      <link>https://forem.com/m0hammedimran/easiest-way-to-create-a-secure-and-random-strings-for-your-jwt-session-and-cookie-secrets-lnn</link>
      <guid>https://forem.com/m0hammedimran/easiest-way-to-create-a-secure-and-random-strings-for-your-jwt-session-and-cookie-secrets-lnn</guid>
      <description>&lt;p&gt;While in development or even in production, I just find it difficult to come up with secrets for my JWTs, cookies, sessions, etc...&lt;/p&gt;

&lt;p&gt;I first came across &lt;code&gt;openssl rand&lt;/code&gt; command in next-auth's docs.&lt;/p&gt;

&lt;p&gt;It is as simple as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;openssl rand &lt;span class="nt"&gt;-base64&lt;/span&gt; 40
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But, can we build on it to make our lives easier with &lt;code&gt;xclip&lt;/code&gt; to copy the output directly it into the clipboard.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;openssl rand &lt;span class="nt"&gt;-base64&lt;/span&gt; 40 | xclip &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="nt"&gt;-selection&lt;/span&gt; clipboard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explaining &lt;code&gt;openssl&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;openssl&lt;/code&gt; program is a command line tool for using the various cryptography functions of OpenSSL's crypto library from the shell.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rand&lt;/code&gt; : Generate pseudo-random bytes.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-base64&lt;/code&gt; : Converts the bytes into base64 encoded string.&lt;/li&gt;
&lt;li&gt;Length : In the example, I've used 40 which just means 40 random bytes will be generated and that will be encoded into base64.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Explaining &lt;code&gt;xclip&lt;/code&gt; -tags
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-r&lt;/code&gt; or &lt;code&gt;-rmlastnl&lt;/code&gt; : When the last character of the selection is a newline character, remove it. Newline characters that are not the last character in the selection are not affected. If the selection does not end with a newline character, this option has no effect. This option is useful for copying one-line output of programs like &lt;code&gt;pwd&lt;/code&gt; to the clipboard to paste it again into the command prompt without executing the line immediately due to the character &lt;code&gt;pwd&lt;/code&gt; appends.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-selection&lt;/code&gt; : Specify which X selection to use, options are "primary" to use &lt;code&gt;XA_PRIMARY&lt;/code&gt; (default), "secondary" for &lt;code&gt;XA_SECONDARY&lt;/code&gt; or "clipboard" for &lt;code&gt;XA_CLIPBOARD&lt;/code&gt;. I usually use clipboard, since I haven't found a good use case for the other options in my workflow.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>jwt</category>
      <category>node</category>
      <category>security</category>
    </item>
  </channel>
</rss>
