Last active
July 10, 2025 09:44
-
-
Save stanleyxu2005/df0f368d1f3a69971a92d8715cc96833 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jks | |
from cryptography.hazmat.primitives import serialization | |
# 加载 JKS 文件 | |
keystore = jks.KeyStore.load('keystore.jks', 'password') | |
# 导出证书为 PEM | |
for alias, cert in keystore.certs.items(): | |
pem_cert = cert.cert.public_bytes( | |
encoding=serialization.Encoding.PEM, | |
format=serialization.PublicFormat.SubjectPublicKeyInfo | |
) | |
with open(f"{alias}_cert.pem", "wb") as f: | |
f.write(pem_cert) | |
# 导出私钥为 PEM | |
for alias, private_key in keystore.private_keys.items(): | |
pem_key = private_key.pkey.privateBytes( | |
encoding=serialization.Encoding.PEM, | |
format=serialization.PrivateFormat.TraditionalOpenSSL, | |
encryption_algorithm=serialization.NoEncryption() | |
) | |
with open(f"{alias}_key.pem", "wb") as f: | |
f.write(pem_key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment