Hot Door CORE 0.8.2
Adobe® Illustrator® Plug-in Library
Loading...
Searching...
No Matches
hdicoreCrypt.h
Go to the documentation of this file.
1
7#ifndef __HDI_CORE_CRYPT__
8#define __HDI_CORE_CRYPT__
9
10#include <vector>
11
12#include "hdicoreTypes.h"
13
14namespace hdi
15{
16 namespace plat
17 {
18 class AESKey;
19 class AESInitializationVector;
20 class PublicRSAKey;
21 class PrivateRSAKey;
22 }
23
24 namespace core
25 {
29 namespace crypt
30 {
41 std::string rot13(const std::string& str_);
42
52 std::string md5(const std::string& str_);
53
63 std::string sha1(const std::string& str_);
64
74 std::string sha2_256(const std::string& str_);
75
85 std::string sha2_512(const std::string& str_);
86
95 std::string base64Encode(const std::string& plain_);
96
105 std::string base64Decode(const std::string& cipher_);
106
107 namespace aes
108 {
109 class Key;
110 class InitVector;
111 }
112
116 namespace aes
117 {
118 typedef std::vector<byte> ByteVector;
119
136 bool encrypt(const Key& key_, const InitVector& iv_, const std::string& data_, std::string& b64Cipher__);
137
151 bool decrypt(const Key& key_, const InitVector& iv_, const std::string& b64Cipher_, std::string& data__);
152
156 class Key
157 {
158 public:
166 Key(const Key& key_);
167
176 Key(const std::string& serializedKey_);
177
185 Key(const int32_t size_);
186
196 Key(const int32_t size_, const ByteVector& bytes_);
197
203 virtual ~Key();
204
214 Key& operator=(const Key& rhs_);
215
223 bool valid() const;
224
232 int32_t length() const;
233
241 ByteVector bytes() const;
242
255 std::string serialize() const;
256
265 bool operator==(const Key& rhs_) const;
266
275 bool operator!=(const Key& rhs_) const;
276
277
278 private:
279 friend plat::AESKey* __accessImpl(const Key&);
280
281 friend bool encrypt(const Key&, const InitVector&, const std::string&, std::string&);
282 friend bool decrypt(const Key&, const InitVector&, const std::string&, std::string&);
283
287 plat::AESKey* __impl;
288
294 Key();
295 };
296
297 typedef std::unique_ptr<Key> KeyUP;
298 typedef std::shared_ptr<Key> KeySP;
299 typedef std::weak_ptr<Key> KeyWP;
300
305 {
306 public:
319
328
337 InitVector(const std::string& serializedIV_);
338
344 virtual ~InitVector();
345
357
365 ByteVector bytes() const;
366
378 std::string serialize() const;
379
388 bool operator==(const InitVector& rhs_) const;
389
398 bool operator!=(const InitVector& rhs_) const;
399
400
401 private:
402 friend plat::AESInitializationVector* __accessImpl(const InitVector&);
403
404 friend bool encrypt(const Key&, const InitVector&, const std::string&, std::string&);
405 friend bool decrypt(const Key&, const InitVector&, const std::string&, std::string&);
406
410 plat::AESInitializationVector* __impl;
411 };
412
413 typedef std::unique_ptr<InitVector> InitVectorUP;
414 typedef std::shared_ptr<InitVector> InitVectorSP;
415 typedef std::weak_ptr<InitVector> InitVectorWP;
416
417 extern plat::AESKey* __accessImpl(const Key&);
418 extern plat::AESInitializationVector* __accessImpl(const InitVector&);
419 }
420
421 namespace rsa
422 {
423 class PublicKey;
424 class PrivateKey;
425 }
426
430 namespace rsa
431 {
444 bool generateKeyPair(const int32_t size_, PrivateKey& privKey__, PublicKey& pubKey__);
445
461 bool encryptWithPublicKey(const PublicKey& key_, const std::string& data_, std::string& b64Cipher__);
462
475 bool decryptWithPrivateKey(const PrivateKey& key_, const std::string& b64Cipher_, std::string& data__);
476
497 bool encryptWithPrivateKey(const PrivateKey& key_, const std::string& data_, std::string& b64Cipher__);
498
511 bool decryptWithPublicKey(const PublicKey& key_, const std::string& b64Cipher_, std::string& data__);
512
517 {
518 public:
531
539 PublicKey(const PublicKey& key_);
540
549 PublicKey(const std::string& serializedKey_);
550
556 virtual ~PublicKey();
557
569
577 bool valid() const;
578
586 int32_t length() const;
587
599 std::string serialize() const;
600
609 bool operator==(const PublicKey& rhs_) const;
610
619 bool operator!=(const PublicKey& rhs_) const;
620
621
622 private:
623 friend bool generateKeyPair(const int32_t, PrivateKey&, PublicKey&);
624 friend bool encryptWithPublicKey(const PublicKey&, const std::string&, std::string&);
625 friend bool decryptWithPrivateKey(const PrivateKey&, const std::string&, std::string&);
626 friend bool encryptWithPrivateKey(const PrivateKey&, const std::string&, std::string&);
627 friend bool decryptWithPublicKey(const PublicKey&, const std::string&, std::string&);
628
632 plat::PublicRSAKey* __impl;
633 };
634
635 typedef std::unique_ptr<PublicKey> PublicKeyUP;
636 typedef std::shared_ptr<PublicKey> PublicKeySP;
637 typedef std::weak_ptr<PublicKey> PublicKeyWP;
638
643 {
644 public:
657
665 PrivateKey(const PrivateKey& key_);
666
675 PrivateKey(const std::string& serializedKey_);
676
682 virtual ~PrivateKey();
683
695
703 bool valid() const;
704
712 int32_t length() const;
713
726 std::string serialize() const;
727
736 bool operator==(const PrivateKey& rhs_) const;
737
746 bool operator!=(const PrivateKey& rhs_) const;
747
748
749 private:
750 friend bool generateKeyPair(const int32_t, PrivateKey&, PublicKey&);
751 friend bool encryptWithPublicKey(const PublicKey&, const std::string&, std::string&);
752 friend bool decryptWithPrivateKey(const PrivateKey&, const std::string&, std::string&);
753 friend bool encryptWithPrivateKey(const PrivateKey&, const std::string&, std::string&);
754 friend bool decryptWithPublicKey(const PublicKey&, const std::string&, std::string&);
755
759 plat::PrivateRSAKey* __impl;
760 };
761
762 typedef std::unique_ptr<PrivateKey> PrivateKeyUP;
763 typedef std::shared_ptr<PrivateKey> PrivateKeySP;
764 typedef std::weak_ptr<PrivateKey> PrivateKeyWP;
765 }
766 }
767 }
768}
769
770#endif
771// __HDI_CORE_CRYPT__
Wraps around an AES initialization vector's raw data for some added conveniences.
Definition: hdicoreCrypt.h:305
bool operator==(const InitVector &rhs_) const
Compares two InitVector objects for equality.
ByteVector bytes() const
Gets the raw bytes of the AES initialization vector.
friend 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.
friend 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...
bool operator!=(const InitVector &rhs_) const
Compares two InitVector objects for inequality.
virtual ~InitVector()
Destructs an InitVector object.
InitVector()
Constructs a new(ly generated) InitVector object for some random initialization vector values.
InitVector(const std::string &serializedIV_)
Constructs an InitVector object from a previous serialization of the initialization vector (using the...
std::string serialize() const
Serializes the initialization vector in a base-64 string; useful for transmitting the string to anoth...
InitVector & operator=(const InitVector &rhs_)
Assigns one InitVector object to another.
InitVector(const InitVector &iv_)
Constructs an InitVector object from another (copy constructor)
Wraps around an AES key's raw data for some added conveniences.
Definition: hdicoreCrypt.h:157
Key(const Key &key_)
Constructs a Key object from another (copy constructor)
Key & operator=(const Key &rhs_)
Assigns one Key object to another.
friend 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.
friend 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...
std::string serialize() const
Serializes the key in a base-64 string; useful for transmitting the string to another party or writin...
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.
ByteVector bytes() const
Gets the raw bytes of the AES key.
int32_t length() const
Gets the size/length of the key in bits.
virtual ~Key()
Destructs a Key object.
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.
bool operator==(const Key &rhs_) const
Compares two Key objects for equality.
bool valid() const
Gets whether the object contains a valid key.
bool operator!=(const Key &rhs_) const
Compares two Key objects for inequality.
Wraps around a private RSA key's raw data for some added conveniences.
Definition: hdicoreCrypt.h:643
int32_t length() const
Gets the size/length of the key in bits.
PrivateKey & operator=(const PrivateKey &rhs_)
Assigns one PrivateKey object to another.
friend bool encryptWithPublicKey(const PublicKey &, const std::string &, std::string &)
Encrypts a string (or raw bytes stuffed into a string) with a public RSA key.
PrivateKey(const std::string &serializedKey_)
Constructs a PrivateKey object from a previous serialization of the key (using the serialize() method...
bool operator!=(const PrivateKey &rhs_) const
Compares two PrivateKey objects for inequality.
friend bool generateKeyPair(const int32_t, PrivateKey &, PublicKey &)
Generates a new RSA key pair of a given size/length.
friend bool decryptWithPrivateKey(const PrivateKey &, const std::string &, std::string &)
Decrypts a base-64 encoded string of cipher text (previously encrypted with the encryptWithPublicKey(...
friend bool decryptWithPublicKey(const PublicKey &, const std::string &, std::string &)
Decrypts a base-64 encoded string of cipher text (previously encrypted with the encryptWithPrivateKey...
bool operator==(const PrivateKey &rhs_) const
Compares two PrivateKey objects for equality.
bool valid() const
Gets whether the object contains a valid key.
std::string serialize() const
Serializes the private key in a base-64 string; useful for transmitting the string to another party (...
PrivateKey()
Constructs an empty PrivateKey object.
virtual ~PrivateKey()
Destructs a PrivateKey object.
PrivateKey(const PrivateKey &key_)
Constructs a PrivateKey object from another (copy constructor)
friend bool encryptWithPrivateKey(const PrivateKey &, const std::string &, std::string &)
Encrypts a string (or raw bytes stuffed into a string) with a private RSA key.
Wraps around a public RSA key's raw data for some added conveniences.
Definition: hdicoreCrypt.h:517
PublicKey(const std::string &serializedKey_)
Constructs a PublicKey object from a previous serialization of the key (using the serialize() method)
friend bool encryptWithPublicKey(const PublicKey &, const std::string &, std::string &)
Encrypts a string (or raw bytes stuffed into a string) with a public RSA key.
bool operator!=(const PublicKey &rhs_) const
Compares two PublicKey objects for inequality.
int32_t length() const
Gets the length of the key in bits.
PublicKey()
Constructs an empty PublicKey object.
bool valid() const
Gets whether the object contains a valid key.
PublicKey & operator=(const PublicKey &rhs_)
Assigns one PublicKey object to another.
friend bool generateKeyPair(const int32_t, PrivateKey &, PublicKey &)
Generates a new RSA key pair of a given size/length.
friend bool decryptWithPrivateKey(const PrivateKey &, const std::string &, std::string &)
Decrypts a base-64 encoded string of cipher text (previously encrypted with the encryptWithPublicKey(...
friend bool decryptWithPublicKey(const PublicKey &, const std::string &, std::string &)
Decrypts a base-64 encoded string of cipher text (previously encrypted with the encryptWithPrivateKey...
bool operator==(const PublicKey &rhs_) const
Compares two PublicKey objects for equality.
std::string serialize() const
Serializes the public key in a base-64 string; useful for transmitting the string to another party or...
PublicKey(const PublicKey &key_)
Constructs a PublicKey object from another (copy constructor)
friend bool encryptWithPrivateKey(const PrivateKey &, const std::string &, std::string &)
Encrypts a string (or raw bytes stuffed into a string) with a private RSA key.
virtual ~PublicKey()
Destructs a PublicKey object.
Header file for a wide variety of necessary typedefs, enums, and forwards declarations.
bool decrypt(const Key &key_, const InitVector &iv_, const std::string &b64Cipher_, std::string &data__)
Decrypts a base-64 encoded string of cipher text (previously encrypted with the encrypt() function or...
bool encrypt(const Key &key_, const InitVector &iv_, const std::string &data_, std::string &b64Cipher__)
Encrypts a string (or raw bytes stuffed into a string) with an AES key.
bool decryptWithPublicKey(const PublicKey &key_, const std::string &b64Cipher_, std::string &data__)
Decrypts a base-64 encoded string of cipher text (previously encrypted with the encryptWithPrivateKey...
bool generateKeyPair(const int32_t size_, PrivateKey &privKey__, PublicKey &pubKey__)
Generates a new RSA key pair of a given size/length.
bool encryptWithPublicKey(const PublicKey &key_, const std::string &data_, std::string &b64Cipher__)
Encrypts a string (or raw bytes stuffed into a string) with a public RSA key.
bool decryptWithPrivateKey(const PrivateKey &key_, const std::string &b64Cipher_, std::string &data__)
Decrypts a base-64 encoded string of cipher text (previously encrypted with the encryptWithPublicKey(...
bool encryptWithPrivateKey(const PrivateKey &key_, const std::string &data_, std::string &b64Cipher__)
Encrypts a string (or raw bytes stuffed into a string) with a private RSA key.
std::string base64Encode(const std::string &plain_)
Base-64 encodes any data stuffed into a string.
std::string sha1(const std::string &str_)
Generates an SHA1 hash of a given source string.
std::string sha2_256(const std::string &str_)
Generates an SHA2-256 hash of a given source string.
std::string rot13(const std::string &str_)
Performs a rot-13 cipher (Caeser's cipher) on a string.
std::string md5(const std::string &str_)
Generates an MD5 hash of a given source string.
std::string base64Decode(const std::string &cipher_)
Decodes any data previously base-64 encoded.
std::string sha2_512(const std::string &str_)
Generates an SHA2-512 hash of a given source string.