Ir al contenido


Foto

Obtener todos los hashes (md5, sha1, sha256, sha384, sha215, CRC, etc...)


  • Por favor identifícate para responder
3 respuestas en este tema

#1 monchito_elroro

monchito_elroro

    Advanced Member

  • Miembros
  • PipPipPip
  • 259 mensajes

Escrito 08 junio 2015 - 01:25

Buenas noches con todos, si me pudieran ayudar a como obtener los hashes de un archivo.


  • 0

#2 seoane

seoane

    Advanced Member

  • Administrador
  • 1.259 mensajes
  • LocationEspaña

Escrito 08 junio 2015 - 02:00

Buenas noches con todos, si me pudieran ayudar a como obtener los hashes de un archivo.


Porqué necesitas todos? Con sha256 y md5 suele ser mas que suficiente en la mayoría de los casos.

En mi web http://delphi.jmrds.com encontraras las librerías SeCrypt y que incluyen tanto md5 como sha256. Para el resto de algoritmos no te puedo ayudar.

Saludos
  • 0

#3 monchito_elroro

monchito_elroro

    Advanced Member

  • Miembros
  • PipPipPip
  • 259 mensajes

Escrito 08 junio 2015 - 11:28

Muchas gracias por la respuesta, lo que sucede es que deseo hacer un software completo de hashes e información de un archivo, el md5 y el sha1 lo saco así:


php
  1. uses
  2.       md5, sha1;
  3.  
  4. var
  5.       sumamd5, sumasha1, myfile: String;
  6.  
  7. myfile:='D:\Pruebas.exe';
  8.  
  9. sumamd5:=MD5Print(MD5File(myfile)); // ejemplo
  10. sumasha1:= SHA1Print(SHA1File(myfile)); // ejemplo

.

