#1 2024-11-14 09:16:42

George
Member
Registered: 2016-04-05
Posts: 142

Data encrypted in 1.18 cannot be decrypted in 2.3 | AES256CTR

Hello,

After upgrading to the latest stable version, I found that long enough data encrypted in 1.18 cannot be decrypted in 2.3.8854.
Lazarus 2.0.12; FPC: 3.2.0.

Is it a bug (somewhere in the padding)?

// Data to encrypt: "SOME TEST DATA  SOME TEST DATA SOME TEST DATA SOME TEST DATA SOME TEST DATA SOME TEST DATA SOME TEST DATA SOME TEST DATA SOME TEST DATA SOME TEST DATA SOME TEST DATA SOME TEST DATA"

  function EncryptAES256CTR(Data: Pointer; DataLength: Int64; const Key: THash256; out EncryptedData: RawByteString): Boolean;
  var
    AES:               TAESCTR;
    EncryptedDataSize: Int64;
  begin
    Result := True;
     try
      EncryptedData := '';
      AES := TAESCTR.Create(Key);
       try
        EncryptedDataSize := AES.EncryptPKCS7Length(DataLength, True);
        SetString(EncryptedData, nil, EncryptedDataSize);
        Result := AES.EncryptPKCS7Buffer(Data, @EncryptedData[1], DataLength, EncryptedDataSize, True);
       except
        Result := False;
       end;
      AES.Free;
     except
      Result := False;
     end;
  end;

// ===

  function DecryptAES256CTR(Data: Pointer; DataLength: Int64; const Key: THash256; out DecryptedData: RawByteString): Boolean;
  var
    AES: TAESCTR;
  begin
    Result := True;
     try
      AES := TAESCTR.Create(Key);
       try
        DecryptedData := AES.DecryptPKCS7Buffer(Data, DataLength, True);
       except
        Result := False;
       end;
      AES.Free;
     except
      Result := False;
     end;
  end;

Offline

#2 2024-11-14 15:49:54

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

Re: Data encrypted in 1.18 cannot be decrypted in 2.3 | AES256CTR

If you look at the documentation / source code you would find for mORMot 2 TAesCtr:

WARNING: BREAKING CHANGE mORMot 1.18 SynCrypto's TAESCTR is TAesC64    

Offline

#3 2024-11-14 16:28:18

George
Member
Registered: 2016-04-05
Posts: 142

Re: Data encrypted in 1.18 cannot be decrypted in 2.3 | AES256CTR

Thank you!
You are right as always.

Offline

Board footer

Powered by FluxBB