Azure C++ Utils 1.5.2+3
Azure REST API Helpers for Modern C++
siddiqsoft::EncryptionUtils Struct Reference

Encryption utility functions for ServiceBus, Cosmos, EventGrid, EventHub Implementation Note! The support for wstring is for completeness and typically the use-case is where we fiddle with utf8 data and not utf16 over the internet and especially json documents! More...

#include <encryption-utils.hpp>

Static Public Member Functions

template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::string MD5 (const std::basic_string< T > &source)
 Create a MD5 hash for the given source as a string. More...
 
template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::string HMAC (const std::basic_string< T > &message, const std::string &key)
 Returns binary HMAC using SHA-256. https://www.liavaag.org/English/SHA-Generator/HMAC/. More...
 
template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::basic_string< T > JWTHMAC256 (const std::string &key, const std::basic_string< T > &header, const std::basic_string< T > &payload)
 Create a JsonWebToken authorization with HMAC 256. More...
 
template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::basic_string< T > SASToken (const std::string &key, const std::basic_string< T > &url, const std::basic_string< T > &keyName, const std::chrono::seconds &timeout)
 Create a Shared Access Signature for Azure storage https://docs.microsoft.com/en-us/rest/api/eventhub/generate-sas-token. More...
 
template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::basic_string< T > SASToken (const std::string &key, const std::basic_string< T > &url, const std::basic_string< T > &keyName, const std::basic_string< T > &expiry)
 Create a Shared Access Signature for Azure storage https://docs.microsoft.com/en-us/rest/api/eventhub/generate-sas-token. More...
 
template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::basic_string< T > CosmosToken (const std::string &key, const std::basic_string< T > &verb, const std::basic_string< T > &type, const std::basic_string< T > &resourceLink, const std::basic_string< T > &date)
 Create the Cosmos Authorization Token using the Key for this connection. More...
 

Detailed Description

Encryption utility functions for ServiceBus, Cosmos, EventGrid, EventHub Implementation Note! The support for wstring is for completeness and typically the use-case is where we fiddle with utf8 data and not utf16 over the internet and especially json documents!

Definition at line 72 of file encryption-utils.hpp.

Member Function Documentation

◆ CosmosToken()

template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::basic_string< T > siddiqsoft::EncryptionUtils::CosmosToken ( const std::string &  key,
const std::basic_string< T > &  verb,
const std::basic_string< T > &  type,
const std::basic_string< T > &  resourceLink,
const std::basic_string< T > &  date 
)
inlinestatic

Create the Cosmos Authorization Token using the Key for this connection.

Parameters
keyBinary. The key must be decoded from the base64 value in the connection string from the Azure portal
verbGET, POST, PUT, DELETE
typeOne of the following: dbs, docs, colls, attachments or empty
resourceLinkThe resource link sub-uri
dateDate in RFC7231 as string
Returns
Cosmos Authorization signature as std::string. It is base64 encoded and urlsafe

Definition at line 298 of file encryption-utils.hpp.

◆ HMAC()

template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::string siddiqsoft::EncryptionUtils::HMAC ( const std::basic_string< T > &  message,
const std::string &  key 
)
inlinestatic

Returns binary HMAC using SHA-256. https://www.liavaag.org/English/SHA-Generator/HMAC/.

Parameters
messageSource text
keySource key; MUST NOT be base64 encoded
Returns
Binary enclosed in string (narrow); you must base64encode to get useful result.

Definition at line 136 of file encryption-utils.hpp.

◆ JWTHMAC256()

template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::basic_string< T > siddiqsoft::EncryptionUtils::JWTHMAC256 ( const std::string &  key,
const std::basic_string< T > &  header,
const std::basic_string< T > &  payload 
)
inlinestatic

Create a JsonWebToken authorization with HMAC 256.

Parameters
keyMust be std::string as the contents are the "key" and treated as "binary"
headerThe JWT header
payloadThe string wiht json tokens
Returns
HMAC256 encoded JWT token

Definition at line 206 of file encryption-utils.hpp.

◆ MD5()

template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::string siddiqsoft::EncryptionUtils::MD5 ( const std::basic_string< T > &  source)
inlinestatic

Create a MD5 hash for the given source as a string.

Parameters
sourceMaybe std::string or std::wstring
Returns
MD5 of the source argument empty if there is a failure

Definition at line 79 of file encryption-utils.hpp.

◆ SASToken() [1/2]

template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::basic_string< T > siddiqsoft::EncryptionUtils::SASToken ( const std::string &  key,
const std::basic_string< T > &  url,
const std::basic_string< T > &  keyName,
const std::basic_string< T > &  expiry 
)
inlinestatic

Create a Shared Access Signature for Azure storage https://docs.microsoft.com/en-us/rest/api/eventhub/generate-sas-token.

Parameters
keyThe key to sign the url with time
urlThe url for the session
keyNameThe key name
expiryThe expiry is the number of seconds since 1970-1-1 plus timeout
Returns
SAS token

Definition at line 261 of file encryption-utils.hpp.

◆ SASToken() [2/2]

template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::basic_string< T > siddiqsoft::EncryptionUtils::SASToken ( const std::string &  key,
const std::basic_string< T > &  url,
const std::basic_string< T > &  keyName,
const std::chrono::seconds &  timeout 
)
inlinestatic

Create a Shared Access Signature for Azure storage https://docs.microsoft.com/en-us/rest/api/eventhub/generate-sas-token.

Parameters
keyThe key is "binary" in std::string
urlThe url for the session
keyNameThe key name
timeoutAmount of ticks past the "now" (number of seconds since 1970-1-1)
Returns
SAS token

Definition at line 234 of file encryption-utils.hpp.


The documentation for this struct was generated from the following file: