Skip to content

C++ Encrypt variables in memory. Secured Pointer Template Class to encrypt/decrypt the DATA of std::string,std::wstring,CString or user defined classes/structs in memory

License

Notifications You must be signed in to change notification settings

teenccu/SecurePtr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

Encrypt variables in memory using C++ SecurePtr template class

Windows C++ Secured Pointer Template Class to autpmatically encrypt/decrypt the DATA of std::string,std::wstring,CString or user defined classes/structs etc. in memory by using inbuilt Windows DPAPI. However, it is possible to use the same concept for other systems like Linux by changing the crypto implementation

WARNING
This version does not take care of deep copying of class data.
Constructors and destructors are not called contructor and when securedptr is created/destroyed.
Any object inheritance is not properly maintained inside SecuredPtr.
Class objects can be recreated with the data recovered from SecuredPtr by calling construtors/destructors

Examples: SecuredPtr varaibles will keep the data of Type T in memory encrypted till its scope.
Like other smart pointers outside of the scope the SecuredPtr will destroy its internal data.

Accessing of member functions of member properties are allowed which is atomatically decrypt and encypt data in back-end

SecuredPtr< CString > teststring = CString("Hellohow");//Inside teststring the value is encrypted however all member accesses will work
teststring->MakeUpper(); // Call CString method
if(teststring == "HELLOHOW") //True

class struexmp {public :int a;string c;double d;}; // create a structure

struexmp var{ 15,"hello",14.01 };
SecuredPtr< struexmp > structexample2; // create structure variable
structexample2 = var; //Inside structexample2 value is encrypted however member accesses/changes are allowed
if(structexample2->c=="hello") // True

Dereferencing of value with unencrypted data using pointer operator from SecuredPtr
SecuredPtr< std::wstring > hh;
hh= L"hello";
std::wstring h1 = *hh; //h1 value is string with unencypted copy of data however hh keeps the copy of encrypted value till its scope

Very Important Please note as accessing member properties with '->' is costly as it decrypts and encrypts data on each access. It is ok when there are not too many accesses. When too many accesses it is recommended to use '&' to improve perfomance. However data inside SecuredPtr stays uncrypted till all the variables created by '&' goes out of scope. If these vaiables are shared again and all is out of scope the SecuredPtr variable will re-encrypt the data automatically.

Getting the pointer of unencrypted data using '&'(like pointers) SecuredPtr< struexmp > structexample2; //class struexmp like above
struexmp var{ 15,"hello",14.01 };
structexample2 = var;
{ //Create a scope
auto uncr = &structexample2; // structexample2 now have its internal data unecrypted and uncr as well
uncr->a = 17; //Change the first member
} //Going out of scope for uncr so uncr is destroyed now
//here structexample2 is encypted again
if(structexample2->a == 17) //True

Additionaly comparison operators, copy constructor work normally like other variables
Debug Value Display
#define _ShowDebugVal to show decrypted data in SecuredPtr for debugging purpose

About

C++ Encrypt variables in memory. Secured Pointer Template Class to encrypt/decrypt the DATA of std::string,std::wstring,CString or user defined classes/structs in memory

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages