mirror of
https://github.com/StephenGenusa/DCPCrypt.git
synced 2025-08-24 21:48:59 +02:00
Initial Commit with XE7 Package Files added
DCPCrypt by David Barton updated and tested with Delphi 2009, 2010, XE, XE2, XE3, XE4, XE5 by Warren Postma. Updated for XE7 by Stephen Genusa.
This commit is contained in:
13
demos/FileHash/FileHash.dpr
Normal file
13
demos/FileHash/FileHash.dpr
Normal file
@@ -0,0 +1,13 @@
|
||||
program FileHash;
|
||||
|
||||
uses
|
||||
Forms,
|
||||
uMain in 'uMain.pas' {frmMain};
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TfrmMain, frmMain);
|
||||
Application.Run;
|
||||
end.
|
BIN
demos/FileHash/FileHash.res
Normal file
BIN
demos/FileHash/FileHash.res
Normal file
Binary file not shown.
199
demos/FileHash/uMain.dfm
Normal file
199
demos/FileHash/uMain.dfm
Normal file
@@ -0,0 +1,199 @@
|
||||
object frmMain: TfrmMain
|
||||
Left = 224
|
||||
Top = 110
|
||||
Width = 416
|
||||
Height = 450
|
||||
BorderIcons = [biSystemMenu, biMinimize]
|
||||
Caption = 'DCPcrypt File Hashing Demo'
|
||||
Color = clBtnFace
|
||||
Font.Charset = ANSI_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -13
|
||||
Font.Name = 'Arial'
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
OnCreate = FormCreate
|
||||
DesignSize = (
|
||||
408
|
||||
416)
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 16
|
||||
object grpInputFile: TGroupBox
|
||||
Left = 8
|
||||
Top = 8
|
||||
Width = 393
|
||||
Height = 57
|
||||
Anchors = [akLeft, akTop, akRight]
|
||||
Caption = 'Input File'
|
||||
TabOrder = 0
|
||||
DesignSize = (
|
||||
393
|
||||
57)
|
||||
object btnBrowseFiles: TSpeedButton
|
||||
Left = 360
|
||||
Top = 24
|
||||
Width = 24
|
||||
Height = 24
|
||||
Anchors = [akTop, akRight]
|
||||
Glyph.Data = {
|
||||
76010000424D7601000000000000760000002800000020000000100000000100
|
||||
04000000000000010000120B0000120B00001000000000000000000000000000
|
||||
800000800000008080008000000080008000808000007F7F7F00BFBFBF000000
|
||||
FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00555555555555
|
||||
5555555555555555555555555555555555555555555555555555555555555555
|
||||
555555555555555555555555555555555555555FFFFFFFFFF555550000000000
|
||||
55555577777777775F55500B8B8B8B8B05555775F555555575F550F0B8B8B8B8
|
||||
B05557F75F555555575F50BF0B8B8B8B8B0557F575FFFFFFFF7F50FBF0000000
|
||||
000557F557777777777550BFBFBFBFB0555557F555555557F55550FBFBFBFBF0
|
||||
555557F555555FF7555550BFBFBF00055555575F555577755555550BFBF05555
|
||||
55555575FFF75555555555700007555555555557777555555555555555555555
|
||||
5555555555555555555555555555555555555555555555555555}
|
||||
NumGlyphs = 2
|
||||
OnClick = btnBrowseFilesClick
|
||||
end
|
||||
object boxInputFile: TEdit
|
||||
Left = 8
|
||||
Top = 24
|
||||
Width = 345
|
||||
Height = 24
|
||||
Anchors = [akLeft, akTop, akRight]
|
||||
TabOrder = 0
|
||||
end
|
||||
end
|
||||
object grpHashes: TGroupBox
|
||||
Left = 8
|
||||
Top = 72
|
||||
Width = 393
|
||||
Height = 153
|
||||
Anchors = [akLeft, akTop, akRight]
|
||||
Caption = 'Hashes'
|
||||
TabOrder = 1
|
||||
DesignSize = (
|
||||
393
|
||||
153)
|
||||
object lstHashes: TCheckListBox
|
||||
Left = 8
|
||||
Top = 24
|
||||
Width = 289
|
||||
Height = 121
|
||||
Anchors = [akLeft, akTop, akRight]
|
||||
ItemHeight = 16
|
||||
Sorted = True
|
||||
TabOrder = 0
|
||||
end
|
||||
object btnHash: TButton
|
||||
Left = 304
|
||||
Top = 120
|
||||
Width = 81
|
||||
Height = 25
|
||||
Anchors = [akTop, akRight]
|
||||
Caption = 'Hash Files'
|
||||
TabOrder = 1
|
||||
OnClick = btnHashClick
|
||||
end
|
||||
end
|
||||
object grpOutput: TGroupBox
|
||||
Left = 8
|
||||
Top = 232
|
||||
Width = 393
|
||||
Height = 177
|
||||
Anchors = [akLeft, akTop, akRight, akBottom]
|
||||
Caption = 'Output'
|
||||
TabOrder = 2
|
||||
DesignSize = (
|
||||
393
|
||||
177)
|
||||
object txtOutput: TMemo
|
||||
Left = 8
|
||||
Top = 24
|
||||
Width = 377
|
||||
Height = 145
|
||||
Anchors = [akLeft, akTop, akRight, akBottom]
|
||||
Font.Charset = ANSI_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -13
|
||||
Font.Name = 'Courier New'
|
||||
Font.Style = []
|
||||
ParentFont = False
|
||||
ReadOnly = True
|
||||
ScrollBars = ssBoth
|
||||
TabOrder = 0
|
||||
end
|
||||
end
|
||||
object DCP_haval1: TDCP_haval
|
||||
Id = 14
|
||||
Algorithm = 'Haval (256bit, 5 passes)'
|
||||
HashSize = 256
|
||||
Left = 24
|
||||
Top = 104
|
||||
end
|
||||
object DCP_md41: TDCP_md4
|
||||
Id = 17
|
||||
Algorithm = 'MD4'
|
||||
HashSize = 128
|
||||
Left = 56
|
||||
Top = 104
|
||||
end
|
||||
object DCP_md51: TDCP_md5
|
||||
Id = 16
|
||||
Algorithm = 'MD5'
|
||||
HashSize = 128
|
||||
Left = 88
|
||||
Top = 104
|
||||
end
|
||||
object DCP_ripemd1281: TDCP_ripemd128
|
||||
Id = 27
|
||||
Algorithm = 'RipeMD-128'
|
||||
HashSize = 128
|
||||
Left = 120
|
||||
Top = 104
|
||||
end
|
||||
object DCP_ripemd1601: TDCP_ripemd160
|
||||
Id = 10
|
||||
Algorithm = 'RipeMD-160'
|
||||
HashSize = 160
|
||||
Left = 152
|
||||
Top = 104
|
||||
end
|
||||
object DCP_sha11: TDCP_sha1
|
||||
Id = 2
|
||||
Algorithm = 'SHA1'
|
||||
HashSize = 160
|
||||
Left = 24
|
||||
Top = 136
|
||||
end
|
||||
object DCP_sha2561: TDCP_sha256
|
||||
Id = 28
|
||||
Algorithm = 'SHA256'
|
||||
HashSize = 256
|
||||
Left = 56
|
||||
Top = 136
|
||||
end
|
||||
object DCP_sha3841: TDCP_sha384
|
||||
Id = 29
|
||||
Algorithm = 'SHA384'
|
||||
HashSize = 384
|
||||
Left = 88
|
||||
Top = 136
|
||||
end
|
||||
object DCP_sha5121: TDCP_sha512
|
||||
Id = 30
|
||||
Algorithm = 'SHA512'
|
||||
HashSize = 512
|
||||
Left = 120
|
||||
Top = 136
|
||||
end
|
||||
object DCP_tiger1: TDCP_tiger
|
||||
Id = 18
|
||||
Algorithm = 'Tiger'
|
||||
HashSize = 192
|
||||
Left = 152
|
||||
Top = 136
|
||||
end
|
||||
object dlgOpen: TOpenDialog
|
||||
Filter = 'All Files (*.*)|*.*'
|
||||
Title = 'Choose input file'
|
||||
Left = 24
|
||||
Top = 168
|
||||
end
|
||||
end
|
151
demos/FileHash/uMain.pas
Normal file
151
demos/FileHash/uMain.pas
Normal file
@@ -0,0 +1,151 @@
|
||||
{******************************************************************************}
|
||||
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
|
||||
{******************************************************************************}
|
||||
{* A file hashing demo ********************************************************}
|
||||
{******************************************************************************}
|
||||
{* Copyright (c) 2003 David Barton *}
|
||||
{* Permission is hereby granted, free of charge, to any person obtaining a *}
|
||||
{* copy of this software and associated documentation files (the "Software"), *}
|
||||
{* to deal in the Software without restriction, including without limitation *}
|
||||
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
|
||||
{* and/or sell copies of the Software, and to permit persons to whom the *}
|
||||
{* Software is furnished to do so, subject to the following conditions: *}
|
||||
{* *}
|
||||
{* The above copyright notice and this permission notice shall be included in *}
|
||||
{* all copies or substantial portions of the Software. *}
|
||||
{* *}
|
||||
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
|
||||
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
|
||||
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
|
||||
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
|
||||
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
|
||||
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
|
||||
{* DEALINGS IN THE SOFTWARE. *}
|
||||
{******************************************************************************}
|
||||
unit uMain;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||||
Dialogs, Buttons, StdCtrls, CheckLst, DCPtiger, DCPsha512, DCPsha256,
|
||||
DCPsha1, DCPripemd160, DCPripemd128, DCPmd5, DCPmd4, DCPcrypt2, DCPhaval;
|
||||
|
||||
type
|
||||
TfrmMain = class(TForm)
|
||||
DCP_haval1: TDCP_haval;
|
||||
DCP_md41: TDCP_md4;
|
||||
DCP_md51: TDCP_md5;
|
||||
DCP_ripemd1281: TDCP_ripemd128;
|
||||
DCP_ripemd1601: TDCP_ripemd160;
|
||||
DCP_sha11: TDCP_sha1;
|
||||
DCP_sha2561: TDCP_sha256;
|
||||
DCP_sha3841: TDCP_sha384;
|
||||
DCP_sha5121: TDCP_sha512;
|
||||
DCP_tiger1: TDCP_tiger;
|
||||
grpInputFile: TGroupBox;
|
||||
boxInputFile: TEdit;
|
||||
grpHashes: TGroupBox;
|
||||
lstHashes: TCheckListBox;
|
||||
grpOutput: TGroupBox;
|
||||
txtOutput: TMemo;
|
||||
btnHash: TButton;
|
||||
btnBrowseFiles: TSpeedButton;
|
||||
dlgOpen: TOpenDialog;
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure btnBrowseFilesClick(Sender: TObject);
|
||||
procedure btnHashClick(Sender: TObject);
|
||||
private
|
||||
{ Private declarations }
|
||||
public
|
||||
{ Public declarations }
|
||||
end;
|
||||
|
||||
var
|
||||
frmMain: TfrmMain;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.dfm}
|
||||
|
||||
procedure TfrmMain.FormCreate(Sender: TObject);
|
||||
var
|
||||
i: integer;
|
||||
Hash: TDCP_hash;
|
||||
begin
|
||||
ClientHeight := 416;
|
||||
ClientWidth := 408;
|
||||
MessageDlg('This is a file hashing demo using the DCPcrypt component set.'+#13+'For more information see http://www.cityinthesky.co.uk/cryptography.html',mtInformation,[mbOK],0);
|
||||
|
||||
// find all the hash algorithms on the form
|
||||
for i := 0 to ComponentCount - 1 do
|
||||
begin
|
||||
if Components[i] is TDCP_hash then
|
||||
begin
|
||||
Hash := TDCP_hash(Components[i]);
|
||||
lstHashes.Items.AddObject(Hash.Algorithm + ' (Digest size: ' + IntToStr(Hash.HashSize) + ' bits)',Components[i]);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrmMain.btnBrowseFilesClick(Sender: TObject);
|
||||
begin
|
||||
if dlgOpen.Execute then
|
||||
boxInputFile.Text := dlgOpen.FileName;
|
||||
end;
|
||||
|
||||
procedure TfrmMain.btnHashClick(Sender: TObject);
|
||||
var
|
||||
Hashes: array of TDCP_hash;
|
||||
HashDigest: array of byte;
|
||||
i, j, read: integer;
|
||||
s: string;
|
||||
buffer: array[0..16383] of byte;
|
||||
strmInput: TFileStream;
|
||||
begin
|
||||
txtOutput.Clear;
|
||||
if not FileExists(boxInputFile.Text) then
|
||||
begin
|
||||
MessageDlg('File does not exist',mtInformation,[mbOK],0);
|
||||
Exit;
|
||||
end;
|
||||
Hashes := nil;
|
||||
// make a list of all the hash algorithms to use
|
||||
for i := 0 to lstHashes.Items.Count - 1 do
|
||||
begin
|
||||
if lstHashes.Checked[i] then
|
||||
begin
|
||||
// yes I know this is inefficient but it's also easy ;-)
|
||||
SetLength(Hashes,Length(Hashes) + 1);
|
||||
Hashes[Length(Hashes) - 1] := TDCP_hash(lstHashes.Items.Objects[i]);
|
||||
TDCP_hash(lstHashes.Items.Objects[i]).Init;
|
||||
end;
|
||||
end;
|
||||
strmInput := nil;
|
||||
try
|
||||
strmInput := TFileStream.Create(boxInputFile.Text,fmOpenRead);
|
||||
repeat
|
||||
// read into the buffer
|
||||
read := strmInput.Read(buffer,Sizeof(buffer));
|
||||
// hash the buffer with each of the selected hashes
|
||||
for i := 0 to Length(Hashes) - 1 do
|
||||
Hashes[i].Update(buffer,read);
|
||||
until read <> Sizeof(buffer);
|
||||
strmInput.Free;
|
||||
// iterate through the selected hashes
|
||||
for i := 0 to Length(Hashes) - 1 do
|
||||
begin
|
||||
SetLength(HashDigest,Hashes[i].HashSize div 8);
|
||||
Hashes[i].Final(HashDigest[0]); // get the output
|
||||
s := '';
|
||||
for j := 0 to Length(HashDigest) - 1 do // convert it into a hex string
|
||||
s := s + IntToHex(HashDigest[j],2);
|
||||
txtOutput.Lines.Add(Hashes[i].Algorithm + ': ' + s);
|
||||
end;
|
||||
except
|
||||
strmInput.Free;
|
||||
MessageDlg('An error occurred while reading the file',mtError,[mbOK],0);
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
Reference in New Issue
Block a user