Key.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef Key_H
  2. #define Key_H
  3. #include "OperatingSystem.h"
  4. #include "ReferenceCounter.h"
  5. namespace Framework
  6. {
  7. namespace Encryption
  8. {
  9. //! Stores an array of bytes
  10. class Bytes : public virtual ReferenceCounter
  11. {
  12. private:
  13. char* bytes;
  14. bool del;
  15. int length;
  16. public:
  17. //! Creates an empty byte array
  18. DLLEXPORT Bytes();
  19. //! Creates a new byte array with a specific length
  20. //! \param length The length of the array
  21. DLLEXPORT Bytes(int length);
  22. //! Creates a new byte array by copying the bytes
  23. //! \param daten The bytes to copy
  24. //! \param length The number of bytes to copy
  25. DLLEXPORT Bytes(const char* daten, int length);
  26. //! Deletes the array
  27. DLLEXPORT ~Bytes();
  28. //! Fills the byte array by copying the bytes
  29. //! \param daten The bytes to copy
  30. DLLEXPORT void setBytes(const char* daten);
  31. //! Deletes the array and creates a new one
  32. //! \param daten The bytes to copy
  33. //! \param length The length of the array
  34. DLLEXPORT void setBytes(const char* daten, int length);
  35. //! Deletes the array and takes ownership of the given one without copying
  36. //! \param daten The new byte array
  37. //! \param length The length of the array
  38. DLLEXPORT void setBytesZ(char* daten, int length);
  39. //! Sets all bytes of the array to a specific value
  40. //! \param c The value to set the bytes to
  41. DLLEXPORT void fill(const char c);
  42. //! Sets a specific number of bytes of the array to a specific value
  43. //! \param c The value to set the bytes to
  44. //! \param len The number of bytes to set
  45. DLLEXPORT void fill(const char c, int len);
  46. //! Sets a specific section of bytes of the array to a specific value
  47. //! \param c The value to set the bytes to
  48. //! \param beg The start position of the section to set
  49. //! \param end The end position of the section to set (exclusive)
  50. DLLEXPORT void fill(const char c, int beg, int end);
  51. //! Copies specific bytes into the array
  52. //! \param c The bytes to copy
  53. //! \param cLength The number of bytes to set
  54. DLLEXPORT void fill(const char* c, int cLength);
  55. //! Sets a specific byte to a value
  56. //! \param c The value to set the byte to
  57. //! \param pos The position of the byte in the array
  58. DLLEXPORT void set(const char c, int pos);
  59. //! Returns the length of the array
  60. DLLEXPORT int getLength() const;
  61. //! Returns the array of bytes
  62. DLLEXPORT char* getBytes() const;
  63. };
  64. //! Can encrypt and decrypt byte sequences with specific keys
  65. class Key : public virtual ReferenceCounter
  66. {
  67. private:
  68. unsigned char* key;
  69. int length;
  70. int pos;
  71. public:
  72. //! Creates an empty object
  73. DLLEXPORT Key();
  74. //! Creates a new object with a key
  75. //! \param s The key to use for encryption and decryption
  76. //! \param length The length of the key
  77. DLLEXPORT Key(const char* s, int length);
  78. //! Deletes the object
  79. DLLEXPORT ~Key();
  80. //! Sets the position in the key where encryption and decryption
  81. //! should begin \param p The position in the key
  82. DLLEXPORT void setPos(__int64 p);
  83. //! Sets the key to use for encryption and decryption
  84. //! \param s The key \param length The length of the key
  85. DLLEXPORT void setKey(const char* s, int length);
  86. //! Encrypts a byte array with the set key
  87. //! \param daten The byte array to encrypt. Modified by the function
  88. DLLEXPORT void encode2(Bytes* daten);
  89. //! Decrypts a byte array with the set key
  90. //! \param daten The byte array to decrypt. Modified by the function
  91. DLLEXPORT void decode2(Bytes* daten);
  92. };
  93. } // namespace Encryption
  94. } // namespace Framework
  95. #endif