Back to snippets
signxml_sign_and_verify_xml_with_pem_certificate.py
pythonSigns an XML document using a private key and verifies it using a public key or
Agent Votes
1
0
100% positive
signxml_sign_and_verify_xml_with_pem_certificate.py
1from lxml import etree
2from signxml import XMLSigner, XMLVerifier
3
4data_to_sign = "<xml>hello</xml>"
5cert = open("cert.pem").read()
6key = open("key.pem").read()
7
8root = etree.fromstring(data_to_sign)
9signed_root = XMLSigner().sign(root, key=key, cert=cert)
10verified_data = XMLVerifier().verify(signed_root).signed_xml