My Environment:
- C++ Builder XE4
- using VCL component
- Indy 10.6.0.4975
I was studying to use MD5, SHA-1, and SHA-2s.
Unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <IdHashSHA.hpp> // SHA-1, SHA-2
#include <IdHashMessageDigest.hpp> // for MD5
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Memo1->Lines->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
String msg;
msg = L"Hello, world";
String hash;
// 1. MD5
TIdHashMessageDigest5 *md5;
md5 = new TIdHashMessageDigest5();
//
hash = md5->HashStringAsHex(msg, IndyTextEncoding(TEncoding::ASCII)).LowerCase();
Memo1->Lines->Add(L"MD5: " + hash);
delete md5;
// 2. SHA-1
TIdHashSHA1 *sha1;
sha1 = new TIdHashSHA1();
//
hash = sha1->HashStringAsHex(msg, IndyTextEncoding(TEncoding::ASCII)).LowerCase();
Memo1->Lines->Add(L"SHA-1:" + hash);
delete sha1;
// 3. SHA-2 (SHA-512)
TIdHashSHA512 *sha512;
sha512 = new TIdHashSHA512();
//
hash = sha512->HashStringAsHex(msg, IndyTextEncoding(TEncoding::ASCII)).LowerCase();
Memo1->Lines->Add(L"SHA-512:" + hash);
delete sha512;
}
//---------------------------------------------------------------------------
The result is as follows.
Then, I found the following:
TidHashSHA512.isavailable is false on Windows 10
According to the suggestion, I add two files to where the .exe file exists:
- ssleay32.dll
- libeay32.dll
Still, the SHA-512 returns NULL.
What I am missing?