On Friday, July 12, 2013 5:14:29 PM UTC-4, Stefano Mtangoo wrote:
>
> ... 

Code:
>
> wxString DecryptString(const wxString& instr, const wxString& passPhrase)
> {
>     std::string outstr;
>     const char* charToDecrypt = instr.ToStdString().c_str();
>     const char* pass = passPhrase.ToStdString().c_str();
>
>     try
>     {
>         CryptoPP::HexDecoder decryptor(new 
> CryptoPP::DefaultDecryptorWithMAC(pass, new CryptoPP::StringSink(outstr)));
>         decryptor.Put((byte *)charToDecrypt, strlen(charToDecrypt));
>         decryptor.MessageEnd();
>     }
>     catch (CryptoPP::Exception& e)
>     {
>         wxPuts(e.what());
>     }
>
>     return wxString(outstr);
> }
>

    const char* charToDecrypt = instr.ToStdString().c_str();
    const char* pass = passPhrase.ToStdString().c_str();

With all things being equal, there's likely an embedded NULL in the 
charToDecrypt c-string. Don't convert it to a c-style string.

I've never worked with WX, but the following would probably be a step in 
the right direction:

    const std:string& encrypted = instr.ToStdString();
    const std:string& pass = passPhrase.ToStdString();

And then, perhaps something like:

    // 
http://www.cryptopp.com/docs/ref/class_default_decryptor_with_m_a_c.html
    CryptoPP::DefaultDecryptorWithMAC decryptor(pass.data(), pass.size(), 
new CryptoPP::StringSink(outstr)));
    decryptor.Put((byte *)encrypted.data(), encrypted.size());
    decryptor.MessageEnd();

Or:

    StringSource ss(
        encrypted, true,
        new DefaultDecryptorWithMAC decryptor(
            pass.data(), pass.size(),
            new CryptoPP::StringSink(outstr)
        )
    );

Jeff

-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to