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;
Unknown's avatar

Author: Rodrigo

Just another Delphi guy.

Leave a comment