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

xmlsec.Error: (1, 'cannot load key') while loading the private key #328

Open
ramanareddy438 opened this issue Oct 10, 2024 · 2 comments
Open

Comments

@ramanareddy438
Copy link

Hi Team,

I have a X509 private in a file and trying to use the below code to load the private key. However i am getting the xmlsec.Error: (1, 'cannot load key'). I tried multiple ways. nothing is working and more over the error message is not detailed enough to try other options.

Any suggestions are greatly appreciated. Thank you.

with open('private_key.pem', 'rb') as key_file:
    key_data = key_file.read()
xmlsec.Key.from_memory(key_data, xmlsec.constants.KeyDataFormatPem)

My PEM file format is as shown below:

-----BEGIN PRIVATE KEY-----
TUlkjshduahdajsduaydjaudhswmb7ajwesdajhassdadasdsdaeddasdaeqdea
TUlkjshduahdajsduaydjaudhswmb7ajwesdajhassdadasdsdaeddasdaeqdea
TUlkjshduahdajsduaydjaudhswmb7ajwesdajhassdadasdsdaeddasdaeqdea
TUlkjshduahdajsduaydjaudhswmb7ajwesdajhassdadasdsdaeddasdaeqdea
TUlkjshduahdajsduaydjaudhswmb7ajwesdajhassdadasdsdaeddasdaeqdea
TUlkjshduahdajsduaydjaudhswmb7ajwesdajhassdadasdsdaeddasdaeqdea
TUlkjshduahdajsduaydjaudhswmb7ajwesdajhassdadasdsdaeddasdaeqdea
TUlkjshduahdajsduaydjaudhswmb7ajwesdajhassdadasdsdaeddasdaeqdea
TUlkjshduahdajsduaydjaudhswmb7ajwesdajhassdadasdsdaeddasdaeqdea
TUlkjshduahdajsduaydjaudhswmb7ajwesdajhassdadasdsdaeddasdaeqdea
TUlkjshduahdajsduaydjaudhswmb7ajwesdajhassdadasdsdaeddasdaeqdea
TUlkjshduahdajsduaydjaudhswmb7ajwesdajhassdadasdsdaeddasdaeqdea
TUlkjshduahdajsduaydjaudhswmb7ajwesdajhassdadasdsdaeddasdaeqdea
TUlkjshduahdajsduaydjaudhswmb7ajwesdajhassdadasdsdaeddasdaeqdea
asdadasd==
-----END PRIVATE KEY-----

@tpanum
Copy link

tpanum commented Oct 14, 2024

I am experiencing a similar issue. I have a .p12-certificate that I have transformed to x509 using OpenSSL.

$ openssl x509 -in cert.pem -text -noout runs without issues. However, I can't load the file with xmlsec.

@jimjag
Copy link
Collaborator

jimjag commented Nov 5, 2024

Are we sure that this is an issue w/ us and not the underlying lib itself?

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