SSL certificates और private keys कई file formats में store की जा सकती हैं। Content same होता है — encoding और packaging अलग होती है। ज़्यादातर confusion आपके server के लिए एक specific format की requirement से आता है।
Format comparison
| Format | Extensions | Encoding | Contains | Used by |
|---|---|---|---|---|
| PEM | .pem, .crt, .cer, .key | Base64 (text) | Cert, key, या chain (एक per file) | Nginx, Apache, ज़्यादातर Linux servers |
| DER | .der, .cer | Binary | Single cert या key | Java, कुछ Windows apps |
| PFX/PKCS#12 | .pfx, .p12 | Binary | Cert + key + chain एक file में | Windows IIS, Azure, macOS Keychain |
PEM — सबसे common format
PEM (Privacy Enhanced Mail) base64-encoded text है। आप इसे text editor में open कर सकते हैं:
-----BEGIN CERTIFICATE-----
MIIFYjCCBEqgAwIBAgISA8ht...
(base64 encoded data)
-----END CERTIFICATE-----
PEM files में certificates, private keys, या certificate chains हो सकते हैं। Header बताता है कि अंदर क्या है:
BEGIN CERTIFICATE— एक certificateBEGIN PRIVATE KEY— एक private key (याBEGIN RSA PRIVATE KEY/BEGIN EC PRIVATE KEY)BEGIN CERTIFICATE REQUEST— एक CSR
GetHTTPS PEM format में output देता है — privkey.pem, cert.pem, chain.pem, fullchain.pem।
DER — binary encoding
DER same data का binary form है जिसे PEM text के रूप में encode करता है। यह human-readable नहीं है। Mainly Java applications (keytool) और कुछ Windows components द्वारा use किया जाता है।
PFX/PKCS#12 — bundle format
PFX (Personal Information Exchange) certificate, private key, और chain को एक password-protected file में bundle करता है। Windows IIS, Azure App Service, और macOS Keychain को इस format की ज़रूरत होती है।
Formats के बीच conversion
सभी conversions OpenSSL use करते हैं:
PEM → PFX
openssl pkcs12 -export \
-out certificate.pfx \
-inkey privkey.pem \
-in cert.pem \
-certfile chain.pem
आपसे एक export password set करने के लिए कहा जाएगा।
PFX → PEM
# Extract certificate
openssl pkcs12 -in certificate.pfx -clcerts -nokeys -out cert.pem
# Extract private key
openssl pkcs12 -in certificate.pfx -nocerts -nodes -out privkey.pem
# Extract chain
openssl pkcs12 -in certificate.pfx -cacerts -nokeys -out chain.pem
PEM → DER
openssl x509 -in cert.pem -outform DER -out cert.der
DER → PEM
openssl x509 -in cert.der -inform DER -outform PEM -out cert.pem
मुझे कौन सा format चाहिए?
| Server/Platform | Format | Required files |
|---|---|---|
| Nginx | PEM | fullchain.pem + privkey.pem |
| Apache | PEM | cert.pem + chain.pem + privkey.pem |
| IIS (Windows) | PFX | certificate.pfx (PEM से convert करें) |
| Azure App Service | PFX | certificate.pfx |
| AWS (ACM) | PEM | cert.pem + chain.pem + privkey.pem (console में paste करें) |
| Java (Tomcat) | JKS या PFX | PEM → PFX → JKS keytool से convert करें |
| Node.js | PEM | Code में directly files read करें |
File का format कैसे identify करें
Sure नहीं कि file किस format में है? Check करें:
# If it starts with "-----BEGIN" — it's PEM (base64 text)
head -1 mystery-file.pem
# If it's binary (garbled text) — it's DER or PFX
file mystery-file.cer
# Output like "data" or "certificate" = DER
# Output like "PKCS12" = PFX
# Inspect a PEM certificate
openssl x509 -in cert.pem -noout -text
# Inspect a DER certificate
openssl x509 -in cert.der -inform DER -noout -text
# Inspect a PFX file
openssl pkcs12 -in cert.pfx -info -nokeys
Common file extension confusion
| Extension | Usually means | But could be |
|---|---|---|
.pem | PEM (base64) | Always PEM |
.crt | PEM certificate | Windows पर DER |
.cer | PEM certificate | Windows पर DER |
.key | PEM private key | DER (rare) |
.pfx | PKCS#12 bundle | Always PFX |
.p12 | PKCS#12 bundle | Always PFX (.pfx के same) |
.der | DER (binary) | Always DER |
.jks | Java KeyStore | Always JKS |
Thumb rule: File को text editor में open करें। अगर आप -----BEGIN CERTIFICATE----- देखते हैं, तो extension चाहे जो हो, यह PEM है। अगर आप binary garbage देखते हैं, तो यह DER या PFX है।
FAQ
.crt, .cer, और .pem में क्या difference है?
ये सभी PEM format हो सकते हैं। Extension एक naming convention है, format indicator नहीं। .crt और .cer आमतौर पर certificate files के लिए use होते हैं, .pem किसी भी PEM-encoded file के लिए। Windows पर, .cer files कभी-कभी DER-encoded होती हैं — check करने के लिए text editor में open करें।
GetHTTPS मुझे 4 files क्यों देता है?
Maximum compatibility। GetHTTPS provide करता है: privkey.pem (private key), cert.pem (सिर्फ आपका certificate), chain.pem (intermediate CA certificate), fullchain.pem (cert + chain combined)। Nginx को fullchain.pem चाहिए; Apache को अलग cert.pem + chain.pem चाहिए; IIS को PFX चाहिए (PEM से convert करें)।
Windows/IIS के लिए PFX कैसे बनाएँ?
ऊपर दिए गए OpenSSL PEM → PFX command use करें। आपको GetHTTPS से privkey.pem, cert.pem, और chain.pem चाहिए। Resulting .pfx को IIS, Azure App Service, या macOS Keychain में import किया जा सकता है।
क्या मैं private key के बिना एक format से दूसरे में convert कर सकता हूँ?
आप certificate को private key के बिना PEM और DER के बीच convert कर सकते हैं। लेकिन PFX बनाने के लिए private key ज़रूरी है (यह cert + key को एक साथ bundle करता है)। अगर आपने अपनी private key खो दी है, तो आपको एक नया certificate generate करना होगा।
Let’s Encrypt कौन सा format use करता है?
Let’s Encrypt (GetHTTPS सहित किसी भी ACME client के through) PEM format में output देता है। अगर आपको अपने server के लिए different format चाहिए, तो ऊपर दिए गए OpenSSL commands use करके convert करें।