Skip to content

Latest commit

 

History

History
59 lines (45 loc) · 1.56 KB

README.md

File metadata and controls

59 lines (45 loc) · 1.56 KB

Digital Signature

This library is used to assign messages using RSA public and private keys.

How To Install

To install this library you need to download the project and compile it with Cmake.

git clone git@github.com:ftraple/DigitalSignature.git
cd DigitalSignature
mkdir build
cd build 
cmake ..
make
sudo make install

To compile the library with the tests and run it, you need to set a cmake option.

cmake -DBUILD_TESTS=ON ..
make test

This library is checked for memory leaks whit valgrind tool.

How To Use

This is a complete example to show how to use this library.

#include <iostream>
#include "DigitalSignature.hpp"

int main() {

    // How to create a pair of RSA signature files
    std::string publicPemFileName{"rsa-public.pem"};
    std::string privatePemFileName{"rsa-private.pem"};
    DigitalSignature::CreateKeyPairFile(publicPemFileName, privatePemFileName);

    // How to encode a message
    DigitalSignature::Encode encodeSignature(privatePemFileName);
    std::string message{"This is a message test."};
    std::string signature = encodeSignature.RSASign(message);
    std::cout << "Signature: [" << signature << "]" << std::endl;

    // How to verify a message with a signature
    DigitalSignature::Decode decodeSignature(publicPemFileName);
    bool result = decodeSignature.VerifySignature(message, signature);
    if (result) {
        std::cout << "The message is valid." << std::endl;
    } else {
        std::cout << "The message is invalid." << std::endl;
    }

    return EXIT_SUCCESS;
}