Gizmo_the_Great
Gizmo_the_Great

Reputation: 979

Does Free Pascal have a way to implement SHA256 or SHA512?

In the Free Pascal libraries there's a hash library that enables use of MD5 and SHA1 hashing algorithms (http://wiki.freepascal.org/hash). But what if I wanted to use a higher one, such as SHA256 or SHA512? Could I achieve this using Free Pascal? Searching the FP Wiki retunrs zero hits for SHA256\SHA512.

Upvotes: 4

Views: 4455

Answers (4)

Vinko
Vinko

Reputation: 21

In Lazarus 3.2, I used the library HashLib4Pascal. A SHA512 hash could be calculated like this:

uses
HlpIHash,HlpHashFactory;

function CalcSha512(const aStrToHash: String): String;
var
IHashCrypt: IHash;
begin 
  IHashCrypt:=THashFactory.TCrypto.CreateSHA2_512();
  Result:=IHashCrypt.ComputeString(aStrToHash,TEncoding.UTF8).ToString();
  //...
  //free up
  //...
end;

Upvotes: 0

Wouter van Nifterick
Wouter van Nifterick

Reputation: 24086

In Google codesearch I found several units that implement it in pascal.

Query: sha256 | sha512 lang:pascal

One of the sources is from Double Commander, which is a norton/total commander clone that's developed with FreePascal and Lazarus, so there you go.

Upvotes: 3

Marco van de Voort
Marco van de Voort

Reputation: 26358

In recent versions (say 2 years or so), there is a package "hash" with units "sha1" and "md5" that implement some basic hashes and checksums

If you need more, most people use DCPCrypt as it is easily converted

http://www.cityinthesky.co.uk/opensource/dcpcrypt

At least I see regularly posts on the lists that people are using it

Upvotes: 5

Michał Niklas
Michał Niklas

Reputation: 54292

For other hashes I use "Delphi Encryption Compendium (DEC) 5.2". I don't know if it works with FPC, but you should try. There is THash_SHA512 and THash_SHA256. Download it from: http://www.torry.net/pages.php?id=519#939342

Upvotes: 1

Related Questions