Hot Door CORE  0.7.1
Adobe® Illustrator® Plug-in Library
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 
14 namespace hdi
15 {
16  namespace plugin
17  {
18  class AESKey;
19  class AESInitializationVector;
20  class PublicRSAKey;
21  class PrivateRSAKey;
22  }
23 
24  namespace core
25  {
26  namespace crypt
27  {
38  std::string rot13(const std::string& str_);
39 
49  std::string md5(const std::string& str_);
50 
60  std::string sha1(const std::string& str_);
61 
71  std::string sha2_256(const std::string& str_);
72 
82  std::string sha2_512(const std::string& str_);
83 
92  std::string base64Encode(const std::string& plain_);
93 
102  std::string base64Decode(const std::string& cipher_);
103 
104  namespace aes
105  {
106  class Key;
107  class InitVector;
108  }
109 
110  namespace aes
111  {
112  typedef std::vector<byte> ByteVector;
113 
130  bool encrypt(const Key& key_, const InitVector& iv_, const std::string& data_, std::string& b64Cipher__);
131 
145  bool decrypt(const Key& key_, const InitVector& iv_, const std::string& b64Cipher_, std::string& data__);
146 
150  class Key
151  {
152  public:
160  Key(const Key& key_);
161 
170  Key(const std::string& serializedKey_);
171 
179  Key(const int32_t size_);
180 
190  Key(const int32_t size_, const ByteVector& bytes_);
191 
197  virtual ~Key();
198 
208  Key& operator=(const Key& rhs_);
209 
217  bool valid() const;
218 
226  int32_t length() const;
227 
235  ByteVector bytes() const;
236 
249  std::string serialize() const;
250 
259  bool operator==(const Key& rhs_) const;
260 
269  bool operator!=(const Key& rhs_) const;
270 
271 
272  private:
273  friend plugin::AESKey* __accessImpl(const Key&);
274 
275  friend bool encrypt(const Key&, const InitVector&, const std::string&, std::string&);
276  friend bool decrypt(const Key&, const InitVector&, const std::string&, std::string&);
277 
281  plugin::AESKey* __impl;
282 
288  Key();
289  };
290 
291  typedef std::auto_ptr<Key> KeyAP;
292 
297  {
298  public:
310  InitVector();
311 
319  InitVector(const InitVector& iv_);
320 
329  InitVector(const std::string& serializedIV_);
330 
336  virtual ~InitVector();
337 
348  InitVector& operator=(const InitVector& rhs_);
349 
357  ByteVector bytes() const;
358 
370  std::string serialize() const;
371 
380  bool operator==(const InitVector& rhs_) const;
381 
390  bool operator!=(const InitVector& rhs_) const;
391 
392 
393  private:
394  friend plugin::AESInitializationVector* __accessImpl(const InitVector&);
395 
396  friend bool encrypt(const Key&, const InitVector&, const std::string&, std::string&);
397  friend bool decrypt(const Key&, const InitVector&, const std::string&, std::string&);
398 
402  plugin::AESInitializationVector* __impl;
403  };
404 
405  typedef std::auto_ptr<InitVector> InitVectorAP;
406 
407  extern plugin::AESKey* __accessImpl(const Key&);
408  extern plugin::AESInitializationVector* __accessImpl(const InitVector&);
409  }
410 
411  namespace rsa
412  {
413  class PublicKey;
414  class PrivateKey;
415  }
416 
417  namespace rsa
418  {
431  bool generateKeyPair(const int32_t size_, PrivateKey& privKey__, PublicKey& pubKey__);
432 
448  bool encryptWithPublicKey(const PublicKey& key_, const std::string& data_, std::string& b64Cipher__);
449 
462  bool decryptWithPrivateKey(const PrivateKey& key_, const std::string& b64Cipher_, std::string& data__);
463 
484  bool encryptWithPrivateKey(const PrivateKey& key_, const std::string& data_, std::string& b64Cipher__);
485 
498  bool decryptWithPublicKey(const PublicKey& key_, const std::string& b64Cipher_, std::string& data__);
499 
503  class PublicKey
504  {
505  public:
517  PublicKey();
518 
526  PublicKey(const PublicKey& key_);
527 
536  PublicKey(const std::string& serializedKey_);
537 
543  virtual ~PublicKey();
544 
555  PublicKey& operator=(const PublicKey& rhs_);
556 
564  bool valid() const;
565 
573  int32_t length() const;
574 
586  std::string serialize() const;
587 
596  bool operator==(const PublicKey& rhs_) const;
597 
606  bool operator!=(const PublicKey& rhs_) const;
607 
608 
609  private:
610  friend bool generateKeyPair(const int32_t, PrivateKey&, PublicKey&);
611  friend bool encryptWithPublicKey(const PublicKey&, const std::string&, std::string&);
612  friend bool decryptWithPrivateKey(const PrivateKey&, const std::string&, std::string&);
613  friend bool encryptWithPrivateKey(const PrivateKey&, const std::string&, std::string&);
614  friend bool decryptWithPublicKey(const PublicKey&, const std::string&, std::string&);
615 
619  plugin::PublicRSAKey* __impl;
620  };
621 
622  typedef std::auto_ptr<PublicKey> PublicKeyAP;
623 
628  {
629  public:
641  PrivateKey();
642 
650  PrivateKey(const PrivateKey& key_);
651 
660  PrivateKey(const std::string& serializedKey_);
661 
667  virtual ~PrivateKey();
668 
679  PrivateKey& operator=(const PrivateKey& rhs_);
680 
688  bool valid() const;
689 
697  int32_t length() const;
698 
711  std::string serialize() const;
712 
721  bool operator==(const PrivateKey& rhs_) const;
722 
731  bool operator!=(const PrivateKey& rhs_) const;
732 
733 
734  private:
735  friend bool generateKeyPair(const int32_t, PrivateKey&, PublicKey&);
736  friend bool encryptWithPublicKey(const PublicKey&, const std::string&, std::string&);
737  friend bool decryptWithPrivateKey(const PrivateKey&, const std::string&, std::string&);
738  friend bool encryptWithPrivateKey(const PrivateKey&, const std::string&, std::string&);
739  friend bool decryptWithPublicKey(const PublicKey&, const std::string&, std::string&);
740 
744  plugin::PrivateRSAKey* __impl;
745  };
746 
747  typedef std::auto_ptr<PrivateKey> PrivateKeyAP;
748  }
749  }
750  }
751 }
752 
753 #endif
754 // __HDI_CORE_CRYPT__
std::string sha1(const std::string &str_)
Generates an SHA1 hash of a given source string.
std::string md5(const std::string &str_)
Generates an MD5 hash of a given source string.
std::string sha2_512(const std::string &str_)
Generates an SHA2-512 hash of a given source string.
std::string base64Encode(const std::string &plain_)
Base-64 encodes any data stuffed into a string.
std::string rot13(const std::string &str_)
Performs a rot-13 cipher (Caeser&#39;s cipher) on a string.
Wraps around an AES key&#39;s raw data for some added conveniences.
Definition: hdicoreCrypt.h:150
Header file for a wide variety of necessary typedefs, enums, and forwards declarations.
Definition: hdicoreaiArray.h:12
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...
std::string sha2_256(const std::string &str_)
Generates an SHA2-256 hash of a given source string.
std::string base64Decode(const std::string &cipher_)
Decodes any data previously base-64 encoded.
Wraps around an AES initialization vector&#39;s raw data for some added conveniences. ...
Definition: hdicoreCrypt.h:296
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.
Wraps around a private RSA key&#39;s raw data for some added conveniences.
Definition: hdicoreCrypt.h:627
Wraps around a public RSA key&#39;s raw data for some added conveniences.
Definition: hdicoreCrypt.h:503