File Encryption & Read/Write in Binary Mode
I am working on an encryption program. There are two versions. One is text encryption and the second is binary encrytion. The text encryption is fairly simply. The downside to the text version is that is only works on text files. One the other hand, I cannot get the binary encryption program to work.
There are two problems. First, I cannot copy complete raw data from any file and save it into a character array. I have tried giving the array a specific size and I have tried dynamically allocating the size of the array based on the size of the ifstream.
openFile.open(x, ios::in | ios::binary);
size = openFile.tellg();
temp = new char(size);
openFile.read((char *) temp, sizeof(temp));
The code above does work, however, "sizeof(temp)" always output a 4 even if its subscript is 1000. the char * does not affect it because I saw the same number even if I use:
How do you read raw data (binary) from any file and save it in memory so you can make specific encryption and then write it back in binary mode?