Pero los demás hashes (sha256, sha384, sha215, CRC, etc...)  no logro sacarlos, por eso acudo a su ayuda. :(

 

 


  • 0

#4 monchito_elroro

monchito_elroro

    Advanced Member

  • Miembros
  • PipPipPip
  • 259 mensajes

Escrito 19 junio 2015 - 10:47

Buenas amigos de momento he logrado un pequeño avance mediante el componente "DCPcrypt" que lo baje de acá:

http://www.cityinthe...ource/dcpcrypt/

 

del mismo baje un demo creo que se llamaba "DCPcrypt v2 for Delphi 2009/2010"

 

Modificandolo logré un pequeño avance adjunto las fuentes:


php
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   windows, messages, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
  9.   StdCtrls, CheckLst, Buttons, DCPtiger, DCPsha512, DCPsha256,
  10.   DCPsha1, DCPripemd160, DCPripemd128, DCPmd5, DCPmd4, DCPcrypt2, DCPhaval;
  11.  
  12. type
  13.  
  14.   { TForm1 }
  15.  
  16.   TForm1 = class(TForm)
  17.     btnHash: TButton;
  18.     grpOutput: TGroupBox;
  19.     DCP_haval1: TDCP_haval;
  20.     DCP_md4_1: TDCP_md4;
  21.     DCP_md5_1: TDCP_md5;
  22.     DCP_ripemd128_1: TDCP_ripemd128;
  23.     DCP_ripemd160_1: TDCP_ripemd160;
  24.     DCP_sha1_1: TDCP_sha1;
  25.     DCP_sha256_1: TDCP_sha256;
  26.     DCP_sha384_1: TDCP_sha384;
  27.     DCP_sha512_1: TDCP_sha512;
  28.     DCP_tiger1: TDCP_tiger;
  29.     boxInputFile: TEdit;
  30.     grpHashes: TGroupBox;
  31.     btnBrowseFiles: TSpeedButton;
  32.     dlgOpen: TOpenDialog;
  33.     lstHashes: TCheckListBox;
  34.     txtOutput: TMemo;
  35.     procedure btnBrowseFilesClick(Sender: TObject);
  36.     procedure btnHashClick(Sender: TObject);
  37.     procedure FormCreate(Sender: TObject);
  38.   private
  39.     { private declarations }
  40.   public
  41.     { public declarations }
  42.   end;
  43.  
  44. var
  45.   Form1: TForm1;
  46.  
  47. implementation
  48.  
  49. {$R *.lfm}
  50.  
  51. { TForm1 }
  52.  
  53. procedure TForm1.FormCreate(Sender: TObject);
  54. var
  55.   i: integer;
  56.   Hash: TDCP_hash;
  57. begin
  58.   {ClientHeight := 416;
  59.   ClientWidth := 408;}
  60.   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);
  61.  
  62.   // find all the hash algorithms on the form
  63.   for i := 0 to ComponentCount - 1 do
  64.   begin
  65.     if Components[i] is TDCP_hash then
  66.     begin
  67.       Hash := TDCP_hash(Components[i]);
  68.       lstHashes.Items.AddObject(Hash.Algorithm + ' (Digest size: ' + IntToStr(Hash.HashSize) + ' bits)',Components[i]);
  69.     end;
  70.   end;
  71.  
  72. procedure TForm1.btnHashClick(Sender: TObject);
  73. var
  74.   Hashes: array of TDCP_hash;
  75.   HashDigest: array of byte;
  76.   i, j, read: integer;
  77.   s: string;
  78.   buffer: array[0..16383] of byte;
  79.   strmInput: TFileStream;
  80. begin
  81.   txtOutput.Clear;
  82.   if not FileExists(boxInputFile.Text) then
  83.   begin
  84.     MessageDlg('File does not exist',mtInformation,[mbOK],0);
  85.     Exit;
  86.   end;
  87.   Hashes := nil;
  88.   // make a list of all the hash algorithms to use
  89.   for i := 0 to lstHashes.Items.Count - 1 do
  90.   begin
  91.     if lstHashes.Checked[i] then
  92.     begin
  93.       // yes I know this is inefficient but it's also easy ;-)
  94.       SetLength(Hashes,Length(Hashes) + 1);
  95.       Hashes[Length(Hashes) - 1] := TDCP_hash(lstHashes.Items.Objects[i]);
  96.       TDCP_hash(lstHashes.Items.Objects[i]).Init;
  97.     end;
  98.   end;
  99.   strmInput := nil;
  100.   try
  101.     strmInput := TFileStream.Create(boxInputFile.Text,fmOpenRead);
  102.     repeat
  103.       // read into the buffer
  104.       read := strmInput.Read(buffer,Sizeof(buffer));
  105.       // hash the buffer with each of the selected hashes
  106.       for i := 0 to Length(Hashes) - 1 do
  107.         Hashes[i].Update(buffer,read);
  108.     until read <> Sizeof(buffer);
  109.     strmInput.Free;
  110.     // iterate through the selected hashes
  111.     for i := 0 to Length(Hashes) - 1 do
  112.     begin
  113.       SetLength(HashDigest,Hashes[i].HashSize div 8);
  114.       Hashes[i].Final(HashDigest[0]);  // get the output
  115.       s := '';
  116.       for j := 0 to Length(HashDigest) - 1 do  // convert it into a hex string
  117.         s := s + IntToHex(HashDigest[j],2);
  118.       txtOutput.Lines.Add(Hashes[i].Algorithm + ': ' + s);
  119.     end;
  120.   except
  121.     strmInput.Free;
  122.     MessageDlg('An error occurred while reading the file',mtError,[mbOK],0);
  123.   end;
  124.  
  125. procedure TForm1.btnBrowseFilesClick(Sender: TObject);
  126. begin
  127.   if dlgOpen.Execute then
  128.     boxInputFile.Text := dlgOpen.FileName;
  129.  

Espero me puedan ayudar a mejorarlo o usar alternativas, gracias de antemano.

 

 

 

 

 


  • 1




IP.Board spam blocked by CleanTalk.