Skip to content

thefinalcutbg/XML-Cpp-Signer-PKCS11

Repository files navigation

XML Cpp Signer PKCS11

A simple C++17 script that creates enveloped XML signature using the PKCS11 interface. It supports XAdES BASELINE_B specification.

Dependencies

Setup

Use the provided MS Visual Studio solution or setup the project by yourself. Provide the necessary includes and libs.

Example

#include <iostream>
#include "signer.h"
#include "pkcs11.h"

int main()
{
      std::string xml = R"xml(<?xml version="1.0"?><example>some data to sign</example>)xml";
     
      PKCS11::setMiddlewareFilePath({ "C:/Program Files/OpenSC Project/OpenSC/pkcs11/opensc-pkcs11.dll" });
     
      PKCS11 hsm;
     
      if (!hsm.hsmLoaded()) {
          std::cout << "no hsm found";
          return 0;
      }
     
      if (hsm.loginRequired()) {
     
          std::string password;

          std::cout << "Enter password: ";
          std::cin >> password;
     
          if (!hsm.login(password)) {
              std::cout << std::endl << "Wrong password!" << std::endl;
              return 0;
          }
      }
     
      bool signWithXAdES = true;
      std::cout << std::endl << Signer::signEnveloped(xml, hsm.takePrivateKey(), hsm.x509raw(), signWithXAdES);
     
      return 0;
}

License

This software is licensed under the MIT license.

About

A simple C++ script for generating enveloped XAdES xml signatures using pkcs11

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages