unicode file name

৫৩টি ভিউ
প্রথম অপঠিত মেসেজটিতে চলে আসুন

fa

পড়া হয়নি,
৯ জুন, ২০২৩, ১১:২১:০৯ AM৯/৬/২৩
প্রাপক 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

পড়া হয়নি,
১০ জুন, ২০২৩, ১১:৫৩:০১ AM১০/৬/২৩
প্রাপক 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

পড়া হয়নি,
১৫ জুন, ২০২৩, ১২:১৬:৫৬ AM১৫/৬/২৩
প্রাপক 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

পড়া হয়নি,
১৫ জুন, ২০২৩, ৫:১৪:৪১ AM১৫/৬/২৩
প্রাপক 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

পড়া হয়নি,
১৫ জুন, ২০২৩, ৯:০০:৩২ AM১৫/৬/২৩
প্রাপক 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

পড়া হয়নি,
১৬ জুন, ২০২৩, ১:০৮:৫৬ AM১৬/৬/২৩
প্রাপক 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

পড়া হয়নি,
২৫ জুন, ২০২৩, ২:০২:৫৩ PM২৫/৬/২৩
প্রাপক Crypto++ Users
Please provide a minimum reproducer with the steps to duplicate the problem.

Jeff

fa

পড়া হয়নি,
৭ জুল, ২০২৩, ৩:২১:৩৬ AM৭/৭/২৩
প্রাপক 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

পড়া হয়নি,
১১ জুল, ২০২৩, ১১:৪৭:৩২ AM১১/৭/২৩
প্রাপক 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

পড়া হয়নি,
২৮ জুল, ২০২৩, ১১:২৬:৩৬ AM২৮/৭/২৩
প্রাপক 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.




সকলকে উত্তর দিন
লেখককে লিখে পাঠান
ফরওয়ার্ড করুন
মেসেজ মুছে দেওয়া হয়েছে
0টি নতুন মেসেজ