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 #320

Open
ramanareddy438 opened this issue Oct 10, 2024 · 1 comment
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-----

@pitbulk
Copy link
Contributor

pitbulk commented Oct 14, 2024

If you execute in the command line:

openssl rsa -in private_key.pem -check

What you get? Maybe the private key is wrong

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

2 participants