single-file set of cryptographic and security utils using OpenSSL underneath. Common crypto tasks like encrypting, signing, verifying, X.509 manipulations made easy.
Check examples folder for sample applications.
if(const auto hash = hash::fileSHA256(filePath))
{
LOG_DBG << “File “ << filePath << “ hash: “ << binToHexStr(hash.value);
}
else
{
LOG_ERR << hash.msg();
}
* Generate RSA key and convert it to PEM format
```cpp
using namespace so;
auto key = rsa::create(rsa::KeyBits::_3072_)
if(!key)
{
LOG_ERR << key.msg();
return;
}
const auto pemKey = rsa::convertPrivKeyToPem(*key.value);
if(!pemKey)
{
LOG_ERR << pemKey.msg();
return;
}
const auto pemPubKey = rsa::convertPubKeyToPem(*key.value);
if(!pemPubKey)
{
LOG_ERR << pemPubKey.msg();
return;
}
LOG_INF << "New priv key pem: " << pemKey.value;
LOG_INF << "New pub key pem: " << pemPubKey.value;
so::X509_uptr cert = so::make_unique(SSL_get_peer_certificate(ssl));
if(!cert)
{
LOG_ERR << “Get peer cert error: “ << so::getLastErrString();
return;
}
const auto validity = x509::getValidity(*cert);
if(!validity)
{
LOG_ERR << “Getting validity failed: “ << validity.msg();
return;
}
LOG_INF << “Cert not before: “ << timetPrettyString(validity->notBefore);
LOG_INF << “Cert not after: “ << timetPrettyString(validity->notAfter);
// ………………………….
std::string timetPrettyString(std::time_t time)
{
std::tm *ptm = std::gmtime(&time);
char buffer[32];
std::strftime(buffer, 32, “%a, %d.%m.%Y %H:%M:%S”, ptm);
return buffer;
}
# Usage
1. Copy [simpleopenssl.hpp](https://raw.githubusercontent.com/severalgh/simpleopenssl/master/include/simpleopenssl/simpleopenssl.hpp) to your build tree.
2. Add ```#define SO_IMPLEMENTATION``` in exacly one place just before the include to specify where implementation should be placed for the linker:
#define SO_IMPLEMENTATION
#include "simpleopenssl.hpp"
```
#include "simpleopenssl.hpp"
in every other place.