#1 Re: Other components » AES (Rijndael)? » 2022-09-15 16:06:23

thx ab.
I made it with help from this example:
https://synopse.info/forum/viewtopic.php?id=4821

BAT something is strange!
if I use Indy TCP Client:

IdTCPClient1.Connect;
IdTCPClient1.Disconnect;

and then call decrypt I get always "Invalid input"!
without using IdTCPClient1 is everything fine!

#2 Other components » AES (Rijndael)? » 2022-09-15 10:37:16

teleport.soccer
Replies: 2

can someone help me to implement this method in delphi:

private static string DecryptString(string content, string password)
{
    Rijndael aes;
    byte[] retVal = null;
    byte[] contentBytes;
    byte[] passwordBytes;
    byte[] ivBytes;
    try
    {
        //Get the content as byte[]
        contentBytes = Convert.FromBase64String(content);

        //Create the password and initial vector bytes
        passwordBytes = new byte[32];
        ivBytes = new byte[16];
        Array.Copy(Encoding.Unicode.GetBytes(password), passwordBytes,         
                   Encoding.Unicode.GetBytes(password).Length);
        Array.Copy(passwordBytes, ivBytes, 16);


        //Create the cryptograpy object
        aes = Rijndael.Create();
        aes.Key = passwordBytes;
        aes.IV = ivBytes;
        aes.Padding = PaddingMode.PKCS7;
        //Decrypt
        retVal = aes.CreateDecryptor().TransformFinalBlock(contentBytes, 0,
                 contentBytes.Length);
    }
    catch
    {
    }
    aes = null;
    contentBytes = null;
    passwordBytes = null;
    ivBytes = null;
    return Encoding.Unicode.GetString(retVal)
}

I've tried with TAESCFB, but I always get "Invalid input"!
Any advice is welcome.

#3 Re: mORMot 1 » DynArrayLoadJSON problem » 2019-01-31 10:53:41

thx,
now is result of DynArrayLoadJSON not nil!

#4 Re: mORMot 1 » DynArrayLoadJSON problem » 2019-01-30 07:53:59

what's wrong with this code?

program SynopseTest;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  mORMot,
  SynCommons;

type
  TTestRecord = packed record
    AAA: integer;
    BBB: integer;
  end;
  TTestDynArray = array of TTestRecord;


procedure Test1;
const
  __TTestRecord = 'AAA: integer; BBB: integer';
var
  array1: TTestDynArray;
  str: RawUTF8;
begin
  TTextWriter.RegisterCustomJSONSerializerFromText(
    TypeInfo(TTestRecord),__TTestRecord); //.Options := [soReadIgnoreUnknownFields,soWriteHumanReadable];
  str := '[{"AAA":1,"BBB":2},{"AAA":3,"BBB":4}]';
  if (DynArrayLoadJSON(array1, @str[1], TypeInfo(TTestDynArray)) <> nil) then begin
    Writeln('ok');
  end else Writeln('not ok');
end;

procedure Test2;
var
  array1, array2: TTestDynArray;
  str: RawUTF8;
begin
  SetLength(array1, 2);
  array1[0].AAA := 1;
  array1[0].BBB := 2;
  array1[1].AAA := 3;
  array1[1].BBB := 4;
  str := DynArraySaveJSON(array1,TypeInfo(TTestDynArray));
  Writeln(str); // [8589934593,17179869187]   - why?
  if (str = '[{"AAA":1,"BBB":2},{"AAA":3,"BBB":4}]') then begin
    Writeln('ok');
  end else Writeln('not ok');
end;

begin
  try
    Test1;
    Test2;
    ConsoleWaitForEnterKey;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

output:

not ok
[8589934593,17179869187]
not ok

#5 Re: mORMot 1 » DynArrayLoadJSON problem » 2019-01-29 14:25:32

for Test2 my problem is on line:

if (DynArrayLoadJSON(ar, PUTF8Char(TestRequest), TypeInfo(TTiTestRecordDynArray)) <> nil) then begin

result DynArrayLoadJSON is always nil!!!

and for Test1 browser return:

{
"errorCode":406,
"errorText":"sicShared execution failed (probably due to bad input parameters) for TestService.Test1"
}

#6 mORMot 1 » DynArrayLoadJSON problem » 2019-01-29 13:55:21

teleport.soccer
Replies: 5

hi,
I'm trying to parse json with "DynArrayLoadJSON", but it seems not working correctly!

http://127.0.0.1:60401/myroot/TestService/Test1?TestRequest=[{"A":1,"B":2},{"A":3,"B":4}]
http://127.0.0.1:60401/myroot/TestService/Test2?TestRequest=[{"A":1,"B":2},{"A":3,"B":4}]
TTiTestRecord = packed record
    A: Integer;
    B: Integer;
    //C: RawUTF8; // <-- with this line, it's ok ???
  end;
  TTiTestRecordDynArray = array of TTiTestRecord;

ITestService = interface(IInvokable)
    ['{FA5628E6-1929-4382-B1D9-860CE4E67A6D}']
    function Test1(const TestRequest: TTiTestRecordDynArray): TServiceCustomAnswer;
    function Test2(TestRequest: RawUTF8): TServiceCustomAnswer;
  end;

....

function TTestService.Test1(const TestRequest: TTiTestRecordDynArray): TServiceCustomAnswer;
var 
  str: RawUTF8;
begin
  Result.Header := TEXT_CONTENT_TYPE_HEADER;
  Result.Status := HTTP_SERVERERROR;
  try
    str := RecordSaveJSON(TestRequest, TypeInfo(TTiTestRecordDynArray));
    Result.Status := HTTP_SUCCESS;
    Result.Content := RawByteString(str);
  except on E: Exception do
    Result.Content := RawByteString(E.Message);
  end;
end;

function TTestService.Test2(TestRequest: RawUTF8): TServiceCustomAnswer;
var 
  ar: TTiTestRecordDynArray;
begin
  Result.Header := TEXT_CONTENT_TYPE_HEADER;
  Result.Status := HTTP_SERVERERROR;
  try
    if (DynArrayLoadJSON(ar, PUTF8Char(TestRequest), TypeInfo(TTiTestRecordDynArray)) <> nil) then begin
      Result.Status := HTTP_SUCCESS;
      Result.Header := JSON_CONTENT_TYPE;
      Result.Content := RecordSaveJSON(ar, TypeInfo(TTiTestRecordDynArray));
    end;
  except on E: Exception do
    Result.Content := RawByteString(E.Message);
  end;
end;

if in record RawUTF8-field exists then is everything fine, why?

Board footer

Powered by FluxBB