Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Me ayudan con este código?? (https://www.clubdelphi.com/foros/showthread.php?t=87900)

MaxiDucoli 15-03-2015 15:35:29

Me ayudan con este código??
 
Hola, conseguí este código que supuestamente hace un Sha256 HMAC en delphi, pero para testearlo y ver si me sirve, necesito que funcione y no logro hacerlofuncionar.

Les dejo el dódigo y yo tengo Delphi XE7 y ahí me daerror en incompatibilidad con los TidBytes y los TArray.

Código Delphi [-]
unit HMAC;

interface

uses
  System.SysUtils,
  EncdDecd,
  IdHMAC,
  IdSSLOpenSSL,
  IdHash;

type
  THMACUtils < T: TIdHMAC, constructor> = class
  public
    class function HMAC(aKey, aMessage: RawByteString): TBytes;
    class function HMAC_HexStr(aKey, aMessage: RawByteString): RawByteString;
    class function HMAC_Base64(aKey, aMessage: RawByteString): RawByteString;
  end;

implementation

class function THMACUtils.HMAC(aKey, aMessage: RawByteString): TBytes;
var
  _HMAC: T;
begin
  if not IdSSLOpenSSL.LoadOpenSSLLibrary then Exit;
  _HMAC:= T.Create;
  try
    _HMAC.Key := BytesOf(aKey);      <----------------------------- Acá ya empieza a dar error y no encuentro un convertidor para eso.
    Result:= _HMAC.HashValue(BytesOf(aMessage));
  finally
    _HMAC.Free;
  end;
end;

class function THMACUtils.HMAC_HexStr(aKey, aMessage: RawByteString): RawByteString;
var
  I: Byte;
begin
  Result:= '0x';
  for I in HMAC(aKey, aMessage) do
    Result:= Result + IntToHex(I, 2);
end;

class function THMACUtils.HMAC_Base64(aKey, aMessage: RawByteString): RawByteString;
var
  _HMAC: TBytes;
begin
  _HMAC:= HMAC(aKey, aMessage);
  Result:= EncodeBase64(_HMAC, Length(_HMAC));
end;

end.

nlsgarcia 15-03-2015 16:04:31

MaxiDucoli,

Cita:

Empezado por MaxiDucoli
...conseguí este código que supuestamente hace un SHA256 HMAC en Delphi...y no logro hacerlo funcionar...tengo Delphi XE7...

:rolleyes:

Pregunto :

1- ¿Tienes las librerías IdHMAC, IdSSLOpenSSL, IdHash referenciadas en Delphi? :confused:

2- ¿Puedes publicar el link del código en cuestión?.

Revisa esta otra alternativa:
Espero sea útil :)

Nelson.


La franja horaria es GMT +2. Ahora son las 05:39:56.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi