标签:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
unit CheckFilePropertity;
interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons,IdHashMessageDigest, IdHashCRC, IdHashSHA, IdSSLOpenSSLHeaders; type TMainFrm = class(TForm) lbl1: TLabel; edtFileName: TEdit; btnBrowser: TBitBtn; lbl2: TLabel; edtMD5: TEdit; lbl3: TLabel; edtCRC: TEdit; lbl4: TLabel; edtSHA1: TEdit; dlgOpenFile: TOpenDialog; btn1: TButton; procedure btnBrowserClick(Sender: TObject); procedure edtFileNameChange(Sender: TObject); procedure FormCreate(Sender: TObject); procedure btn1Click(Sender: TObject); private { Private declarations } public function GetFile_MD5(const iFileName: String): String; // 获取文件MD5 function GetFile_CRC(const iFileName: String): String; // 获取文件CRC function GetFile_SHA1(const iFileName: String): String; // 获取文件SHA1 function GetFile_SHA256(const iFileName: String): String; // 获取文件SHA256 function GetFile_SHA384(const iFileName: String): String; // 获取文件SHA384 function GetFile_SHA512(const iFileName: String): String; // 获取文件SHA512 procedure GetSum(i:Integer; j:Integer); function CheckSum(i:Integer; j:Integer):Integer; { Public declarations } end; type TMD5=class(TIdHashMessageDigest5); var MainFrm: TMainFrm; implementation {$R *.dfm} function TMainFrm.CheckSum(i: Integer; j: Integer):Integer; var sum : Integer; begin sum := i * j; result:= sum; end; Procedure TMainFrm.GetSum(i: Integer; j: Integer); begin ShowMessage(IntToStr(i + j)); end; function TMainFrm.GetFile_MD5(const iFileName: string): String; var MemSteam: TMemoryStream; MyMD5 : TIdHashMessageDigest5; begin MemSteam := TMemoryStream.Create; MemSteam.LoadFromFile(iFileName); MyMD5 := TIdHashMessageDigest5.Create; Result := MyMD5.HashStreamAsHex(MemSteam); MyMD5.Free; MemSteam.Free; end; procedure TMainFrm.edtFileNameChange(Sender: TObject); begin edtMD5.Text := GetFile_MD5(edtFileName.Text); edtCRC.Text := GetFile_CRC(edtFileName.Text); edtSHA1.Text := GetFile_SHA1(edtFileName.Text); //edtSHA256.Text := GetFile_SHA256(edtFileName.Text); //edtSHA384.Text := GetFile_SHA384(edtFileName.Text); //edtSHA512.Text := GetFile_SHA512(edtFileName.Text); end; procedure TMainFrm.FormCreate(Sender: TObject); begin edtMD5.Font.Color := clRed; edtCRC.Font.Color := clRed; edtSHA1.Font.Color := clRed; end; function TMainFrm.GetFile_CRC(const iFileName: string): String; var MemSteam: TMemoryStream; MyCRC : TIdHashCRC32; begin MemSteam := TMemoryStream.Create; MemSteam.LoadFromFile(iFileName); MyCRC := TIdHashCRC32.Create; Result := MyCRC.HashStreamAsHex(MemSteam); MyCRC.Free; MemSteam.Free; end; function TMainFrm.GetFile_SHA1(const iFileName: String): String; var SHA1 : TIdHashSHA1; fileStream: TMemoryStream; begin SHA1 := TIdHashSHA1.Create; fileStream := TMemoryStream.Create; try fileStream.LoadFromFile(iFileName); Result := SHA1.HashStreamAsHex(fileStream); finally fileStream.Free; SHA1.Free; end; end; function TMainFrm.GetFile_SHA256(const iFileName: String): String; var SHA256 : TIdHashSHA256; fileStream: TMemoryStream; begin if 1=1 then begin SHA256 := TIdHashSHA256.Create; fileStream := TMemoryStream.Create; try fileStream.LoadFromFile(iFileName); Result := SHA256.HashStreamAsHex(fileStream); finally fileStream.Free; SHA256.Free; end; end else begin Result := ‘Error‘; end; end; function TMainFrm.GetFile_SHA384(const iFileName: String): String; var SHA384 : TIdHashSHA384; fileStream: TMemoryStream; begin if 1=1 then begin SHA384 := TIdHashSHA384.Create; fileStream := TMemoryStream.Create; try fileStream.LoadFromFile(iFileName); Result := SHA384.HashStreamAsHex(fileStream); finally fileStream.Free; SHA384.Free; end; end else begin Result := ‘Error‘; end; end; function TMainFrm.GetFile_SHA512(const iFileName: String): String; var SHA512 : TIdHashSHA512; fileStream: TMemoryStream; begin if 1=1 then begin SHA512 := TIdHashSHA512.Create; fileStream := TMemoryStream.Create; try fileStream.LoadFromFile(iFileName); Result := SHA512.HashStreamAsHex(fileStream); finally fileStream.Free; SHA512.Free; end; end else begin Result := ‘Error‘; end; end; procedure TMainFrm.btn1Click(Sender: TObject); begin //GetSum(400,50); ShowMessage(IntToStr(CheckSum(4,5))); end; procedure TMainFrm.btnBrowserClick(Sender: TObject); begin if dlgOpenFile.Execute then edtFileName.Text:= dlgOpenFile.FileName; end; end. |
标签:
原文地址:http://www.cnblogs.com/kivin/p/4646939.html