On Tuesday, January 3, 2017 at 11:41:44 PM UTC-5, c++programmer wrote: > > I've been having an issue where decrypted data is left in RAM once I'm > done with it. I've traced the problem to decrypting the data to a > std::string. So I've started to move all my code over to use SecByteBlock. > > - I wasn't able to figure out how to create a sink that put the encrypted > data so I patched cryptolib with this: > https://www.cryptopp.com/wiki/Secbyteblocksink > This will come back and haunt me next time I update cryptopp so I was > wondering if there is a better way to do it that I've missed? > m_encrypter=new DefaultEncryptorWithMAC(blockPwd,blockPwdlen,new > SecByteBlockSink(m_encrypteddata)); > > - I can't find any examples of decrypting data into a SecByteBlock or > other similar device. std::string has no guarantees of destroying its data > afterwards so decrypted data is leaked out from the program. > > (Simplified version of what I'm currently doing butI need to put it into > something other than a string) > string decodedData; > Filter *decrypt=new > StringSource(m_encrypteddata.BytePtr(),m_encrypteddata.size(),true,new > DefaultDecryptorWithMAC(blockPwd,blockPwdlen, new StringSink(decodedData))); >
Can you use a ByteQueue? A ByteQueue is a BufferedTransformation, so it can participate in a pipeline. If so, then it would look similar to: #include "queue.h" #include "default.h" using namespace CryptoPP; #include <iostream> #include <string> using namespace std; int main(int argc, char* argv[]) { string password = "super secret password"; string message = "Attack at dawn!"; DefaultEncryptorWithMAC encryptor(password.c_str()); encryptor.Put((const byte*)message.data(), message.length()); encryptor.MessageEnd(); SecByteBlock encrypted(encryptor.MaxRetrievable()); encryptor.Get(encrypted, encrypted.size()); encryptor.MessageEnd(); ByteQueue decrypted; DefaultDecryptorWithMAC decryptor(password.c_str(), new Redirector(decrypted)); decryptor.Put(encrypted, encrypted.size()); decryptor.MessageEnd(); string recovered; recovered.resize(decrypted.MaxRetrievable()); decrypted.Get((byte*)&recovered[0], recovered.length()); cout << recovered << endl; return 0; } Jeff -- -- You received this message because you are subscribed to the "Crypto++ Users" Google Group. To unsubscribe, send an email to cryptopp-users-unsubscr...@googlegroups.com. More information about Crypto++ and this group is available at http://www.cryptopp.com. --- You received this message because you are subscribed to the Google Groups "Crypto++ Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.