planed-es / qxmlsec Goto Github PK
View Code? Open in Web Editor NEWXML digital signatures for Qt
License: BSD 3-Clause "New" or "Revised" License
XML digital signatures for Qt
License: BSD 3-Clause "New" or "Revised" License
Hi!
Thank you for this effort! I was trying the library, and after some modifications to the source code, particularly a few missing include clauses and a more intriguing error, that, may explain (perhaps) why I am not being able to sucessfully sign the .xml I was able to build the library.
I was "forced" to change the xmlsign.cpp
source file, specifically bool QXmlSign::sign()
because the compilation failed as xmlSecCryptoAppKeyLoad
method was not declared. I used xmlSecCryptoAppKeyLoadEx
instead, and to accomodate this change also added a new private member of type unsigned int to the Certificate
class to match the argument list of the xmlSecCryptoAppKeyLoadEx
symbol. After this change, I was able to build xmlsec-qt.
Now I was trying to sign a demo xml by including this library in a minimalist Qt project. I am using the following code
`QDomDocument targetDocument;
QFile file("/home/dev/mini_projects/xmlsign/data/demo.xml");
if (!file.open(QIODevice::ReadOnly))
return;
if (!targetDocument.setContent(&file)) {
file.close();
return;
}
file.close();
QXmlSecCertificate certificateData;
QXmlSign signer;
QXmlSec xmlsec;
QString keyInfoId;
certificateData.setFormat(QXmlSecCertificate::Pkcs12);
certificateData.setFilepath("/home/dev/mini_projects/xmlsign/data/u718ja1.p12");
certificateData.setPassword("blablabla");
certificateData.setType(0);
signer.withSignatureId("Signature-a53a6ab2")
.useNamespace("ds")
.useCertificate(certificateData)
.useDocument(targetDocument);
keyInfoId = signer.signatureContext().tagId("KeyInfo");
signer.useKeyInfo(QXmlSignKeyInfo()
.withId(keyInfoId)
.withKeyValue()
.withX509Data()
);
signer.useSignInfo(QXmlSignInfo()
.addReference(QXmlSignReference()
.withType(QUrl("http://www.w3.org/2000/09/xmldsig#Object"))
.useAlgorithm(QUrl("http://www.w3.org/2000/09/xmldsig#Object"))
.addTransform(QUrl("http://www.w3.org/2000/09/xmldsig#enveloped-signature"))
.addTransform(QUrl("http://www.w3.org/TR/1999/REC-xpath-19991116"))
)
.addReference(QXmlSignReference()
.withUri('#' + keyInfoId)
.useAlgorithm(QUrl("http://www.w3.org/2001/04/xmlenc#sha512"))
)
);
if (signer.sign())
{
std::cerr << "Successfully signed XML document" << std::endl;
std::cout << signer.toString().toStdString() << std::endl;
}
else
std::cerr << "Failed to sign XML document." << std::endl;`
Please note the line certificateData.setType(0)
with the call of the setter of the "type" member which I added to the Certificate class in order to be able to call the xmlSecCryptoAppKeyLoadEx
method.
When signign, the following error is shown:
Anybody can help me? I am in an effort to port some Python code used to sign xml files to C++ and found this library very useful!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.