Enviado em 22/06/2018 - 12:46h
Olá, gostaria de saber se existe uma API para as linguagens C e C++ para se trabalhar com funções hash (SHA-2 e SHA-1) e que seja compativel com todas as plataformas (Windows, Mac OS, Linux e Unix)?
Enviado em 22/06/2018 - 12:46h
Enviado em 23/06/2018 - 16:06h
g++ -o teste teste.cpp -lcrypto
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <string>
#include <sstream>
#include <openssl/sha.h>
std::string sha512sum(const std::string& input)
{
unsigned char digest[SHA512_DIGEST_LENGTH];
// compute hash
SHA512(reinterpret_cast<unsigned const char*>(input.c_str()),
input.size(),
&digest[0]);
// convert byte digest to hex representation
std::stringstream ss;
for(int i = 0; i < SHA512_DIGEST_LENGTH; i++) {
ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(digest[i]);
}
return ss.str();
}
int main()
{
using namespace std;
string a {"hello\n"};
cout << a << "\n\nsha512 hash: " << sha512sum(a) << endl;
return 0;
}
Enviado em 22/06/2018 - 19:57h
https://github.com/clibs/sha1
https://github.com/B-Con/crypto-algorithmsAbraço,
Enviado em 23/06/2018 - 09:41h
Enviado em 23/06/2018 - 14:51h
Entre na sua conta para responder.