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 "DwmReadable.hh" 56 #include "DwmWritable.hh" 72 :
public CryptoPP::RSA::PublicKey,
73 public Dwm::Readable,
public Dwm::Writable
77 : CryptoPP::RSA::PublicKey()
80 PublicKey(
const CryptoPP::RSA::PublicKey & key)
81 : CryptoPP::RSA::PublicKey(key)
86 std::istream & Read(std::istream & is);
88 size_t Read(FILE * f);
90 std::ostream & Write(std::ostream & os)
const;
91 ssize_t Write(
int fd)
const;
92 size_t Write(FILE *f)
const;
93 uint32_t StreamedLength()
const;
95 std::string ToString()
const;
96 std::string ToBase64String()
const;
97 bool FromString(
const std::string & s);
98 bool FromBase64String(
const std::string & s);
110 :
public CryptoPP::RSA::PrivateKey,
111 public Dwm::Readable,
public Dwm::Writable
115 : CryptoPP::RSA::PrivateKey()
118 PrivateKey(
const CryptoPP::RSA::PrivateKey & key)
119 : CryptoPP::RSA::PrivateKey(key)
122 bool IsValid()
const;
124 std::istream & Read(std::istream & is);
125 ssize_t Read(
int fd);
126 size_t Read(FILE * f);
128 std::ostream & Write(std::ostream & os)
const;
129 ssize_t Write(
int fd)
const;
130 size_t Write(FILE *f)
const;
131 uint32_t StreamedLength()
const;
133 std::string ToString()
const;
134 std::string ToBase64String()
const;
135 bool FromString(
const std::string & s);
147 :
public std::pair<PrivateKey,PublicKey>
170 this->first = keys.first;
171 this->second = keys.second;
208 bool Load(
const std::string & privKeyPath, std::string & name);
237 #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...
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:146
Definition: DwmAuth.hh:48
KeyPair(const PrivateKey &privKey, const PublicKey &publicKey)
Construct from a private and public key.
Definition: DwmAuthPKCrypto.hh:160
Public key crypto utilities.
Definition: DwmAuthPKCrypto.hh:65
const PrivateKey & Private() const
Returns a const reference to the private key.
Definition: DwmAuthPKCrypto.hh:179
const PublicKey & Public() const
Returns a const reference to the public key.
Definition: DwmAuthPKCrypto.hh:195
KeyPair()
Default constructor.
Definition: DwmAuthPKCrypto.hh:153
PrivateKey & Private()
Returns a mutable reference to the private key.
Definition: DwmAuthPKCrypto.hh:187
PublicKey & Public()
Returns a mutable reference to the public key.
Definition: DwmAuthPKCrypto.hh:203
Encapsulates a readable and writable private key.
Definition: DwmAuthPKCrypto.hh:109
Encapsulates a readable and writable public key.
Definition: DwmAuthPKCrypto.hh:71