DiceKeys Seeded Cryptography Library
UnsealingKey Class Reference

an UnsealingKey is used to unseal messages sealed with its corresponding SealingKey. The UnsealingKey and SealingKey are generated from a seed and a set of options in JSON Format for Recipes. More...

#include <unsealing-key.hpp>

Public Member Functions

 UnsealingKey (const SodiumBuffer unsealingKeyBytes, const std::vector< unsigned char > sealingKeyBytes, const std::string recipe)
 Construct a new UnsealingKey by passing its members.
 
 UnsealingKey (const SodiumBuffer &seedBuffer, const std::string &recipe)
 Construct a new UnsealingKey by deriving a public/private key pair from a seedBuffer and a set of recipe in JSON Format for Recipes. More...
 
 UnsealingKey (const std::string &seedString, const std::string &recipe)
 Construct a new UnsealingKey by deriving a public/private key pair from a seed string and a set of recipe in JSON Format for Recipes. More...
 
 UnsealingKey (const UnsealingKey &other)
 Construct by copying another UnsealingKey.
 
const SealingKey getSealingKey () const
 Get the SealingKey used to seal messages that can be unsealed with this UnsealingKey.
 
const SodiumBuffer unseal (const unsigned char *ciphertext, const size_t ciphertextLength, const std::string &unsealingInstructions) const
 Unseal a message. More...
 
const SodiumBuffer unseal (const std::vector< unsigned char > &ciphertext, const std::string &unsealingInstructions={}) const
 Unseal a message. More...
 
