Skip to content

Commit

Permalink
test: use non-deprecated api for OpenSSL example (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-azarchs authored Oct 23, 2024
1 parent 4457a7e commit 23f2c4d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions examples/ssl.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Demonstrate linking against a conda package, in this case OpenSSL.

#include <openssl/sha.h>
#include <openssl/evp.h>

#include <iostream>
#include <string_view>
Expand All @@ -9,15 +9,16 @@ using std::string_view;

int main() {
const string_view message = "Hello World";
unsigned char hash[SHA256_DIGEST_LENGTH];
unsigned char hash[EVP_MAX_MD_SIZE];
size_t hashLen;

SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, message.data(), message.size());
SHA256_Final(hash, &sha256);
if (!EVP_Q_digest(nullptr, "SHA256", nullptr, message.data(),
message.length(), hash, &hashLen)) {
return 1;
}

std::cout << "SHA-256 Hash of 'Hello World': ";
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
for (int i = 0; i < hashLen; i++) {
printf("%02x", hash[i]);
}
std::cout << std::endl;
Expand Down

0 comments on commit 23f2c4d

Please sign in to comment.