string.hHeader
Header file defining the string
class for secure encrypted string management. More...
Detailed Description
The string
class extends std::vector<char32_t>
to provide secure handling of encrypted strings. It ensures that sensitive data is encrypted during storage and decrypted only when accessed, offering features such as automatic memory management, safe destruction, and conversion operators for easy integration with standard C++ string types.
Key Features:
Encryption and Decryption :
The
string
class encrypts the string data upon storage and decrypts it when accessed.It uses a secure encryption key (
key_
) to ensure that the data is protected from unauthorized access.The decryption process is automatically handled when the string is accessed via conversion operators or index operations.
Hashing :
The class computes and stores a hash value (
hash_
) for the string, which can be used for quick comparisons, integrity checks, or as a unique identifier for the string.The hash is calculated based on the string's content, ensuring that even small changes in the string result in a different hash.
Conversion Operators :
The class provides conversion operators to
std::string
,std::wstring
, andstd::u32string
, allowing easy integration with standard C++ string types.These operators automatically decrypt the string before converting it, ensuring that the decrypted data is returned in the appropriate format.
Safe Destruction :
- The destructor securely erases the encryption key and string data from memory, preventing any residual data from being recovered after the string object is destroyed.
Example Usage:
int
In this example, encryptedString
is stored in an encrypted form, and when accessed, it is automatically decrypted and converted to the desired string format.
Security Considerations:
The
string
class provides a high level of security for sensitive data by ensuring that the string is never stored in plaintext in memory.The encryption key is generated randomly for each instance, and the hash value ensures data integrity and uniqueness.
While the class offers strong protection, it should be used as part of a broader security strategy, including other measures such as secure key management and data access control.