const SodiumBuffer unseal (const PackagedSealedMessage &packagedSealedMessage) const
 Unseal a message from packaged format, ignoring the recipe since this UnsealingKey has been instantiated. (If it's the wrong key, the unseal will fail.) More...
 
const std::string toJson (int indent=-1, const char indent_char=' ') const
 Serialize this object to a JSON-formatted string. More...
 
const SodiumBuffer toSerializedBinaryForm () const
 Serialize to byte array as a list of: (unsealingKeyBytes, sealingKeyBytes, recipe) More...
 

Static Public Member Functions

static UnsealingKey deriveFromSeed (const std::string &seedString, const std::string &recipe)
 Construct a new UnsealingKey by deriving a public/private key pair from a seed string and a set of recipe in JSON Format for Recipes. More...
 
static UnsealingKey fromJson (const std::string &unsealingKeyAsJson)
 Construct (reconstitute) from serialized JSON format. More...
 
static const SodiumBuffer unseal (const PackagedSealedMessage &packagedSealedMessage, const std::string &seedString)
 Unseal a message by re-deriving the UnsealingKey from its seed. More...
 
static UnsealingKey fromSerializedBinaryForm (const SodiumBuffer &serializedBinaryForm)
 Deserialize from a byte array stored as a list of: (unsealingKeyBytes, sealingKeyBytes, recipe) More...
 

Public Attributes

const SodiumBuffer unsealingKeyBytes
 The libSodium private key used for unsealing.
 
const std::vector< unsigned char > sealingKeyBytes
 The libsodium public key used for sealing.
 
const std::string recipe
 A JSON Format for Recipes string used to specify how this key is derived.
 

Detailed Description

an UnsealingKey is used to unseal messages sealed with its corresponding SealingKey. The UnsealingKey and SealingKey are generated from a seed and a set of options in JSON Format for Recipes.

The UnsealingKey includes a copy of the SealingKey, which can be reconstituted as a SealingKey object via the getSealingKey method.

Constructor & Destructor Documentation

◆ UnsealingKey() [1/2]

UnsealingKey::UnsealingKey ( const SodiumBuffer seedBuffer,
const std::string &  recipe 
)

Construct a new UnsealingKey by deriving a public/private key pair from a seedBuffer and a set of recipe in JSON Format for Recipes.

Parameters
seedBufferThe seed as sequence of bytes
recipeThe recipe in JSON Format for Recipes.

◆ UnsealingKey() [2/2]

UnsealingKey::UnsealingKey ( const std::string &  seedString,
const std::string &  recipe 
)

Construct a new UnsealingKey by deriving a public/private key pair from a seed string and a set of recipe in JSON Format for Recipes.

Parameters
seedStringThe private seed which is used to generate the key pair. Anyone who knows (or can guess) this seed can re-generate the key pair by passing it along with the recipe.
recipeThe recipe in JSON Format for Recipes.

Member Function Documentation

◆ deriveFromSeed()

UnsealingKey UnsealingKey::deriveFromSeed ( const std::string &  seedString,
const std::string &  recipe 
)
static

Construct a new UnsealingKey by deriving a public/private key pair from a seed string and a set of recipe in JSON Format for Recipes.

Parameters
seedStringThe private seed which is used to generate the key pair. Anyone who knows (or can guess) this seed can re-generate the key pair by passing it along with the recipe.
recipeThe recipe in JSON Format for Recipes.

◆ fromJson()

UnsealingKey UnsealingKey::fromJson ( const std::string &  unsealingKeyAsJson)
static

Construct (reconstitute) from serialized JSON format.

Parameters
unsealingKeyAsJson

◆ fromSerializedBinaryForm()

UnsealingKey UnsealingKey::fromSerializedBinaryForm ( const SodiumBuffer serializedBinaryForm)
static

Deserialize from a byte array stored as a list of: (unsealingKeyBytes, sealingKeyBytes, recipe)

Stored in SodiumBuffer's fixed-length list format. Strings are stored as UTF8 byte arrays.

◆ toJson()

const std::string UnsealingKey::toJson ( int  indent = -1,
const char  indent_char = ' ' 
) const

Serialize this object to a JSON-formatted string.

It can be reconstituted by calling the constructor with this string.

Parameters
indentThe number of characters to indent the JSON (optional)
indent_charThe character with which to indent the JSON (optional)
Returns
const std::string an UnsealingKey serialized to JSON format.

◆ toSerializedBinaryForm()

const SodiumBuffer UnsealingKey::toSerializedBinaryForm ( ) const

Serialize to byte array as a list of: (unsealingKeyBytes, sealingKeyBytes, recipe)

Stored in SodiumBuffer's fixed-length list format. Strings are stored as UTF8 byte arrays.

◆ unseal() [1/4]

const SodiumBuffer UnsealingKey::unseal ( const PackagedSealedMessage packagedSealedMessage) const

Unseal a message from packaged format, ignoring the recipe since this UnsealingKey has been instantiated. (If it's the wrong key, the unseal will fail.)

Parameters
packagedSealedMessageThe message to be unsealed
Returns
const SodiumBuffer The plaintext message that had been sealed

◆ unseal() [2/4]

static const SodiumBuffer UnsealingKey::unseal ( const PackagedSealedMessage packagedSealedMessage,
const std::string &  seedString 
)
inlinestatic

Unseal a message by re-deriving the UnsealingKey from its seed.

Parameters
packagedSealedMessageThe message to be unsealed
seedStringThe seed string used to generate the key pair of the SealingKey used to seal this message and the UnsealingKey needed to unseal it.
Returns
const SodiumBuffer The plaintesxt message that had been sealed

◆ unseal() [3/4]

const SodiumBuffer UnsealingKey::unseal ( const std::vector< unsigned char > &  ciphertext,
const std::string &  unsealingInstructions = {} 
) const

Unseal a message.

Parameters
ciphertextThe sealed message to be unsealed
unsealingInstructionsIf this optional value was set during the SealingKey::seal operation, the same value must be provided to unseal the message or the operation will fail.
Returns
const SodiumBuffer
Exceptions
CryptographicVerificationFailureExceptionThrown if the ciphertext is not valid and cannot be unsealed.

◆ unseal() [4/4]

const SodiumBuffer UnsealingKey::unseal ( const unsigned char *  ciphertext,
const size_t  ciphertextLength,
const std::string &  unsealingInstructions 
) const

Unseal a message.

Parameters
ciphertextThe sealed message to be unsealed
ciphertextLengthThe length of the sealed message
unsealingInstructionsIf this optional value was set during the SealingKey::seal operation, the same value must be provided to unseal the message or the operation will fail. It can be used to pair a secret (sealed) message with public instructions about what should happen after the message is unsealed.
Returns
const SodiumBuffer
Exceptions
CryptographicVerificationFailureExceptionThrown if the ciphertext is not valid and cannot be unsealed.

The documentation for this class was generated from the following files: