I'm writing a C++ class to add a digital signature to a PDF, using OpenSSL to generate a SHA1 hash, which I then print to a file:
unsigned char hash[SHA_DIGEST_LENGTH];
SHA1((unsigned char *)temp.c_str(), temp.size(), hash);
std::ofstream fout("resources/hash.out", std::ios::binary);
fout << hash;
fout << hash
for (int i=0; i<SHA_DIGEST_LENGTH; ++i) fout.put(hash[i]);
There is a stream-inserter for NUL-terminated strings, which is the one selected.
But you are trying to output an array of fixed length containing arbitrary bytes, which is something completely different, leading to UB.
Just use memberfunction
write(buffer, size) instead, which is designed for that.