Wraps around an AES key's raw data for some added conveniences.
More...
#include <hdicoreCrypt.h>
|
| Key (const Key &key_) |
| Constructs a Key object from another (copy constructor)
|
|
| Key (const std::string &serializedKey_) |
| Constructs a Key object from a previous serialization of the key (using the serialize() method)
|
|
| Key (const int32_t size_) |
| Constructs a new(ly generated) Key object of a given size/length.
|
|
| Key (const int32_t size_, const ByteVector &bytes_) |
| Constructs a new(ly generated) Key object of a given size/length and a predetermined set of bytes.
|
|
virtual | ~Key () |
| Destructs a Key object.
|
|
Key & | operator= (const Key &rhs_) |
| Assigns one Key object to another.
|
|
bool | valid () const |
| Gets whether the object contains a valid key.
|
|
int32_t | length () const |
| Gets the size/length of the key in bits.
|
|
ByteVector | bytes () const |
| Gets the raw bytes of the AES key.
|
|
std::string | serialize () const |
| Serializes the key in a base-64 string; useful for transmitting the string to another party or writing the key to disk (not recommended without encrypting it first!)
|
|
bool | operator== (const Key &rhs_) const |
| Compares two Key objects for equality.
|
|
bool | operator!= (const Key &rhs_) const |
| Compares two Key objects for inequality.
|
|
|
plat::AESKey * | __accessImpl (const Key &) |
|
bool | encrypt (const Key &, const InitVector &, const std::string &, std::string &) |
| Encrypts a string (or raw bytes stuffed into a string) with an AES key.
|
|
bool | decrypt (const Key &, const InitVector &, const std::string &, std::string &) |
| Decrypts a base-64 encoded string of cipher text (previously encrypted with the encrypt() function or equivalent)
|
|
Wraps around an AES key's raw data for some added conveniences.
◆ Key() [1/4]
hdi::core::crypt::aes::Key::Key |
( |
const Key & |
key_ | ) |
|
Constructs a Key object from another (copy constructor)
- Author
- GW
- Date
- 10/2013
- Parameters
-
key_ | Key object to copy values from |
◆ Key() [2/4]
hdi::core::crypt::aes::Key::Key |
( |
const std::string & |
serializedKey_ | ) |
|
Constructs a Key object from a previous serialization of the key (using the serialize() method)
- Author
- GW
- Date
- 10/2013
- Parameters
-
serializedKey_ | Base-64 encoded serialization of an AES key |
◆ Key() [3/4]
hdi::core::crypt::aes::Key::Key |
( |
const int32_t |
size_ | ) |
|
Constructs a new(ly generated) Key object of a given size/length.
- Author
- GW
- Date
- 10/2013
- Parameters
-
size_ | Size/length of the key in bits (must be 128, 192, or 256) |
◆ Key() [4/4]
hdi::core::crypt::aes::Key::Key |
( |
const int32_t |
size_, |
|
|
const ByteVector & |
bytes_ |
|
) |
| |
Constructs a new(ly generated) Key object of a given size/length and a predetermined set of bytes.
- Author
- GW
- Date
- 10/2013
- Parameters
-
size_ | Size/length of the key in bits (must be 128, 192, or 256) |
bytes_ | Raw bytes to use for the AES key (must contain size_/8 bytes) |
◆ ~Key()
virtual hdi::core::crypt::aes::Key::~Key |
( |
| ) |
|
|
virtual |
Destructs a Key object.
- Author
- GW
- Date
- 10/2013
◆ bytes()
ByteVector hdi::core::crypt::aes::Key::bytes |
( |
| ) |
const |
Gets the raw bytes of the AES key.
- Author
- GW
- Date
- 10/2013
- Returns
- A container of all the raw byte values of the AES key
◆ length()
int32_t hdi::core::crypt::aes::Key::length |
( |
| ) |
const |
Gets the size/length of the key in bits.
- Author
- GW
- Date
- 10/2013
- Returns
- The number of bits for the key
◆ operator!=()
bool hdi::core::crypt::aes::Key::operator!= |
( |
const Key & |
rhs_ | ) |
const |
Compares two Key objects for inequality.
- Author
- GW
- Date
- 10/2013
- Parameters
-
rhs_ | Righthand side of the inequality operator; Key object to compare against |
- Returns
- true if the two objects have differing key values, false otherwise
◆ operator=()
Key & hdi::core::crypt::aes::Key::operator= |
( |
const Key & |
rhs_ | ) |
|
Assigns one Key object to another.
- Author
- GW
- Date
- 10/2013
- Parameters
-
rhs_ | Righthand side of the assignment operator; key object to copy values from |
- Returns
- A reference to the target object (lefthand side of assignment operator), but with its values updated
◆ operator==()
bool hdi::core::crypt::aes::Key::operator== |
( |
const Key & |
rhs_ | ) |
const |
Compares two Key objects for equality.
- Author
- GW
- Date
- 10/2013
- Parameters
-
rhs_ | Righthand side of the equality operator; Key object to compare against |
- Returns
- true if the two objects have the same key values, false otherwise
◆ serialize()
std::string hdi::core::crypt::aes::Key::serialize |
( |
| ) |
const |
Serializes the key in a base-64 string; useful for transmitting the string to another party or writing the key to disk (not recommended without encrypting it first!)
- Author
- GW
- Date
- 10/2013
- Returns
- The serialized version of the key
- Note
- A key serialization string can be converted back into a Key object at runtime with the Key(const std::string&) constructor.
◆ valid()
bool hdi::core::crypt::aes::Key::valid |
( |
| ) |
const |
Gets whether the object contains a valid key.
- Author
- GW
- Date
- 10/2013
- Returns
- true if the key is valid/not empty, false otherwise
◆ decrypt
bool decrypt |
( |
const Key & |
, |
|
|
const InitVector & |
, |
|
|
const std::string & |
, |
|
|
std::string & |
|
|
) |
| |
|
friend |
Decrypts a base-64 encoded string of cipher text (previously encrypted with the encrypt() function or equivalent)
- Author
- GW
- Date
- 10/2013
- Parameters
-
key_ | AES key to use for decryption |
iv_ | Initialization vector to use for this decryption call |
b64Cipher_ | Base-64 encoded cipher text to attempt to decrypt |
data__ | Return-by-reference for the decrypted plain text (or raw bytes stuffed into a string) |
- Returns
- true if the data could be decrypted, false otherwise
◆ encrypt
bool encrypt |
( |
const Key & |
, |
|
|
const InitVector & |
, |
|
|
const std::string & |
, |
|
|
std::string & |
|
|
) |
| |
|
friend |
Encrypts a string (or raw bytes stuffed into a string) with an AES key.
- Author
- GW
- Date
- 10/2013
- Parameters
-
key_ | AES key to use for encryption |
iv_ | Initialization vector to use for this encryption call |
data_ | Plain data to be encrypted (in the form of a string or binary data inside of a string object) |
b64Cipher__ | Return-by-reference for the base-64 encoded cipher text |
- Returns
- true if the data could be encrypted, false otherwise
- Note
- To decrypt the cipher, use the decrypt() function (or equivalent - this lib is built on OpenSSL and the AES standard, so any base-64 decoder and function that understands AES decryption can decrypt the cipher with the correct key and initialization vector).