Key.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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
  36. //! copying
  37. //! \param daten The new byte array
  38. //! \param length The length of the array
  39. DLLEXPORT void setBytesZ(char* daten, int length);
  40. //! Sets all bytes of the array to a specific value
  41. //! \param c The value to set the bytes to
  42. DLLEXPORT void fill(const char c);
  43. //! Sets a specific number of bytes of the array to a specific value
  44. //! \param c The value to set the bytes to
  45. //! \param len The number of bytes to set
  46. DLLEXPORT void fill(const char c, int len);
  47. //! Sets a specific section of bytes of the array to a specific
  48. //! value
  49. //! \param c The value to set the bytes to
  50. //! \param beg The start position of the section to set
  51. //! \param end The end position of the section to set (exclusive)
  52. DLLEXPORT void fill(const char c, int beg, int end);
  53. //! Copies specific bytes into the array
  54. //! \param c The bytes to copy
  55. //! \param cLength The number of bytes to set
  56. DLLEXPORT void fill(const char* c, int cLength);
  57. //! Sets a specific byte to a value
  58. //! \param c The value to set the byte to
  59. //! \param pos The position of the byte in the array
  60. DLLEXPORT void set(const char c, int pos);
  61. //! Returns the length of the array
  62. DLLEXPORT int getLength() const;
  63. //! Returns the array of bytes
  64. DLLEXPORT char* getBytes() const;
  65. };
  66. //! Can encrypt and decrypt byte sequences with specific keys
  67. class Key : public virtual ReferenceCounter
  68. {
  69. private:
  70. unsigned char* key;
  71. int length;
  72. int pos;
  73. public:
  74. //! Creates an empty object
  75. DLLEXPORT Key();
  76. //! Creates a new object with a key
  77. //! \param s The key to use for encryption and decryption
  78. //! \param length The length of the key
  79. DLLEXPORT Key(const char* s, int length);
  80. //! Deletes the object
  81. DLLEXPORT ~Key();
  82. //! Sets the position in the key where encryption and decryption
  83. //! should begin \param p The position in the key
  84. DLLEXPORT void setPos(__int64 p);
  85. //! Sets the key to use for encryption and decryption
  86. //! \param s The key \param length The length of the key
  87. DLLEXPORT void setKey(const char* s, int length);
  88. //! Encrypts a byte array with the set key
  89. //! \param daten The byte array to encrypt. Modified by the function
  90. DLLEXPORT void encode(Bytes* daten);
  91. //! Decrypts a byte array with the set key
  92. //! \param daten The byte array to decrypt. Modified by the function
  93. DLLEXPORT void decode(Bytes* daten);
  94. };
  95. } // namespace Encryption
  96. } // namespace Framework
  97. #endif