snipt

Ctrl+h for KB shortcuts

Bash

check if ssl key and certificate match

keyPath=/path/to/key
certPath=/path/to/cert

keyHash=$(openssl rsa -noout -modulus -in "$keyPath" | openssl md5)
certHash=$(openssl x509 -noout -modulus -in "$certPath" | openssl md5)

if [ "$keyHash" = "$certHash" ]
then 
	echo ":)" 
fi
https://snipt.net/embed/cb30116ff894188f17e04d2d86800f4b/
/raw/cb30116ff894188f17e04d2d86800f4b/
cb30116ff894188f17e04d2d86800f4b
bash
Bash
11
2019-08-23T13:26:41
True
False
False
Oct 25, 2015 at 11:14 AM
/api/public/snipt/141929/
check-if-ssl-key-and-certificate-match
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a> <a href="#L-2"> 2</a> <a href="#L-3"> 3</a> <a href="#L-4"> 4</a> <a href="#L-5"> 5</a> <a href="#L-6"> 6</a> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nv">keyPath</span><span class="o">=</span>/path/to/key </span><span id="L-2"><a name="L-2"></a><span class="nv">certPath</span><span class="o">=</span>/path/to/cert </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="nv">keyHash</span><span class="o">=</span><span class="k">$(</span>openssl rsa -noout -modulus -in <span class="s2">&quot;</span><span class="nv">$keyPath</span><span class="s2">&quot;</span> <span class="p">|</span> openssl md5<span class="k">)</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">certHash</span><span class="o">=</span><span class="k">$(</span>openssl x509 -noout -modulus -in <span class="s2">&quot;</span><span class="nv">$certPath</span><span class="s2">&quot;</span> <span class="p">|</span> openssl md5<span class="k">)</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="k">if</span> <span class="o">[</span> <span class="s2">&quot;</span><span class="nv">$keyHash</span><span class="s2">&quot;</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="nv">$certHash</span><span class="s2">&quot;</span> <span class="o">]</span> </span><span id="L-8"><a name="L-8"></a><span class="k">then</span> </span><span id="L-9"><a name="L-9"></a> <span class="nb">echo</span> <span class="s2">&quot;:)&quot;</span> </span><span id="L-10"><a name="L-10"></a><span class="k">fi</span> </span></pre></div> </td></tr></table>
"certificate key", bash, openssl
--- 
+++ 
@@ -0,0 +1,10 @@
+keyPath=/path/to/key
+certPath=/path/to/cert
+
+keyHash=$(openssl rsa -noout -modulus -in "$keyPath" | openssl md5)
+certHash=$(openssl x509 -noout -modulus -in "$certPath" | openssl md5)
+
+if [ "$keyHash" = "$certHash" ]
+then 
+	echo ":)" 
+fi
  • omriko
  • 3 years, 10 months ago