DiceKeys Seeded Cryptography Library
sealing-key.hpp
1 #pragma once
2 
3 #include <vector>
4 #include <string>
5 #include <sodium.h>
6 #include "sodium-buffer.hpp"
7 #include "packaged-sealed-message.hpp"
8 
36 class SealingKey {
37 public:
43  static SealingKey fromJson(const std::string& sealingKeyAsJson);
44 
48  const std::vector<unsigned char> sealingKeyBytes;
52  const std::string recipe;
53 
57  SealingKey(
58  const std::vector<unsigned char>& sealingKeyBytes,
59  const std::string& recipe
60  );
61 
71  const std::string toJson(
72  int indent = -1,
73  const char indent_char = ' '
74  ) const;
75 
93  static const std::vector<unsigned char> sealToCiphertextOnly(
94  const SodiumBuffer& message,
95  const std::vector<unsigned char>& sealingKeyBytes,
96  const std::string& unsealingInstructions = {}
97  );
98 
117  static const std::vector<unsigned char> sealToCiphertextOnly(
118  const unsigned char* message,
119  const size_t messageLength,
120  const std::vector<unsigned char> &sealingKeyBytes,
121  const std::string& unsealingInstructions = {}
122  );
123 
135  const std::vector<unsigned char> sealToCiphertextOnly(
136  const unsigned char* message,
137  const size_t messageLength,
138  const std::string& unsealingInstructions = {}
139  ) const;
140 
149  const std::vector<unsigned char> sealToCiphertextOnly(
150  const SodiumBuffer &message,
151  const std::string& unsealingInstructions = {}
152  ) const;
153 
154 
168  const SodiumBuffer& message,
169  const std::string& unsealingInstructions
170  ) const;
171 
185  const std::vector<unsigned char>& message,
186  const std::string& unsealingInstructions = ""
187  ) const;
188 
189 
190 
204  const std::string& message,
205  const std::string& unsealingInstructions = {}
206  ) const;
207 
208 
223  const unsigned char* message,
224  const size_t messageLength,
225  const std::string& unsealingInstructions
226  ) const;
227 
233  const std::vector<unsigned char> getSealingKeyBytes() const;
234 
241  const std::string getRecipeJson() const {
242  return recipe;
243  }
244 
252  const SodiumBuffer toSerializedBinaryForm() const;
253 
261  static SealingKey fromSerializedBinaryForm(const SodiumBuffer &serializedBinaryForm);
262 
263 };
264 
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
SealingKey::toSerializedBinaryForm
const SodiumBuffer toSerializedBinaryForm() const
Serialize to byte array as a list of: (sealingKeyBytes, recipe)
Definition: sealing-key.cpp:146
SealingKey::recipe
const std::string recipe
A JSON Format for Recipes string used to specify how this key is derived.
Definition: sealing-key.hpp:52
SealingKey::SealingKey
SealingKey(const std::vector< unsigned char > &sealingKeyBytes, const std::string &recipe)
Construct a new Public Key object by passing its members.
Definition: sealing-key.cpp:14
SealingKey::toJson
const std::string toJson(int indent=-1, const char indent_char=' ') const
Serialize this object to a JSON-formatted string.
Definition: sealing-key.cpp:35
PackagedSealedMessage
When a message is sealed, the ciphertext is packaged with the recipe in JSON Format for Recipes,...
Definition: packaged-sealed-message.hpp:14
SealingKey
A sealingKeyBytes is used to seal messages, in combination with a UnsealingKey which can unseal them....
Definition: sealing-key.hpp:36
SealingKey::getSealingKeyBytes
const std::vector< unsigned char > getSealingKeyBytes() const
Get the copy of the raw public key bytes used by lib-sodium.
Definition: sealing-key.cpp:141
SealingKey::getRecipeJson
const std::string getRecipeJson() const
Get the JSON-formatted recipe string used to generate the public-private key pair.
Definition: sealing-key.hpp:241
SealingKey::sealToCiphertextOnly
static const std::vector< unsigned char > sealToCiphertextOnly(const SodiumBuffer &message, const std::vector< unsigned char > &sealingKeyBytes, const std::string &unsealingInstructions={})
Avoid Using Seal a message using a raw libsodium public key.
Definition: sealing-key.cpp:75
SealingKey::fromSerializedBinaryForm
static SealingKey fromSerializedBinaryForm(const SodiumBuffer &serializedBinaryForm)
Deserialize from a byte array stored as a list of: (sealingKeyBytes, recipe)
Definition: sealing-key.cpp:156
SealingKey::seal
const PackagedSealedMessage seal(const SodiumBuffer &message, const std::string &unsealingInstructions) const
Seal a plaintext message and then package the results along with its recipe and unsealingInstructions...
Definition: sealing-key.cpp:111
SealingKey::fromJson
static SealingKey fromJson(const std::string &sealingKeyAsJson)
Construct a sealingKeyBytes from a JSON string.
Definition: sealing-key.cpp:23
SealingKey::sealingKeyBytes
const std::vector< unsigned char > sealingKeyBytes
The binary representation of the public key used for sealing.
Definition: sealing-key.hpp:48