Program Listing for File crypto.hpp
↰ Return to documentation for file (zeep/crypto.hpp
)
// Copyright Maarten L. Hekkelman, 2019-2020
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// --------------------------------------------------------------------
#pragma once
#include <zeep/config.hpp>
#include <exception>
#include <string>
namespace zeep
{
// --------------------------------------------------------------------
// encoding/decoding
class invalid_base64 : public std::exception
{
public:
invalid_base64() {}
const char* what() const noexcept { return "invalid base64 input"; }
};
std::string encode_base64(std::string_view data, size_t wrap_width = 0);
std::string decode_base64(std::string_view data);
// The base64url versions are slightly different
std::string encode_base64url(std::string_view data);
std::string decode_base64url(std::string data);
// And base32 might be handy as well, RFC 4648 (see https://en.wikipedia.org/wiki/Base32)
class invalid_base32 : public std::exception
{
public:
invalid_base32() {}
const char* what() const noexcept { return "invalid base32 input"; }
};
std::string encode_base32(std::string_view data, size_t wrap_width = 0);
std::string decode_base32(std::string_view data);
class invalid_hex : public std::exception
{
public:
invalid_hex() {}
const char* what() const noexcept { return "invalid hexadecimal input"; }
};
std::string encode_hex(std::string_view data);
std::string decode_hex(std::string_view data);
// --------------------------------------------------------------------
// random bytes
std::string random_hash();
// --------------------------------------------------------------------
// hashing
std::string md5(std::string_view data);
std::string sha1(std::string_view data);
std::string sha1(std::streambuf& data);
std::string sha256(std::string_view data);
// --------------------------------------------------------------------
// hmac
std::string hmac_md5(std::string_view message, std::string_view key);
std::string hmac_sha1(std::string_view message, std::string_view key);
std::string hmac_sha256(std::string_view message, std::string_view key);
// --------------------------------------------------------------------
// key derivation based on password (PBKDF2)
std::string pbkdf2_hmac_sha1(std::string_view salt,
std::string_view password, unsigned iterations, unsigned keyLength);
std::string pbkdf2_hmac_sha256(std::string_view salt,
std::string_view password, unsigned iterations, unsigned keyLength);
}