Search code examples
delphidelphi-7

Delphi 7 - Not Enough Actual Parameters


I'm so new to Delphi 7, also in this forum and I've questions.

I have successfully converted an url string to hex using Jorlen Young's function StrToHex - Advanced Encryption Standard (AES) Interface Unit v1.3!.

But, when I implement his function EncryptString, then I got error at the very bottom of my code: Encrypt := EncryptString('www.website.com'); with the following messsage:

[Hint] Unit1.pas(xx): Variable 'st' is declared but never used in 'EncryptString'
[Error] Unit1.pas(xx): Not enough actual parameters
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'

Could you give me some tips in how to implement the "Key" and "KeyBit" option into my syntax: Encrypt := EncryptString('www.website.com'); ?

I would appreciate any help.

...here is my code :

    .....................
    .....................

type
  TKeyBit = (kb128, kb192, kb256);
    .....................
    .....................
    procedure IdMappedPortTCP1Execute(AThread: TIdMappedPortThread);

  private
    { Private declarations }
  public
{ Public declarations }
  end;

implementation

function StrToHex(Const str: Ansistring): Ansistring;
asm
    push ebx
    push esi
    push edi
    test eax,eax
    jz   @@Exit
    mov  esi,edx
    mov  edi,eax
    mov  edx,[eax-4]
    test edx,edx
    je   @@Exit      {Length(S) = 0}
    mov  ecx,edx
    Push ecx
    shl  edx,1
    mov  eax,esi
    {$IFDEF VER210}
    movzx ecx, word ptr [edi-12]
    {$ENDIF}
    call System.@LStrSetLength
    mov  eax,esi
    Call UniqueString
    Pop   ecx
  @@SetHex:
    xor  edx,edx
    mov  dl, [edi]
    mov  ebx,edx
    shr  edx,4
    mov  dl,byte ptr[edx+@@HexChar]
    mov  [eax],dl
    and  ebx,$0F
    mov  dl,byte ptr[ebx+@@HexChar]
    inc  eax
    mov  [eax],dl
    inc  edi
    inc  eax
    loop @@SetHex
  @@Exit:
    pop  edi
    pop  esi
    pop  ebx
    ret
  @@HexChar: db '0123456789ABCDEF'
end;

function EncryptString(Value: AnsiString; Key: AnsiString; KeyBit: TKeyBit = kb128): AnsiString;
var
  {$IFDEF VER210}
  SS,DS: TMemoryStream;
  {$ELSE}
  SS, DS: TStringStream;
  {$ENDIF}
  Size: Int64;
  AESKey128: TAESKey128;
  AESKey192: TAESKey192;
  AESKey256: TAESKey256;
  st: AnsiString;
begin
  Result := '';
  {$IFDEF VER210}
    ss := TMemoryStream.Create;
    SS.WriteBuffer(PAnsiChar(Value)^,Length(Value));
    DS := TMemoryStream.Create;
  {$ELSE}
    SS := TStringStream.Create(Value);
    DS := TStringStream.Create('');
  {$ENDIF}
  try
    Size := SS.Size;
    DS.WriteBuffer(Size, SizeOf(Size));
    if KeyBit = kb128 then
    begin
      FillChar(AESKey128, SizeOf(AESKey128), 0 );
      Move(PAnsiChar(Key)^, AESKey128, Min(SizeOf(AESKey128), Length(Key)));
      EncryptAESStreamECB(SS, 0, AESKey128, DS);
    end;
    if KeyBit = kb192 then
    begin
      FillChar(AESKey192, SizeOf(AESKey192), 0 );
      Move(PAnsiChar(Key)^, AESKey192, Min(SizeOf(AESKey192), Length(Key)));
      EncryptAESStreamECB(SS, 0, AESKey192, DS);
    end;
    if KeyBit = kb256 then
    begin
      FillChar(AESKey256, SizeOf(AESKey256), 0 );
      Move(PAnsiChar(Key)^, AESKey256, Min(SizeOf(AESKey256), Length(Key)));
      EncryptAESStreamECB(SS, 0, AESKey256, DS);
    end;
    {$IFDEF VER210}
      SetLength(st,Ds.Size);
      DS.Position := 0;
      DS.ReadBuffer(PAnsiChar(st)^,DS.Size);
      Result := StrToHex(st);
    {$ELSE}
      Result := StrToHex(DS.DataString);
    {$ENDIF}
  finally
    SS.Free;
    DS.Free;
  end;
end;

procedure TForm1.IdMappedPortTCP1Execute(AThread: TIdMappedPortThread);
var Payload, Encrypt:String;
begin

Encrypt := EncryptString('www.website.com');

  if Pos('CONNECT',AThread.NetData)<>0 then
    begin
      if host.Text = 'Operator' then
        begin
           Athread.OutboundClient.Write(Athread.NetData+#13#10);
           Payload := 'GET http://'+Encrypt+'/ HTTP/1.1'+#13#10;
           Athread.NetData:= Athread.NetData+Payload;
        end;
    end;
end.

Cheers, RzV


Solution

  • EncryptString has 2 required and one optional parameter. You need at least to provide the key.