xmlsec / python-xmlsec

Python bindings for the XML Security Library.
MIT License
95 stars 99 forks source link

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

Open ramanareddy438 opened 1 month ago

ramanareddy438 commented 1 month ago

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 commented 1 month ago

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 commented 2 weeks ago

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