Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load error #67

Open
hply opened this issue Feb 28, 2021 · 3 comments
Open

load error #67

hply opened this issue Feb 28, 2021 · 3 comments

Comments

@hply
Copy link

hply commented Feb 28, 2021

raise BadKeystoreFormatException('Not a JKS or JCEKS keystore'
jks.util.BadKeystoreFormatException: Not a JKS or JCEKS keystore (magic number wrong; expected FEEDFEED or CECECECE);
when i use keytool,print this:

Keystore type: PKCS12
Keystore provider: SUN

Your keystore contains 1 entry

Alias name: abc
Creation date: 2021年2月28日
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: ......
Issuer: ......
Serial number: ......
Valid from: Sun Feb 28 18:14:51 CST 2021 until: Mon Feb 16 18:14:51 CST 2071
Certificate fingerprints:
SHA1: ......
SHA256: ......
Signature algorithm name: SHA256withRSA
Subject Public Key Algorithm: 2048-bit RSA key
Version: 3

Extensions:

#1: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [...]
how can i use pyjks lib for type PKCS12,thanks

@waghcwb
Copy link

waghcwb commented Jun 19, 2021

For BKS you can use jks.bks.BksKeyStore.load

@hply
Copy link
Author

hply commented Jun 21, 2021

For BKS you can use jks.bks.BksKeyStore.load

not 'BKS',is 'PKCS12'

@fenchu
Copy link

fenchu commented Aug 25, 2021

This is because pyjks do not support pkcs12 keystores. although they are now default: This is how I print them in *.pem format:

from OpenSSL import crypto

# this is a p12 cert
pw = "verysecretpassword"
keystore = 'java-keystore\\kafka.test-hso.keystore.jks'
p12 = crypto.load_pkcs12(open(keystore, 'rb').read(), pw.encode())

# PEM formatted private key key.pem
print(f"{crypto.dump_privatekey(crypto.FILETYPE_PEM, p12.get_privatekey()).decode()}")

# PEM formatted certificate cert.pem
print(f"{crypto.dump_certificate(crypto.FILETYPE_PEM, p12.get_certificate()).decode()}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants