Cross-platform problems

42 views
Skip to first unread message

Allan

unread,
May 10, 2016, 5:20:09 PM5/10/16
to cryptop...@googlegroups.com
I'm experiencing the exact same issue as:
http://comments.gmane.org/gmane.comp.encryption.cryptopp/2518

In this case, because I'm using DefaultEncryptorWithMAC with AES-256, I
get the exception "cannot decrypt message with this passphrase".
Generally,

----
std::string pdata;
std::ifstream ifs(sFilePlainText.c_str(), std::ifstream::binary);
std::ofstream ofs(sFileCipherText.c_str(), std::ofstream::binary);

m_enc = new Base64Encoder(NULL, true, 72);
AlgorithmParameters params = MakeParameters(Name::Separator(),
ConstByteArrayParameter("\n#"))
(Name::InsertLineBreaks(), true);
m_enc->IsolatedInitialize(params);
m_enc->Attach(new FileSink(ofs));
m_dem = new DefaultEncryptorWithMAC((byte*)password.data(),
password.size(), new Redirector(*m_enc));

// ... ifs >> pdata ...

m_dem->Put2((byte const*)pdata.data(), pdata.size(), 0, true);
m_dem->MessageEnd();

----

Encrypts/decrypts fine within each OS. The encrypted output for each OS
is different - Ubuntu's is smaller in size. I've gone at this all day.
Any help is appreciated.

Jeffrey Walton

unread,
May 15, 2016, 11:10:34 AM5/15/16
to Crypto++ Users

C++ fstreams can be problematic, even in binary mode. I seem to recall there was some unwanted conversions going on, and I had to disable the processing of whitespace for a time. Microsoft fstreams can be problematic, especially when they are wide streams.

First, ensure the fstreams are behaving as expected. Second, verify the password is expected. There's a difference between encodings, code pages and UTF-8. For password presentation to a lower lay like crypto, always use UTF-8 because its portable across all platforms.

Jeff

Allan

unread,
May 16, 2016, 11:55:03 AM5/16/16
to cryptop...@googlegroups.com
Jeffrey Walton <noloader <at> gmail.com> writes:

>
>
> C++ fstreams can be problematic, even in binary mode. I seem to recall
there was some unwanted conversions going on, and I had to disable the
processing of whitespace for a time. Microsoft fstreams can be
problematic, especially when they are wide streams.First, ensure the
fstreams are behaving as expected. Second, verify the password is
expected. There's a difference between encodings, code pages and UTF-8.
For password presentation to a lower lay like crypto, always use UTF-8
because its portable across all platforms.Jeff
>
>
>
>
>

Thanks for the help. I posted a modified crypto example at
http://stackoverflow.com/q/37163270/5099723. It looks like fstream is ok.
Could you offer a simple cross platform example? Cheers.



aeh

unread,
Sep 7, 2018, 2:59:58 PM9/7/18
to Crypto++ Users
Just wondering if there was any headway with cross-platform, or any successful examples I can reproduce?

Jeffrey Walton

unread,
Sep 7, 2018, 3:09:08 PM9/7/18
to Crypto++ Users


On Friday, September 7, 2018 at 2:59:58 PM UTC-4, aeh wrote:
Just wondering if there was any headway with cross-platform, or any successful examples I can reproduce?

There are lots of examples of using the library in the library's test files. The test files are listed at https://github.com/weidai11/cryptopp/blob/master/GNUmakefile#L812 .

You can verify the build of the library with 'cryptest.exe v'. The wiki also has lots of examples.

Otherwise provide an example of your problem on GitHub and we can take a look at it.

Jeff
Message has been deleted
Message has been deleted

Jeffrey Walton

unread,
Sep 8, 2018, 1:10:55 PM9/8/18
to Crypto++ Users


On Tuesday, May 10, 2016 at 5:20:09 PM UTC-4, aeh wrote:
I'm experiencing the exact same issue as:
http://comments.gmane.org/gmane.comp.encryption.cryptopp/2518

In this case, because I'm using DefaultEncryptorWithMAC with AES-256, I
get the exception "cannot decrypt message with this passphrase".

We added a binary decryption test at https://github.com/weidai11/cryptopp/commit/4ff34ee32938 . It tested OK on Windows 8.1, Solaris 11 and Fedora 28.

Please post a reproducer on GitHub.

Jeff
Reply all
Reply to author
Forward
0 new messages