Hot Door CORE  0.7.0
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 sha1(const std::string& str_);
50 
59  std::string base64Encode(const std::string& plain_);
60 
69  std::string base64Decode(const std::string& cipher_);
70 
71  namespace aes
72  {
73  class Key;
74  class InitVector;
75  }
76 
77  namespace aes
78  {
79  typedef std::vector<byte> ByteVector;
80 
97  bool encrypt(const Key& key_, const InitVector& iv_, const std::string& data_, std::string& b64Cipher__);
98 
112  bool decrypt(const Key& key_, const InitVector& iv_, const std::string& b64Cipher_, std::string& data__);
113 
117  class Key
118  {
119  public:
127  Key(const Key& key_);
128 
137  Key(const std::string& serializedKey_);
138 
146  Key(const int32_t size_);
147 
157  Key(const int32_t size_, const ByteVector& bytes_);
158 
164  virtual ~Key();
165 
175  Key& operator=(const Key& rhs_);
176 
184  bool valid() const;
185 
193  int32_t length() const;
194 
202  ByteVector bytes() const;
203 
216  std::string serialize() const;
217 
226  bool operator==(const Key& rhs_) const;
227 
236  bool operator!=(const Key& rhs_) const;
237 
238 
239  private:
240  friend plugin::AESKey* __accessImpl(const Key&);
241 
242  friend bool encrypt(const Key&, const InitVector&, const std::string&, std::string&);
243  friend bool decrypt(const Key&, const InitVector&, const std::string&, std::string&);
244 
248  plugin::AESKey* __impl;
249 
255  Key();
256  };
257 
258  typedef std::auto_ptr<Key> KeyAP;
259 
264  {
265  public:
277  InitVector();
278 
286  InitVector(const InitVector& iv_);
287 
296  InitVector(const std::string& serializedIV_);
297 
303  virtual ~InitVector();
304 
315  InitVector& operator=(const InitVector& rhs_);
316 
324  ByteVector bytes() const;
325 
337  std::string serialize() const;
338 
347  bool operator==(const InitVector& rhs_) const;
348 
357  bool operator!=(const InitVector& rhs_) const;
358 
359 
360  private:
361  friend plugin::AESInitializationVector* __accessImpl(const InitVector&);
362 
363  friend bool encrypt(const Key&, const InitVector&, const std::string&, std::string&);
364  friend bool decrypt(const Key&, const InitVector&, const std::string&, std::string&);
365 
369  plugin::AESInitializationVector* __impl;
370  };
371 
372  typedef std::auto_ptr<InitVector> InitVectorAP;
373 
374  extern plugin::AESKey* __accessImpl(const Key&);
375  extern plugin::AESInitializationVector* __accessImpl(const InitVector&);
376  }
377 
378  namespace rsa
379  {
380  class PublicKey;
381  class PrivateKey;
382  }
383 
384  namespace rsa
385  {
398  bool generateKeyPair(const int32_t size_, PrivateKey& privKey__, PublicKey& pubKey__);
399 
415  bool encryptWithPublicKey(const PublicKey& key_, const std::string& data_, std::string& b64Cipher__);
416 
429  bool decryptWithPrivateKey(const PrivateKey& key_, const std::string& b64Cipher_, std::string& data__);
430 
451  bool encryptWithPrivateKey(const PrivateKey& key_, const std::string& data_, std::string& b64Cipher__);
452 
465  bool decryptWithPublicKey(const PublicKey& key_, const std::string& b64Cipher_, std::string& data__);
466 
470  class PublicKey
471  {
472  public:
484  PublicKey();
485 
493  PublicKey(const PublicKey& key_);
494 
503  PublicKey(const std::string& serializedKey_);
504 
510  virtual ~PublicKey();
511 
522  PublicKey& operator=(const PublicKey& rhs_);
523 
531  bool valid() const;
532 
540  int32_t length() const;
541 
553  std::string serialize() const;
554 
563  bool operator==(const PublicKey& rhs_) const;
564 
573  bool operator!=(const PublicKey& rhs_) const;
574 
575 
576  private:
577  friend bool generateKeyPair(const int32_t, PrivateKey&, PublicKey&);
578  friend bool encryptWithPublicKey(const PublicKey&, const std::string&, std::string&);
579  friend bool decryptWithPrivateKey(const PrivateKey&, const std::string&, std::string&);
580  friend bool encryptWithPrivateKey(const PrivateKey&, const std::string&, std::string&);
581  friend bool decryptWithPublicKey(const PublicKey&, const std::string&, std::string&);
582 
586  plugin::PublicRSAKey* __impl;
587  };
588 
589  typedef std::auto_ptr<PublicKey> PublicKeyAP;
590 
595  {
596  public:
608  PrivateKey();
609 
617  PrivateKey(const PrivateKey& key_);
618 
627  PrivateKey(const std::string& serializedKey_);
628 
634  virtual ~PrivateKey();
635 
646  PrivateKey& operator=(const PrivateKey& rhs_);
647 
655  bool valid() const;
656 
664  int32_t length() const;
665 
678  std::string serialize() const;
679 
688  bool operator==(const PrivateKey& rhs_) const;
689 
698  bool operator!=(const PrivateKey& rhs_) const;
699 
700 
701  private:
702  friend bool generateKeyPair(const int32_t, PrivateKey&, PublicKey&);
703  friend bool encryptWithPublicKey(const PublicKey&, const std::string&, std::string&);
704  friend bool decryptWithPrivateKey(const PrivateKey&, const std::string&, std::string&);
705  friend bool encryptWithPrivateKey(const PrivateKey&, const std::string&, std::string&);
706  friend bool decryptWithPublicKey(const PublicKey&, const std::string&, std::string&);
707 
711  plugin::PrivateRSAKey* __impl;
712  };
713 
714  typedef std::auto_ptr<PrivateKey> PrivateKeyAP;
715  }
716  }
717  }
718 }
719 
720 #endif
721 // __HDI_CORE_CRYPT__
InitVector & operator=(const InitVector &rhs_)
Assigns one InitVector object to another.
int32_t length() const
Gets the size/length of the key in bits.
std::string serialize() const
Serializes the initialization vector in a base-64 string; useful for transmitting the string to anoth...
std::string serialize() const
Serializes the private key in a base-64 string; useful for transmitting the string to another party (...
PublicKey & operator=(const PublicKey &rhs_)
Assigns one PublicKey object to another.
bool operator==(const Key &rhs_) const
Compares two Key objects for equality.
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.
PrivateKey & operator=(const PrivateKey &rhs_)
Assigns one PrivateKey object to another.
friend bool decryptWithPrivateKey(const PrivateKey &, const std::string &, std::string &)
Decrypts a base-64 encoded string of cipher text (previously encrypted with the encryptWithPublicKey(...
bool operator!=(const InitVector &rhs_) const
Compares two InitVector objects for inequality.
Wraps around an AES key's raw data for some added conveniences.
Definition: hdicoreCrypt.h:117
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(...
std::string serialize() const
Serializes the public key in a base-64 string; useful for transmitting the string to another party or...
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...
Header file for a wide variety of necessary typedefs, enums, and forwards declarations.
friend bool decryptWithPublicKey(const PublicKey &, const std::string &, std::string &)
Decrypts a base-64 encoded string of cipher text (previously encrypted with the encryptWithPrivateKey...
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 valid() const
Gets whether the object contains a valid key.
Key & operator=(const Key &rhs_)
Assigns one Key object to another.
friend bool decryptWithPublicKey(const PublicKey &, const std::string &, std::string &)
Decrypts a base-64 encoded string of cipher text (previously encrypted with the encryptWithPrivateKey...
int32_t length() const
Gets the length of the key in bits.
bool operator!=(const PrivateKey &rhs_) const
Compares two PrivateKey objects for inequality.
bool valid() const
Gets whether the object contains a valid key.
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.
Definition: hdicoreaiArray.h:12
virtual ~PublicKey()
Destructs a PublicKey object.
friend bool generateKeyPair(const int32_t, PrivateKey &, PublicKey &)
Generates a new RSA key pair of a given size/length.
bool operator!=(const PublicKey &rhs_) const
Compares two PublicKey objects for inequality.
bool operator==(const PrivateKey &rhs_) const
Compares two PrivateKey objects for equality.
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.
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.
ByteVector bytes() const
Gets the raw bytes of the AES initialization vector.
virtual ~Key()
Destructs a Key object.
bool operator!=(const Key &rhs_) const
Compares two Key objects for inequality.
ByteVector bytes() const
Gets the raw bytes of the AES key.
virtual ~PrivateKey()
Destructs a PrivateKey object.
PublicKey()
Constructs an empty PublicKey object.
bool valid() const
Gets whether the object contains a valid key.
bool operator==(const PublicKey &rhs_) const
Compares two PublicKey objects for equality.
std::string serialize() const
Serializes the key in a base-64 string; useful for transmitting the string to another party or writin...
int32_t length() const
Gets the size/length of the key in bits.
virtual ~InitVector()
Destructs an InitVector object.
bool operator==(const InitVector &rhs_) const
Compares two InitVector objects for equality.
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 an AES initialization vector's raw data for some added conveniences. ...
Definition: hdicoreCrypt.h:263
PrivateKey()
Constructs an empty PrivateKey object.
Wraps around a private RSA key's raw data for some added conveniences.
Definition: hdicoreCrypt.h:594
Wraps around a public RSA key's raw data for some added conveniences.
Definition: hdicoreCrypt.h:470
InitVector()
Constructs a new(ly generated) InitVector object for some random initialization vector values...
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.