DelphiFan Magazine

Top Menu

Main Menu

  • DELPHI
  • CODE SAMPLES
  • FIREMONKEY
  • DATABASE
  • RELEASES
  • VIDEOS
  • REVIEW
  • TECH NEWS

logo

DelphiFan Magazine

  • DELPHI
  • CODE SAMPLES
  • FIREMONKEY
  • DATABASE
  • RELEASES
  • VIDEOS
  • REVIEW
  • TECH NEWS
  • How to add a server application written in UNIGUI to startup?

  • UniGUI Expiry Link Anonymizer

  • UniGUI Add CAPTCHA to the WEB project

  • UniGui. Unique hybrid of Delphi and JS

  • How to transform a blob field into string lines (varchar) in SQL Firebird?

CODE SAMPLESDELPHI
Home›CODE SAMPLES›Delphi calculates MD5

Delphi calculates MD5

By admin
January 2, 2021
386
0
Share:

Delphi calculates MD5
In cryptography, MD5 (Message Digest Algorithm 5, Message Digest Algorithm 5) is a 128-bit password reduction algorithm, and it is one of the most widely used algorithms today.

One of the most common uses is to check whether the file has not been modified.

One of the best examples of using it is that when we download a file from the Internet, the distributor will provide us with an MD5 hash value so that it can be checked after the download and confirmed that it has not changed.

The MD5 hash is 128 bits long, but is generally read in its 32-bit hexadecimal value.

MD5 function in Delphi
Delphi is not exempted as a programming language, but can create a function that calculates the MD5 of a file.

To perform this function, we will need three units, namely IdHashMessageDigest, idHash and IdGlobal.

In this case, we perform two similar functions, one function calculates MD5 in string form, and the other function calculates MD5 in file form.

 

uses IdGlobal, IdHash, IdHashMessageDigest;
function getFileMd5HashString(const vFileName: string): string;
var
  vHashMD5: TIdHashMessageDigest5;
  vFile: TFileStream;
begin
  vFile := TFileStream.Create(vFileName, fmOpenRead OR fmShareDenyWrite);
  vHashMD5 := nil;
  try
    vHashMD5 := TIdHashMessageDigest5.Create;
    Result := IdGlobal.IndyLowerCase(vHashMD5.HashStreamAsHex(vFile));
  finally
    vHashMD5.Free;
  end;
end;
function getMd5HashString(const vValue: string): string;
var
  vHashMD5: TIdHashMessageDigest5;
begin
  vHashMD5 := nil;
  try
    vHashMD5 := TIdHashMessageDigest5.Create;
    Result := IdGlobal.IndyLowerCase(vHashMD5.HashStringAsHex(vValue));
  finally
    vHashMD5.Free;
  end;
end;
Its use form is as follows:
procedure TForm1.Button1Click(Sender: TObject);
begin
// Calculate the MD5 of a string
  showmessage(getMd5HashString(‘cadena de texto’));
 
// Calculate the MD5 of a file
  showmessage(getFileMd5HashString(‘c:\file.xxx’));
end;
Tagscalculate md5delphidelphi md5md5
Previous Article

Theme setting for Delphi

Next Article

Use Windows API (WinCrypt) to calculate the ...

0
Shares
  • 0
  • +
  • 0
  • 0
  • 0
  • 0

admin

Related articles More from author

  • DELPHIVIDEOS

    Per Form VCL Styling

    September 29, 2020
    By admin
  • CODE SAMPLESDELPHI

    Convert Json to TFDMemTable

    December 7, 2020
    By admin
  • CODE SAMPLESDELPHI

    How to set up Unigui to run on Linux Operating System

    October 11, 2020
    By admin
  • CODE SAMPLESDELPHIFIREMONKEY

    Copy text to clipboard in Firemonkey applications

    December 15, 2020
    By admin
  • CODE SAMPLESDELPHI

    Use Windows API (WinCrypt) to calculate the MD5

    January 2, 2021
    By admin
  • CODE SAMPLESTECH NEWS

    How to modify the maximum number of tcp connections on the windows server

    October 9, 2020
    By admin

Leave a reply Cancel reply

You may interested

  • CODE SAMPLESDELPHI

    Delphi View DPR file

  • CODE SAMPLESDELPHI

    Two Ways to Improve the Development Efficiency of Unigui in Delphi

  • CODE SAMPLESDELPHI

    Implementation of uniGUI login-free

  • LATEST REVIEWS

  • TOP REVIEWS

Timeline

  • January 27, 2021

    How to add a server application written in UNIGUI to startup?

  • January 27, 2021

    UniGUI Expiry Link Anonymizer

  • January 26, 2021

    UniGUI Add CAPTCHA to the WEB project

  • January 26, 2021

    UniGui. Unique hybrid of Delphi and JS

  • January 13, 2021

    How to transform a blob field into string lines (varchar) in SQL Firebird?

Latest Comments

Find us on Facebook

Follow Us on Instagram

logo

Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.

About us

  • 660 Pennsylvania Avenue Southeast #100 Washington, DC 20003
  • 0123456789
  • adsdelphi@gmail.com
  • Recent

  • Popular

  • Comments

  • How to add a server application written in UNIGUI to startup?

    By admin
    January 27, 2021
  • UniGUI Expiry Link Anonymizer

    By admin
    January 27, 2021
  • UniGUI Add CAPTCHA to the WEB project

    By admin
    January 26, 2021
  • UniGui. Unique hybrid of Delphi and JS

    By admin
    January 26, 2021
  • How to add a server application written in UNIGUI to startup?

    By admin
    January 27, 2021
  • Amazing Cross Platform Email App Sample In Delphi 10.4.1 FireMonkey For Android And IOS

    By admin
    August 13, 2020
  • Critical Update Available For Delphi FireMonkey 10.4.1 On Android, IOS, OSX, Windows, And Linux

    By admin
    September 4, 2020
  • Setting up the IDE for your first Android Application in Delphi

    By admin
    September 7, 2020

Follow us

Find us on Facebook

© Copyright Delphifan Forum. All rights reserved.