DiceKeys Seeded Cryptography Library
unsealing-key.hpp
1 #pragma once
2 
3 #include "sodium-buffer.hpp"
4 #include "sealing-key.hpp"
5 
16 class UnsealingKey {
17 public:
25  const std::vector<unsigned char> sealingKeyBytes;
29  const std::string recipe;
30 
36  const std::vector<unsigned char> sealingKeyBytes,
37  const std::string recipe
38  );
39 
49  const SodiumBuffer& seedBuffer,
50  const std::string& recipe
51  );
52 
64  const std::string& seedString,
65  const std::string& recipe
66  );
67 
79  const std::string& seedString,
80  const std::string& recipe
81  );
82 
83 
84 
90  static UnsealingKey fromJson(
91  const std::string& unsealingKeyAsJson
92  );
93 
94 
99  const UnsealingKey& other
100  );
101 
106  const SealingKey getSealingKey() const;
107 
123  const SodiumBuffer unseal(
124  const unsigned char* ciphertext,
125  const size_t ciphertextLength,
126  const std::string& unsealingInstructions
127  ) const;
128 
141  const SodiumBuffer unseal(
142  const std::vector<unsigned char> &ciphertext,
143  const std::string& unsealingInstructions = {}
144  ) const;
145 
154  const SodiumBuffer unseal(
155  const PackagedSealedMessage& packagedSealedMessage
156  ) const;
157 
166  static const SodiumBuffer unseal(
167  const PackagedSealedMessage &packagedSealedMessage,
168  const std::string& seedString
169  ) {
170  return UnsealingKey(seedString, packagedSealedMessage.recipe)
171  .unseal(packagedSealedMessage.ciphertext, packagedSealedMessage.unsealingInstructions);
172  }
173 
183  const std::string toJson(
184  int indent = -1,
185  const char indent_char = ' '
186  ) const;
187 
195  const SodiumBuffer toSerializedBinaryForm() const;
196 
204  static UnsealingKey fromSerializedBinaryForm(const SodiumBuffer &serializedBinaryForm);
205 
206 
207 };
UnsealingKey::unseal
const SodiumBuffer unseal(const unsigned char *ciphertext, const size_t ciphertextLength, const std::string &unsealingInstructions) const
Unseal a message.
Definition: unsealing-key.cpp:60
SodiumBuffer
A byte array containing a length and a pointer to memory (the data field), which ensures data is eras...
Definition: sodium-buffer.hpp:27
UnsealingKey
an UnsealingKey is used to unseal messages sealed with its corresponding SealingKey....
Definition: unsealing-key.hpp:16
UnsealingKey::sealingKeyBytes
const std::vector< unsigned char > sealingKeyBytes
The libsodium public key used for sealing.
Definition: unsealing-key.hpp:25
UnsealingKey::unseal
static const SodiumBuffer unseal(const PackagedSealedMessage &packagedSealedMessage, const std::string &seedString)
Unseal a message by re-deriving the UnsealingKey from its seed.
Definition: unsealing-key.hpp:166
UnsealingKey::recipe
const std::string recipe
A JSON Format for Recipes string used to specify how this key is derived.
Definition: unsealing-key.hpp:29
PackagedSealedMessage
When a message is sealed, the ciphertext is packaged with the recipe in JSON Format for Recipes,...
Definition: packaged-sealed-message.hpp:14
UnsealingKey::fromSerializedBinaryForm
static UnsealingKey fromSerializedBinaryForm(const SodiumBuffer &serializedBinaryForm)
Deserialize from a byte array stored as a list of: (unsealingKeyBytes, sealingKeyBytes,...
Definition: unsealing-key.cpp:150
UnsealingKey::fromJson
static UnsealingKey fromJson(const std::string &unsealingKeyAsJson)
Construct (reconstitute) from serialized JSON format.
Definition: unsealing-key.cpp:113
SealingKey
A sealingKeyBytes is used to seal messages, in combination with a UnsealingKey which can unseal them....
Definition: sealing-key.hpp:36
UnsealingKey::UnsealingKey
UnsealingKey(const SodiumBuffer unsealingKeyBytes, const std::vector< unsigned char > sealingKeyBytes, const std::string recipe)
Construct a new UnsealingKey by passing its members.
Definition: unsealing-key.cpp:9
UnsealingKey::deriveFromSeed
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 re...
Definition: unsealing-key.cpp:41
PackagedSealedMessage::ciphertext
const std::vector< unsigned char > ciphertext
The sealed message as a raw array of bytes.
Definition: packaged-sealed-message.hpp:20
PackagedSealedMessage::unsealingInstructions
const std::string unsealingInstructions
Optional public instructions that the sealer requests the unsealer to follow as a condition of unseal...
Definition: packaged-sealed-message.hpp:30
UnsealingKey::toSerializedBinaryForm
const SodiumBuffer toSerializedBinaryForm() const
Serialize to byte array as a list of: (unsealingKeyBytes, sealingKeyBytes, recipe)
Definition: unsealing-key.cpp:139
UnsealingKey::unsealingKeyBytes
const SodiumBuffer unsealingKeyBytes
The libSodium private key used for unsealing.
Definition: unsealing-key.hpp:21
PackagedSealedMessage::recipe
const std::string recipe
The recipe used to generate the encryption/decryption keys.
Definition: packaged-sealed-message.hpp:25
UnsealingKey::toJson
const std::string toJson(int indent=-1, const char indent_char=' ') const
Serialize this object to a JSON-formatted string.
Definition: unsealing-key.cpp:127
UnsealingKey::getSealingKey
const SealingKey getSealingKey() const
Get the SealingKey used to seal messages that can be unsealed with this UnsealingKey.
Definition: unsealing-key.cpp:99