171 lines
6.8 KiB
HTML
171 lines
6.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self'; font-src 'self' data:; img-src 'self' data:; connect-src 'self'; base-uri 'self'; form-action 'self' https://defcon.social https://bsky.app;">
|
|
<meta http-equiv="X-Content-Type-Options" content="nosniff">
|
|
<link rel="stylesheet" href="../assets/css/style.css">
|
|
<link rel="icon" type="image/x-icon" href="../favicon.ico">
|
|
<script>
|
|
// Apply theme immediately to prevent flash
|
|
(function() {
|
|
const theme = localStorage.getItem('theme') ||
|
|
(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
})();
|
|
</script>
|
|
<title>openssl Cheatsheet - Launch Pad</title>
|
|
</head>
|
|
<body>
|
|
<button class="theme-toggle" id="themeToggle" aria-label="Toggle dark mode">
|
|
<svg class="theme-icon theme-icon-moon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path></svg>
|
|
<svg class="theme-icon theme-icon-sun" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: none;"><circle cx="12" cy="12" r="5"></circle><line x1="12" y1="1" x2="12" y2="3"></line><line x1="12" y1="21" x2="12" y2="23"></line><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line><line x1="1" y1="12" x2="3" y2="12"></line><line x1="21" y1="12" x2="23" y2="12"></line><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line></svg>
|
|
</button>
|
|
<br/><br/>
|
|
<div class="name">
|
|
__ _______________________ _________._________________________
|
|
\_ _____/ \______ \ / _ \ / _____/ / _____/ | | \_ _____/
|
|
| __) | _/ / /_\ \ / \ ___ / \ ___ | | | __)_
|
|
| \ | | \ / | \ \ \_\ \ \ \_\ \ | |___ | \
|
|
\___ / |____|_ / \____|__ / \______ / \______ / |_______ \ /_______ /
|
|
\/ \/ \/ \/ \/ \/ \/
|
|
</div>
|
|
<div class="blog-page-header">
|
|
<div class="blog-header-content">
|
|
<a href="/cheatsheets" class="back-link" title="Back to Cheatsheets">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="42" height="42" viewBox="0 0 24 24" class="home-icon"><path fill="currentColor" d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>
|
|
</a>
|
|
<h1 class="blog-page-title">openssl Cheatsheet</h1>
|
|
</div>
|
|
</div>
|
|
<div class="blog-post-container">
|
|
<div class="blog-posts-container" style="max-width: 900px; margin: 0 auto;">
|
|
<div class="blog-post">
|
|
<div class="blog-post-content">
|
|
<p><a href="index.html">← Back to cheatsheets</a></p>
|
|
<p><a href="../index.html">← Home</a></p>
|
|
<hr>
|
|
<p>OpenSSL is a cryptography toolkit providing implementations of SSL/TLS protocols and various cryptographic algorithms. Essential for certificate management, encryption, and secure communications.</p>
|
|
<hr>
|
|
<h2>Hashes</h2>
|
|
<ul>
|
|
<li>openssl dgst -sha256 file.txt - Calculate SHA-256 hash</li>
|
|
</ul>
|
|
<ul>
|
|
<li>openssl dgst -md5 file.txt - Calculate MD5 hash</li>
|
|
</ul>
|
|
<ul>
|
|
<li>openssl dgst -sha512 file.txt - Calculate SHA-512 hash</li>
|
|
</ul>
|
|
<ul>
|
|
<li>echo -n "text" | openssl dgst -sha256 - Hash from stdin</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Base64 Encoding</h2>
|
|
<ul>
|
|
<li>openssl base64 -in file.txt - Base64 encode</li>
|
|
</ul>
|
|
<ul>
|
|
<li>openssl base64 -d -in encoded.txt - Base64 decode</li>
|
|
</ul>
|
|
<ul>
|
|
<li>echo "text" | openssl base64 - Encode from stdin</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Certificate Management</h2>
|
|
<ul>
|
|
<li>openssl x509 -in cert.pem -text -noout - View certificate details</li>
|
|
</ul>
|
|
<ul>
|
|
<li>openssl x509 -in cert.pem -dates -noout - Show validity dates</li>
|
|
</ul>
|
|
<ul>
|
|
<li>openssl x509 -in cert.pem -fingerprint -noout - Show fingerprint</li>
|
|
</ul>
|
|
<ul>
|
|
<li>openssl req -new -x509 -key key.pem -out cert.pem -days 365 - Generate self-signed cert</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Key Generation</h2>
|
|
<ul>
|
|
<li>openssl genrsa -out key.pem 2048 - Generate RSA private key (2048 bits)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>openssl genrsa -out key.pem 4096 - Generate RSA private key (4096 bits)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>openssl ecparam -genkey -name secp256r1 -out key.pem - Generate EC private key</li>
|
|
</ul>
|
|
<ul>
|
|
<li>openssl rsa -in key.pem -pubout -out pubkey.pem - Extract public key</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Encryption/Decryption</h2>
|
|
<ul>
|
|
<li>openssl enc -aes-256-cbc -salt -in file.txt -out file.enc - Encrypt file</li>
|
|
</ul>
|
|
<ul>
|
|
<li>openssl enc -aes-256-cbc -d -in file.enc -out file.txt - Decrypt file</li>
|
|
</ul>
|
|
<ul>
|
|
<li>openssl enc -aes-256-gcm -in file.txt -out file.enc - Encrypt with GCM</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>SSL/TLS Testing</h2>
|
|
<ul>
|
|
<li>openssl s_client -connect host:443 - Connect to SSL server</li>
|
|
</ul>
|
|
<ul>
|
|
<li>openssl s_client -connect host:443 -showcerts - Show certificate chain</li>
|
|
</ul>
|
|
<ul>
|
|
<li>openssl s_client -connect host:443 -servername example.com - SNI support</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Common Examples</h2>
|
|
<h3>Calculate Hash</h3>
|
|
<pre><code>openssl dgst -sha256 file.iso</code></pre>
|
|
<p>Calculate SHA-256 hash of file.</p>
|
|
<h3>View Certificate</h3>
|
|
<pre><code>openssl x509 -in cert.pem -text -noout</code></pre>
|
|
<p>Display certificate information.</p>
|
|
<h3>Generate Self-Signed Certificate</h3>
|
|
<pre><code>openssl req -new -x509 -key key.pem -out cert.pem -days 365</code></pre>
|
|
<p>Create self-signed certificate valid for 1 year.</p>
|
|
<h3>Encrypt File</h3>
|
|
<pre><code>openssl enc -aes-256-cbc -salt -in secret.txt -out secret.enc</code></pre>
|
|
<p>Encrypt file with AES-256-CBC.</p>
|
|
<h3>Test SSL Connection</h3>
|
|
<pre><code>openssl s_client -connect example.com:443</code></pre>
|
|
<p>Test SSL/TLS connection to server.</p>
|
|
<hr>
|
|
<h2>Tips</h2>
|
|
<ul>
|
|
<li>Use modern algorithms (AES-256-GCM, SHA-256, ECDSA)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Always use -salt for encryption (default in newer versions)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>RSA 2048-bit minimum, prefer 4096 for long-term keys</li>
|
|
</ul>
|
|
<ul>
|
|
<li>EC keys are smaller and faster than RSA</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use s_client to debug SSL/TLS connections</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Check certificate expiration dates regularly</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script async type="text/javascript" src="../blog/analytics.js"></script>
|
|
<script src="../theme.js"></script>
|
|
</body>
|
|
</html>
|
|
|