|
@@ -25,15 +25,15 @@ type
|
|
|
THMACMD5Digest = TMD5Digest;
|
|
|
THMACSHA1Digest = TSHA1Digest;
|
|
|
|
|
|
-function HMACMD5Digest(const AKey, AMessage: string): THMACMD5Digest;
|
|
|
+function HMACMD5Digest(const AKey, AMessage: RawByteString): THMACMD5Digest;
|
|
|
function HMACMD5Print(const ADigest: THMACMD5Digest): string; inline;
|
|
|
function HMACMD5Match(const ADigest1, ADigest2: THMACMD5Digest): boolean; inline;
|
|
|
-function HMACMD5(const AKey, AMessage: string): string; inline;
|
|
|
+function HMACMD5(const AKey, AMessage: RawByteString): string; inline;
|
|
|
|
|
|
-function HMACSHA1Digest(const AKey, AMessage: string): THMACSHA1Digest;
|
|
|
+function HMACSHA1Digest(const AKey, AMessage: RawByteString): THMACSHA1Digest;
|
|
|
function HMACSHA1Print(const ADigest: THMACSHA1Digest): string; inline;
|
|
|
function HMACSHA1Match(const ADigest1, ADigest2: THMACSHA1Digest): boolean; inline;
|
|
|
-function HMACSHA1(const AKey, AMessage: string): string; inline;
|
|
|
+function HMACSHA1(const AKey, AMessage: RawByteString): string; inline;
|
|
|
|
|
|
implementation
|
|
|
|
|
@@ -43,10 +43,10 @@ const
|
|
|
SHA1_BLOCK_SIZE = 64;
|
|
|
SHA1_BLOCK_COUNT = 20;
|
|
|
|
|
|
-function MD5Raw(var ABuffer; const ABufferLength: PtrUInt): string;
|
|
|
+function MD5Raw(var ABuffer; const ABufferLength: PtrUInt): RawByteString;
|
|
|
var
|
|
|
I: Byte;
|
|
|
- VDest: PChar;
|
|
|
+ VDest: PAnsiChar;
|
|
|
VDigest: TMD5Digest;
|
|
|
VContext: TMD5Context;
|
|
|
begin
|
|
@@ -57,17 +57,17 @@ begin
|
|
|
VDest := Pointer(Result);
|
|
|
for I := 0 to MD5_BLOCK_COUNT - 1 do
|
|
|
begin
|
|
|
- VDest^ := Char(VDigest[I]);
|
|
|
+ VDest^ := AnsiChar(VDigest[I]);
|
|
|
Inc(VDest);
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
-function HMACMD5Digest(const AKey, AMessage: string): THMACMD5Digest;
|
|
|
+function HMACMD5Digest(const AKey, AMessage: RawByteString): THMACMD5Digest;
|
|
|
var
|
|
|
I: Byte;
|
|
|
VLength: PtrUInt;
|
|
|
- PKey, POPad, PIPad: PChar;
|
|
|
- VKey, VOPad, VIPad: string;
|
|
|
+ PKey, POPad, PIPad: PAnsiChar;
|
|
|
+ VKey, VOPad, VIPad: RawByteString;
|
|
|
begin
|
|
|
VLength := Length(AKey);
|
|
|
if VLength > MD5_BLOCK_SIZE then
|
|
@@ -83,16 +83,16 @@ begin
|
|
|
VKey := AKey + VKey;
|
|
|
end;
|
|
|
SetLength(VOPad, MD5_BLOCK_SIZE);
|
|
|
- POPad := PChar(VOPad);
|
|
|
+ POPad := PAnsiChar(VOPad);
|
|
|
FillChar(POPad^, MD5_BLOCK_SIZE, $5c);
|
|
|
SetLength(VIPad, MD5_BLOCK_SIZE);
|
|
|
- PIPad := PChar(VIPad);
|
|
|
+ PIPad := PAnsiChar(VIPad);
|
|
|
FillChar(PIPad^, MD5_BLOCK_SIZE, $36);
|
|
|
- PKey := PChar(VKey);
|
|
|
+ PKey := PAnsiChar(VKey);
|
|
|
for I := 1 to VLength do
|
|
|
begin
|
|
|
- POPad^ := Char(Ord(POPad^) xor Ord(PKey^));
|
|
|
- PIPad^ := Char(Ord(PIPad^) xor Ord(PKey^));
|
|
|
+ POPad^ := AnsiChar(Ord(POPad^) xor Ord(PKey^));
|
|
|
+ PIPad^ := AnsiChar(Ord(PIPad^) xor Ord(PKey^));
|
|
|
Inc(POPad);
|
|
|
Inc(PIPad);
|
|
|
Inc(PKey);
|
|
@@ -111,15 +111,15 @@ begin
|
|
|
Result := MD5Match(ADigest1, ADigest2);
|
|
|
end;
|
|
|
|
|
|
-function HMACMD5(const AKey, AMessage: string): string;
|
|
|
+function HMACMD5(const AKey, AMessage: RawByteString): string;
|
|
|
begin
|
|
|
Result := HMACMD5Print(HMACMD5Digest(AKey, AMessage));
|
|
|
end;
|
|
|
|
|
|
-function SHA1Raw(const ABuffer; const ABufferLength: PtrUInt): string;
|
|
|
+function SHA1Raw(const ABuffer; const ABufferLength: PtrUInt): RawByteString;
|
|
|
var
|
|
|
I: Byte;
|
|
|
- VDest: PChar;
|
|
|
+ VDest: PAnsiChar;
|
|
|
VDigest: TSHA1Digest;
|
|
|
VContext: TSHA1Context;
|
|
|
begin
|
|
@@ -130,17 +130,17 @@ begin
|
|
|
VDest := Pointer(Result);
|
|
|
for I := 0 to SHA1_BLOCK_COUNT - 1 do
|
|
|
begin
|
|
|
- VDest^ := Char(VDigest[I]);
|
|
|
+ VDest^ := AnsiChar(VDigest[I]);
|
|
|
Inc(VDest);
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
-function HMACSHA1Digest(const AKey, AMessage: string): THMACSHA1Digest;
|
|
|
+function HMACSHA1Digest(const AKey, AMessage: RawByteString): THMACSHA1Digest;
|
|
|
var
|
|
|
I: Byte;
|
|
|
VLength: PtrUInt;
|
|
|
- PKey, POPad, PIPad: PChar;
|
|
|
- VKey, VOPad, VIPad: string;
|
|
|
+ PKey, POPad, PIPad: PAnsiChar;
|
|
|
+ VKey, VOPad, VIPad: RawBytestring;
|
|
|
begin
|
|
|
// Set up masking block from key.
|
|
|
VLength := Length(AKey);
|
|
@@ -156,18 +156,18 @@ begin
|
|
|
FillChar(Pointer(VKey)^, SHA1_BLOCK_SIZE - VLength, #0);
|
|
|
VKey := AKey + VKey; // VKEY now has length SHA1_BLOCK_SIZE
|
|
|
end;
|
|
|
- PKey := PChar(VKey);
|
|
|
+ PKey := PAnsiChar(VKey);
|
|
|
// Padding blocks
|
|
|
SetLength(VOPad, SHA1_BLOCK_SIZE);
|
|
|
- POPad := PChar(VOPad);
|
|
|
+ POPad := PAnsiChar(VOPad);
|
|
|
FillChar(POPad^, SHA1_BLOCK_SIZE, $5c);
|
|
|
SetLength(VIPad, SHA1_BLOCK_SIZE);
|
|
|
- PIPad := PChar(VIPad);
|
|
|
+ PIPad := PAnsiChar(VIPad);
|
|
|
FillChar(PIPad^, SHA1_BLOCK_SIZE, $36);
|
|
|
for I := 1 to SHA1_BLOCK_SIZE do
|
|
|
begin
|
|
|
- POPad^ := Char(Ord(POPad^) xor Ord(PKey^));
|
|
|
- PIPad^ := Char(Ord(PIPad^) xor Ord(PKey^));
|
|
|
+ POPad^ := AnsiChar(Ord(POPad^) xor Ord(PKey^));
|
|
|
+ PIPad^ := AnsiChar(Ord(PIPad^) xor Ord(PKey^));
|
|
|
Inc(POPad);
|
|
|
Inc(PIPad);
|
|
|
Inc(PKey);
|
|
@@ -186,7 +186,7 @@ begin
|
|
|
Result := SHA1Match(ADigest1, ADigest2);
|
|
|
end;
|
|
|
|
|
|
-function HMACSHA1(const AKey, AMessage: string): string;
|
|
|
+function HMACSHA1(const AKey, AMessage: RawByteString): string;
|
|
|
begin
|
|
|
Result := HMACSHA1Print(HMACSHA1Digest(AKey, AMessage));
|
|
|
end;
|