#1 2021-10-14 20:43:57

ertank
Member
Registered: 2016-03-16
Posts: 163

AES on Android

Hello,

I am using Delphi 10.4.2, targeting Android32.

There is a previously developed REST web service with MARS Curiosity project which is using mORMot encryption routines. That web server running on Windows and is just fine. Now, I have to develop a small mobile application that is consuming some methods on that web service. Unfortunately, I failed to compile below function on Android32. I get error for SynLZ unit for its asm instructions. It uses SynCommons and SynCrypt units on Win32 platform.

function EncryptItAES(const s: string; const AKey: TBytes): string;
var
  Key: TSHA256Digest;
  Aes: TAESCFB;
  _s: RawByteString;
begin
  Result := EmptyStr;
  Key := SHA256Digest(Pointer(AKey), Length(AKey));
  Aes := TAESCFB.Create(Key, 256);
  try
    _s := StringToUTF8(s);
    _s := BinToBase64(Aes.EncryptPKCS7(_s, True));
    Result := UTF8ToString(_s);
  finally
    Aes.Free();
  end;
end;

1) I wonder if I use mORMot2 encryption routines under Android32 and write similar function to above?
2) I can use alternative AES encryption library for Android32. I just don't know how above code each time produce different encrypt data for same input. I appreciate instructions on how to develop same logic using AES library that compiles under Android32? I am confused by checking sources to figure this out.

Thanks & Regards,
Ertan

Offline

#2 2021-10-15 06:52:25

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,238
Website

Re: AES on Android

Hello

1) There is no Android + Delphi support with mORMOt 1 and mORMot 2 - only with FPC.

2) Our implementation of SHA256 + CFB + PKCS7 are standards, so an alternative library would do.

Offline

#3 2021-10-15 08:02:35

ertank
Member
Registered: 2016-03-16
Posts: 163

Re: AES on Android

Hello,

I was more asking about (2) "IVAtBeginning" implementation. This is the part I could not figure.

Offline

#4 2021-10-15 09:05:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,238
Website

Re: AES on Android

It means that the random 16 bytes of IV are put at the beginning of the output stream, as documented:

    // - if IVAtBeginning is TRUE, a random Initialization Vector will be
    // generated by TAesPrng and stored at the beginning of the output buffer

Offline

Board footer

Powered by FluxBB