I have PKCS #7 Certificates (.spc) file generated from some equipment. It has an array of floats, that I need to read into my C++ program.
Before, I was using an external program to generate a .csv file. However, I lose some precision here since it will only save 15 digits. This is a problem, I need the precision.
I have searched around for some time, but to no avail. Trying either fstream or a boost mmap just yields some encrypted gibberish...
Like this:
Fstream:
fstream iofile;
string path = "C:\\test.spc";
iofile.open(path.c_str());
if (iofile.is_open()) {
string s;
while (getline(iofile, s, '\n'))
cout << s << endl;
}
boost mmap:
boost::iostreams::mapped_file mmap("C:\\test.spc", boost::iostreams::mapped_file::readonly); // create RAM access mmap
auto f = mmap.const_data(); // set data to char array
auto l = f + mmap.size(); // used to detect end of file
string next = ""; // used to read in chars
for (; f && f != l; f++) {
cout << f[0] << endl;
}
Both just output random characters that make no sense.
Found out it is a binary format. So I tried this:
streampos size;
char * memblock;
ifstream file("C:\\test.spc", ios::in | ios::binary | ios::ate);
if (file.is_open())
{
size = file.tellg();
memblock = new char[size];
file.seekg(0, ios::beg);
file.read(memblock, size);
file.close();
for (unsigned int i = 0; i < size; i++)
cout << memblock[i];
cout << endl << "DONE" << endl;
cout << "the entire file content is in memory";
delete[] memblock;
}
else cout << "Unable to open file";
Which gave alot more characters than before, but still random.
Here is a link to the file: https://drive.google.com/a/uci.edu/file/d/0B3LD-8zOiOdza2FGSVNtbnlSVjQ/view?usp=sharing
SOLVED. Since it is a binary file, I have been trying to find the format. Found it, I posted a link with examples files, code, and the pdf explaining the format for anyone who needs it. Here is some code in c++ I wrote that reads it in. Thanks to Reticulated Spline for the help! https://drive.google.com/a/uci.edu/folderview?id=0B3LD-8zOiOdzfjY3YXJEdGlTZ2Z1ekJGNVlJalpYRmRkOHFFaFI4XzZEaWpFbldLSEt3LW8&usp=sharing