Virgil Security Crypto library  2.6.3
VirgilPBE.h
1 
37 #ifndef VIRGIL_CRYPTO_VIRGIL_PBE_H
38 #define VIRGIL_CRYPTO_VIRGIL_PBE_H
39 
40 #include <cstdlib>
41 #include <memory>
42 
43 #include "../VirgilByteArray.h"
44 #include "asn1/VirgilAsn1Compatible.h"
45 
46 namespace virgil { namespace crypto { namespace foundation {
47 
53 public:
57  enum class Algorithm {
58  PKCS5,
59  PKCS12
60  };
61 
65 
70  static constexpr size_t kIterationCountMin = 1024;
72 public:
76 
82  VirgilPBE();
83 
91  VirgilPBE(Algorithm alg, const VirgilByteArray& salt, size_t iterationCount = kIterationCountMin);
92 
94 
97 
106  const virgil::crypto::VirgilByteArray& pwd) const;
107 
116  const virgil::crypto::VirgilByteArray& pwd) const;
118 
129  size_t asn1Write(asn1::VirgilAsn1Writer& asn1Writer, size_t childWrittenBytes = 0) const override;
131 
132  void asn1Read(asn1::VirgilAsn1Reader& asn1Reader) override;
134 public:
136  VirgilPBE(VirgilPBE&& rhs) noexcept;
137 
138  VirgilPBE& operator=(VirgilPBE&& rhs) noexcept;
139 
140  virtual ~VirgilPBE() noexcept;
142 
143 private:
147  void checkState() const;
148 
152  virgil::crypto::VirgilByteArray process(
153  const virgil::crypto::VirgilByteArray& data,
154  const virgil::crypto::VirgilByteArray& pwd, int mode) const;
155 
156 private:
157  class Impl;
158 
159  std::unique_ptr<Impl> impl_;
160 };
161 
162 }}}
163 
164 #endif /* VIRGIL_CRYPTO_VIRGIL_PBE_H */
Algorithm
Enumerates possible Password Based Encryption algorithms.
Definition: VirgilPBE.h:57
This class provides methods for reading ASN.1 data structure.
Definition: VirgilAsn1Reader.h:53
Provides Password-Based Cryptography. Now PKCS#5 and PKCS#12 are partially supported.
Definition: VirgilPBE.h:52
This class provides interface that allow to save and restore object state in the ASN.1 structure.
Definition: VirgilAsn1Compatible.h:59
Definition: VirgilHash.h:265
This class provides methods for writing ASN.1 data structure.
Definition: VirgilAsn1Writer.h:54
Root namespace for all Virgil Security libraries.
Definition: VirgilAsn1Compatible.h:46
static constexpr size_t kIterationCountMin
Recommended iteration count that is used for key derivation.
Definition: VirgilPBE.h:70
std::vector< unsigned char > VirgilByteArray
This type represents a sequence of bytes.
Definition: VirgilByteArray.h:50
void asn1Read(asn1::VirgilAsn1Reader &asn1Reader) override
Read object state from the reader.
VirgilPBE()
Create object with undefined algorithm.
virgil::crypto::VirgilByteArray encrypt(const virgil::crypto::VirgilByteArray &data, const virgil::crypto::VirgilByteArray &pwd) const
Encrypt data with given password.
PBE Algorithm: from the standard PKCS#12.
PBE Algorithm: from the standard PKCS#5.
virgil::crypto::VirgilByteArray decrypt(const virgil::crypto::VirgilByteArray &data, const virgil::crypto::VirgilByteArray &pwd) const
Decrypt data with given password.
size_t asn1Write(asn1::VirgilAsn1Writer &asn1Writer, size_t childWrittenBytes=0) const override
Write object state to the writer.