Virgil Security Crypto library  2.6.3
VirgilCipherBase.h
1 
37 #ifndef VIRGIL_CIPHER_BASE_H
38 #define VIRGIL_CIPHER_BASE_H
39 
40 #include <map>
41 #include <set>
42 #include <memory>
43 
44 #include "VirgilByteArray.h"
45 #include "VirgilCustomParams.h"
46 
50 namespace virgil { namespace crypto { namespace foundation {
52 class VirgilSymmetricCipher;
53 }}}
55 
56 namespace virgil { namespace crypto {
57 
62 public:
67 
68 public:
72 
79  void addKeyRecipient(const VirgilByteArray& recipientId, const VirgilByteArray& publicKey);
80 
86  void removeKeyRecipient(const VirgilByteArray& recipientId);
87 
98  bool keyRecipientExists(const VirgilByteArray& recipientId) const;
99 
108  void addPasswordRecipient(const VirgilByteArray& pwd);
109 
114  void removePasswordRecipient(const VirgilByteArray& pwd);
115 
125  bool passwordRecipientExists(const VirgilByteArray& password) const;
126 
130  void removeAllRecipients();
132 
138 
148  VirgilByteArray getContentInfo() const;
149 
156  void setContentInfo(const VirgilByteArray& contentInfo);
157 
162  static size_t defineContentInfoSize(const VirgilByteArray& data);
164 
171 
177  VirgilCustomParams& customParams();
178 
183  const VirgilCustomParams& customParams() const;
185 
188 
202  static VirgilByteArray computeShared(
203  const VirgilByteArray& publicKey,
204  const VirgilByteArray& privateKey, const VirgilByteArray& privateKeyPassword = VirgilByteArray());
206 
207 protected:
217  VirgilByteArray filterAndSetupContentInfo(const VirgilByteArray& encryptedData, bool isLastChunk);
218 
224  void initEncryption();
225 
230  void initDecryptionWithPassword(const VirgilByteArray& pwd);
231 
238  void initDecryptionWithKey(
239  const VirgilByteArray& recipientId,
240  const VirgilByteArray& privateKey, const VirgilByteArray& privateKeyPassword);
241 
245  bool isInited() const;
246 
250  bool isReadyForEncryption() const;
251 
255  bool isReadyForDecryption() const;
256 
262 
269  void buildContentInfo();
270 
279  void clear();
280 
281 public:
283  VirgilCipherBase(VirgilCipherBase&& rhs) noexcept;
284 
285  VirgilCipherBase& operator=(VirgilCipherBase&& rhs) noexcept;
286 
287  virtual ~VirgilCipherBase() noexcept;
289 
290 private:
291  virtual VirgilByteArray doDecryptWithKey(
292  const VirgilByteArray& algorithm, const VirgilByteArray& encryptedKey,
293  const VirgilByteArray& privateKey, const VirgilByteArray& privateKeyPassword) const;
294 
295  virtual VirgilByteArray doDecryptWithPassword(
296  const VirgilByteArray& encryptedKey, const VirgilByteArray& encryptionAlgorithm,
297  const VirgilByteArray& password) const;
298 
299 
305  void accomplishInitDecryption();
306 
307 private:
308  class Impl;
309 
310  std::unique_ptr<Impl> impl_;
311 };
312 
313 }}
314 
315 #endif /* VIRGIL_CIPHER_BASE_H */
Data object that represent ASN.1 structure: VirgilCustomParams.
Definition: VirgilCustomParams.h:51
Root namespace for all Virgil Security libraries.
Definition: VirgilAsn1Compatible.h:46
std::vector< unsigned char > VirgilByteArray
This type represents a sequence of bytes.
Definition: VirgilByteArray.h:50
Provides symmetric ciphers algorithms.
Definition: VirgilSymmetricCipher.h:52
This class provides configuration methods to all Virgil*Cipher classes.
Definition: VirgilCipherBase.h:61