{$IFNDEF CLR}

{$I Dac.inc}

unit CRMD5;
{$ENDIF}

interface

uses
{$IFNDEF CLR}
  CLRClasses,
{$ENDIF}
  SysUtils, CRTypes, CRHash;

type
  TMD5CryptoServiceProvider = class(THash_MD5)
  protected
    procedure HashCore(rgb: IntPtr; cbSize: Integer); overload; override;
    procedure HashCore(const rgb: TBytes; ibStart, cbSize: Integer); overload; override;
    function HashFinal: TBytes; override;

  public
    constructor Create; override;
    procedure Initialize; override;
  end;

implementation

constructor TMD5CryptoServiceProvider.Create;
begin
  inherited;
  Init;
end;

procedure TMD5CryptoServiceProvider.Initialize;
begin
  Init;
end;

procedure TMD5CryptoServiceProvider.HashCore(rgb: IntPtr; cbSize: Integer);
begin
  if (rgb <> nil) and (cbSize > 0) then
    Calc(rgb, cbSize);
end;

procedure TMD5CryptoServiceProvider.HashCore(const rgb: TBytes; ibStart, cbSize: Integer);
begin
  if (rgb <> nil) and (cbSize > 0) then
    Calc(rgb, ibStart, cbSize);
end;

function TMD5CryptoServiceProvider.HashFinal: TBytes;
begin
  Done;
  SetLength(Result, DigestKeySize);
  Buffer.BlockCopy(DigestKey, 0, Result, 0, DigestKeySize);
end;

end.

