42 #ifndef _DWMAUTHPKCRYPTO_HH_ 43 #define _DWMAUTHPKCRYPTO_HH_ 48 #include <cryptopp/cryptlib.h> 49 #include <cryptopp/aes.h> 50 #include <cryptopp/filters.h> 51 #include <cryptopp/gcm.h> 52 #include <cryptopp/osrng.h> 53 #include <cryptopp/rsa.h> 55 #include "DwmDescriptorIOCapable.hh" 56 #include "DwmFileIOCapable.hh" 57 #include "DwmStreamIOCapable.hh" 58 #include "DwmStreamedLengthCapable.hh" 74 :
public CryptoPP::RSA::PublicKey,
75 public DescriptorIOCapable,
public FileIOCapable,
76 public StreamIOCapable,
public StreamedLengthCapable
80 : CryptoPP::RSA::PublicKey()
83 PublicKey(
const CryptoPP::RSA::PublicKey & key)
84 : CryptoPP::RSA::PublicKey(key)
89 std::istream & Read(std::istream & is)
override;
90 ssize_t Read(
int fd)
override;
91 size_t Read(FILE * f)
override;
93 std::ostream & Write(std::ostream & os)
const override;
94 ssize_t Write(
int fd)
const override;
95 size_t Write(FILE *f)
const override;
96 uint32_t StreamedLength()
const override;
98 std::string ToString()
const;
99 std::string ToBase64String()
const;
100 bool FromString(
const std::string & s);
101 bool FromBase64String(
const std::string & s);
113 :
public CryptoPP::RSA::PrivateKey,
114 public DescriptorIOCapable,
public FileIOCapable,
115 public StreamIOCapable,
public StreamedLengthCapable
119 : CryptoPP::RSA::PrivateKey()
122 PrivateKey(
const CryptoPP::RSA::PrivateKey & key)
123 : CryptoPP::RSA::PrivateKey(key)
126 bool IsValid()
const;
128 std::istream & Read(std::istream & is)
override;
129 ssize_t Read(
int fd)
override;
130 size_t Read(FILE * f)
override;
132 std::ostream & Write(std::ostream & os)
const override;
133 ssize_t Write(
int fd)
const override;
134 size_t Write(FILE *f)
const override;
135 uint32_t StreamedLength()
const override;
137 std::string ToString()
const;
138 std::string ToBase64String()
const;
139 bool FromString(
const std::string & s);
140 bool FromBase64String(
const std::string & s);
152 :
public std::pair<PrivateKey,PublicKey>
175 this->first = keys.first;
176 this->second = keys.second;
213 bool Load(
const std::string & privKeyPath, std::string & name);
227 Encrypt(
const PublicKey & publicKey,
const std::string & plainstr);
234 Decrypt(
const PrivateKey & privateKey,
const std::string & cipherstr);
242 #endif // _DWMAUTHPKCRYPTO_HH_ static std::string Encrypt(const PublicKey &publicKey, const std::string &plainstr)
Encrypts the given plainstr with the given publicKey and returns the encrypted string.
static std::string Decrypt(const PrivateKey &privateKey, const std::string &cipherstr)
Decrypts the given cipherstr using the given privateKey and returns the decrypted string.
KeyPair & operator=(const KeyPair &keys)
operator =
Definition: DwmAuthPKCrypto.hh:172
static KeyPair CreateKeyPair(unsigned int keySize)
Generate a private/public key pair.
bool operator==(const PublicKey &pk) const
operator ==
Encapsulates a private/public key pair.
Definition: DwmAuthPKCrypto.hh:151
KeyPair(const PrivateKey &privKey, const PublicKey &publicKey)
Construct from a private and public key.
Definition: DwmAuthPKCrypto.hh:165
Public key crypto utilities.
Definition: DwmAuthPKCrypto.hh:67
const PrivateKey & Private() const
Returns a const reference to the private key.
Definition: DwmAuthPKCrypto.hh:184
const PublicKey & Public() const
Returns a const reference to the public key.
Definition: DwmAuthPKCrypto.hh:200
KeyPair()
Default constructor.
Definition: DwmAuthPKCrypto.hh:158
PrivateKey & Private()
Returns a mutable reference to the private key.
Definition: DwmAuthPKCrypto.hh:192
bool operator==(const PrivateKey &pk) const
operator ==
PublicKey & Public()
Returns a mutable reference to the public key.
Definition: DwmAuthPKCrypto.hh:208
Encapsulates a readable and writable private key.
Definition: DwmAuthPKCrypto.hh:112
Encapsulates a readable and writable public key.
Definition: DwmAuthPKCrypto.hh:73