unicode file name

63 views
Skip to first unread message

fa

unread,
Jun 9, 2023, 11:21:09 AM6/9/23
to Crypto++ Users
Hello

When I try to calculate the Hash of the file with Unicode characters, it shows the following errors:

terminate called after throwing an instance of 'CryptoPP::FileStore::OpenErr'
what():  FileStore: error opening file for reading: C:/é “/テキストファイル.txt

I compiled Crypto++ with msys2 [minGW] in windows and use it with Qt.
I tried many methods that others explained but none of them worked for me. I also use boost::nowide, but nothing changed.

Jeffrey Walton

unread,
Jun 10, 2023, 11:53:01 AM6/10/23
to cryptop...@googlegroups.com
On Fri, Jun 9, 2023 at 11:21 AM fa <fery...@gmail.com> wrote:
>
> Hello
>
> When I try to calculate the Hash of the file with Unicode characters, it shows the following errors:
>
> terminate called after throwing an instance of 'CryptoPP::FileStore::OpenErr'
> what(): FileStore: error opening file for reading: C:/é “/テキストファイル.txt

I believe that's coming from files.cpp and OpenErr,
https://github.com/weidai11/cryptopp/blob/master/files.cpp#L53 .

> I compiled Crypto++ with msys2 [minGW] in windows and use it with Qt.
> I tried many methods that others explained but none of them worked for me. I also use boost::nowide, but nothing changed.

Please provide a minimal example that demonstrates the problem.

Jeff

fa

unread,
Jun 15, 2023, 12:16:56 AM6/15/23
to cryptop...@googlegroups.com
I tried two methods:


1.


void CryptoHashes::makeFileHash(const QString &filePath)

{

FileSource f(filePath.toStdString().c_str(), true, new HashFilter(hash, new HexEncoder(new StringSink(digest))));

}



2.


void CryptoHashes::makeFileHash(const QString &filePath)

{

std::filesystem::path _path { std::filesystem::u8path(filePath.toStdString()) };

std::ifstream m_file(_path, std::ios::in);


FileSource f(m_file, true, new HashFilter(hash, new HexEncoder(new StringSink(digest))));

}



the only exception is that when I tried method 2, it always calculated hash of NULL, no matter which file I selected.

Jeffrey Walton

unread,
Jun 15, 2023, 5:14:41 AM6/15/23
to cryptop...@googlegroups.com
std::ifstream does not have a ctor that takes a std::filesystem::path.
See https://cplusplus.com/reference/fstream/ifstream/ifstream/ . It
looks like you need to do something like
https://stackoverflow.com/a/45401869 .

Jeff

coshvji cujmlqef

unread,
Jun 15, 2023, 9:00:32 AM6/15/23
to cryptop...@googlegroups.com
Can you try fast_io instead of iostream? fast_io always does codecvt itself instead of relying on crt. It also directly supports cryptopp's hash function

--
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-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cryptopp-users/CAH8yC8m09ompC0z8KH%3D7XFQs6nP%3D2vD8hbZpq5ZwF4Da%2BzJVCw%40mail.gmail.com.

fa

unread,
Jun 16, 2023, 1:08:56 AM6/16/23
to cryptop...@googlegroups.com
Thanks to Jeffrey Walton and coshvji cujmlqef

I tried both of your methods but they both print the following errors:

terminate called after throwing an instance of 'CryptoPP::FileStore::ReadErr'
what():  FileStore: error reading file

Jeffrey Walton

unread,
Jun 25, 2023, 2:02:53 PM6/25/23
to Crypto++ Users
Please provide a minimum reproducer with the steps to duplicate the problem.

Jeff

fa

unread,
Jul 7, 2023, 3:21:36 AM7/7/23
to cryptop...@googlegroups.com

Hi Jeffrey Walton


Sorry I answered late.


std::filesystem::path _path { std::filesystem::u8path(filePath.toStdString()) };

std::string _path_string { _path.u8string() };

std::ifstream m_file(_path_string, std::ios::in);

FileSource f(m_file, true, new HashFilter(hash, new HexEncoder(new StringSink(digest))));



ERROR:

One Sini

unread,
Jul 11, 2023, 11:47:32 AM7/11/23
to cryptop...@googlegroups.com

The error message you're encountering suggests that there's an issue with reading the file specified by _path_string in your code. The error is thrown by CryptoPP::FileStore, indicating a problem while trying to read the file.

Here are a few possible reasons for this error:

  1. Incorrect file path: Double-check that filePath.toStdString() returns the correct file path. Ensure that the file exists at that location and that you have read permissions.

  2. File permission issues: Make sure that the file you're trying to read has proper read permissions set. Check the file's permissions and adjust them if necessary.

  3. File not found: If the file specified by _path_string doesn't exist, you'll encounter this error. Verify that the file exists at the given path and that there are no typos in the file name or path.

  4. Insufficient privileges: If your program doesn't have sufficient privileges to access the file, you may encounter this error. Ensure that your program has the necessary permissions to read files from the specified location.

  5. Encoding issues: It's possible that the file you're trying to read contains data encoded in an incompatible format. Ensure that the file is in a readable format and that it's not corrupted or encoded in a way that the std::ifstream cannot handle.

To pinpoint the exact cause of the error, you can try adding some error handling and debugging statements to your code. For example, you can check if the file exists before attempting to read it using std::filesystem::exists(_path).

Here's an updated version of your code that includes some error handling:

cpp

std::filesystem::path _path{ std::filesystem::u8path(filePath.toStdString()) };
std::string _path_string{ _path.u8string() };

if (!std::filesystem::exists(_path)) {
    std::cerr << "File does not exist: " << _path_string << std::endl;
    // Handle the error accordingly
} else {
    std::ifstream m_file(_path_string, std::ios::in);
    if (!m_file) {
        std::cerr << "Failed to open file: " << _path_string << std::endl;
        // Handle the error accordingly
    } else {
        FileSource f(m_file, true, new HashFilter(hash, new HexEncoder(new StringSink(digest))));
        // Continue processing the file
    }
}

By using this updated code, you should be able to identify the specific issue causing the CryptoPP::FileStore::ReadErr error and handle it appropriately.


--
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-user...@googlegroups.com.

fa

unread,
Jul 28, 2023, 11:26:36 AM7/28/23
to cryptop...@googlegroups.com

Hi One Sini


Thanks for your reply, but my problem is not related to file permission or insufficient privileges. No errors occurred when I do this operation with English characters, but errors occur when I use UTF-8 characters. I think the Cryptopp library has a problem with UTF-8 characters.




Reply all
Reply to author
Forward
Message has been deleted
0 new messages