<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Silvio,<br>
<br>
I had the same requirement for an HMAC and used the DCP library:<br>
<br>
<a class="moz-txt-link-freetext" href="http://wiki.freepascal.org/DCPcrypt">http://wiki.freepascal.org/DCPcrypt</a><br>
<br>
I then used the following code snippet to generate the HMAC<br>
<br>
Regards<br>
<br>
Tony Whyman<br>
MWA<br>
<br>
unit hmac;<br>
<br>
{$mode objfpc}{$H+}<br>
<br>
interface<br>
<br>
uses<br>
Classes, SysUtils;<br>
<br>
procedure MakeHMAC(text: string; var seed: LongInt; var hash:
string);<br>
function ValidateHMAC(text: string; seed: LongInt; hmac: string):
boolean;<br>
<br>
implementation<br>
<br>
uses DCPsha1;<br>
<br>
function GenerateHash(seed: longint; data: string):string;<br>
var b1, b2, b3, b4: byte;<br>
q: integer;<br>
sha1: TDCP_sha1;<br>
buffer: PChar;<br>
memsize: integer;<br>
len: integer;<br>
begin<br>
len := Length(data);<br>
b1 := seed mod 256;<br>
q := seed div 256;<br>
b2 := q mod 256;<br>
q := q div 256;<br>
b3 := q mod 256;<br>
b4 := q div 256;<br>
<br>
sha1 := TDCP_sha1.Create(nil);<br>
try<br>
sha1.Init;<br>
memsize := len + 4;<br>
buffer := SysGetMem(memsize);<br>
try<br>
Move(b1,buffer^,1);<br>
Move(b2,(buffer+1)^,1);<br>
Move(b3,(buffer+2)^,1);<br>
Move(b4,(buffer+3)^,1);<br>
Move(data[1],(buffer+4)^,len);<br>
SHA1.Update(buffer^,len+4);<br>
setlength(Result,20);<br>
SHA1.Final(Result[1]);<br>
finally<br>
SysFreeMem(buffer);<br>
end;<br>
finally<br>
sha1.free;<br>
end;<br>
end;<br>
<br>
procedure MakeHMAC(text: string; var seed: LongInt;<br>
var hash: string);<br>
begin<br>
Randomize;<br>
seed := Round(Random(MaxLongInt));<br>
hash := GenerateHash(seed,text);<br>
hash := GenerateHash(seed,hash);<br>
end;<br>
<br>
function ValidateHMAC(text: string; seed: LongInt; hmac: string):
boolean;<br>
var hash1, hash2: string;<br>
begin<br>
hash1 := GenerateHash(seed,text);<br>
hash2 := GenerateHash(seed,hash1);<br>
Result := CompareMem(@(hmac[1]),@(hash2[1]),20)<br>
end;<br>
<br>
end.<br>
<br>
<div class="moz-cite-prefix">On 23/03/13 05:28, silvioprog wrote:<br>
</div>
<blockquote
cite="mid:CAKq_V2KotKoPOWY894deuOdjKZUCJaOhLDF9ejyv8hgonmDedg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div style="">Hello,</div>
<div><br>
</div>
<div style="">How to get HMAC_SHA1 using native functions of
FPC?</div>
<div><br>
</div>
<div>HMAC_SHA1: <a moz-do-not-send="true"
href="http://en.wikipedia.org/wiki/Hash-based_message_authentication_code#Examples_of_HMAC_.28MD5.2C_SHA1.2C_SHA256.29">http://en.wikipedia.org/wiki/Hash-based_message_authentication_code#Examples_of_HMAC_.28MD5.2C_SHA1.2C_SHA256.29</a><br>
</div>
<div><br>
</div>
<div style="">Thank you!</div>
<div><br>
</div>
-- <br>
Silvio Clécio<br>
My public projects - <a moz-do-not-send="true"
href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
fpc-pascal maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a></pre>
</blockquote>
<br>
</body>
</html>