This tutorial continues from Encrypt a file.

Setup

Put another button on the main form and caption it "Hash".
Add a THash component to the form and connect it up to the existing TCryptographicLibrary component.
Pull down the choices for the Hash property of the Hash component. List Hash algorithms include MD5 and a large number from the SHA family. Select MD5.

MD5 is weak hash and shouldn't be used for protecting high value assets. But you might have good reasons to use it for interoperability because it is widely used, for example in the Facebook API.
 

Operation

Now implement the event handler for the Hash button like so …

procedure TmfmWestwood3DES_Tut.btnHashClick(Sender: TObject);
var
  sSourceFN: string;
begin
if not dlgOpenPlaintext.Execute then exit;
try
  Put( '', []);  // Empty line.
  sSourceFN  := dlgOpenPlaintext.FileName;
  Put( 'Now computing MD5 hash on file "%s".', [sSourceFN]);
  Hash1.HashFile( sSourceFN);
  // The binary value of the hash can now be found in the stream Hash1.HashOutputValue
  Put( 'The base64 representation of the hash output is %s.',
    [Stream_to_Base64( Hash1.HashOutputValue)])
except on E: Exception do
    begin
    Put( '%s: %s', [E.ClassName, E.Message]);
    end
  end;
end;

You will need to include the unit uTPLb_StreamUtils to gain access to the Stream_to_Base64 function.

关于法定节假日的问题

1995年5月, 中国开始实行每周5天工作制。 1999年9月18日,中国国务院发布《全国年节及纪念日放假办法》,决定增加公众法定休假日。春节、“五一”和 “十一...

阅读全文

CentOS下shadowsocks-libev一键安装脚本

本脚本适用环境: 系统支持:CentOS 内存要求:≥128M 日期:2018 年 06 月 01 日 关于本脚本: 一键安装 libev 版的 Shadowsocks 最新版本。该版本的特点...

阅读全文

在MAC上安装docker并部署oracle12.2

一。在Mac上安装docker。到docker store下载即可。下载地址是:https://store.docker.com/editions/community/docker-ce-desktop-mac。其实我们还可以看到别...

阅读全文

评论已经关闭。