The Road to Delphi

Delphi – Free Pascal – Oxygene

Calculate the SHA1 hash of a file, using Delphi Prism

Leave a comment

The next code show how calculate the SHA1 hash of a file, using Delphi Prism (Oxygene)

uses
    System.IO,
    System.Security,
    System.Security.Cryptography;

function CalcSHA1HashCode(oFile:String) : String;
var
 sh1Provider : SHA1CryptoServiceProvider;
 st          : FileStream;
 hash        : Array of Byte;
begin
st := New FileStream(oFile,System.IO.FileMode.Open, System.IO.FileAccess.Read,System.IO.FileShare.ReadWrite);
try
  sh1Provider:= New SHA1CryptoServiceProvider();
  hash       := sh1Provider.ComputeHash(st);
  Result     := Convert.ToBase64String(hash);
finally
   st.Close;
end;
end;

Author: Rodrigo

Just another Delphi guy.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s