EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Problem with ElAESSymmetricCrypto

Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.
#14427
Posted: 09/10/2010 02:09:37
by David MICHEL (Standard support level)
Joined: 09/23/2009
Posts: 48

Hello,

I noted a difference between two tools in coding. This difference poses sometimes concern on the side of the waiter which does not manage to decipher my data.

To quantify, I use the TElAESSymmetricCrypto.Encrypt function, in mode aes 128 cbc.

Code
function TChiffrement.ChiffrementAES(fnSource, fnCleTrans: TFileName): TFileName;
var
  Chiffrement  : TElAESSymmetricCrypto;    //Chiffrement
  CleTransact  : TElSymmetricKeyMaterial;

  fsCleTrans   : TFileStream;
  fsSource     : TFileStream;
  fsDest       : TFileStream;

  fichDataChif : TFileName;
  fichCleTrans : TFileName;

  IV           : ByteArray;
  Key          : ByteArray;
begin

  Chiffrement := TElAESSymmetricCrypto.Create(cmCBC); //SB_ALGORITHM_CNT_AES128
  CleTransact := TElSymmetricKeyMaterial.Create();
  try
    try

      fsCleTrans := TFileStream.Create(fnCleTrans, fmOpenRead or fmShareDenyWrite);
      try

        SetLength(Key,16);
        fsCleTrans.ReadBuffer(Pointer(Key)^,length(Key));
        CleTransact.Key := Key;

      finally
        FreeAndNil(fsCleTrans);
        Finalize(Key);
      end;

      SetLength(IV,16);
      CleTransact.IV := IV;

      Finalize(IV);

      Chiffrement.Padding     := cpNone;
      Chiffrement.KeyMaterial := CleTransact;

      fichDataChif := UFonctions.ConstructCheminDest(Copy(fnSource, 1, length(fnSource)- 6), '_2.chf');

      fsSource := TFileStream.Create(fnSource, fmOpenRead);
      try

        fsDest := TFileStream.Create(fichDataChif, fmCreate);
        try
          Chiffrement.Encrypt(fsSource, fsDest);
        finally
          FreeAndNil(fsDest);
        end;

      finally
        FreeAndNil(fsSource);
      end;

    except
      on E : Exception do begin
        MessageDlg(E.Message, mtError, [mbOk], 0);
        Result := '';
      end;
    end;

    Result := fichDataChif;

  finally
    FreeAndNil(CleTransact);
    FreeAndNil(Chiffrement);
  end;

end;


With OpenSSL, I use the order :

Code
OpenSSL> enc -e -in UserSignatureData_1.zip -out kk.chf -aes-128-cbc -K 21da53cd450c3a1e7b05e72582a9e0b0 -iv 0000000000000000


The result is tiny but this difference poses problem(see the attached file).

Is what this difference is normal and how to correct it.

Thanks in advance,




Sincerely yours,
David MICHEL.
#14430
Posted: 09/10/2010 02:34:06
by Ken Ivanov (EldoS Corp.)

Thank you for contacting us.

Please set the Padding property to cpPKCS5. This should resolve the issue.

Chiffrement.Padding := cpPKCS5;
#14431
Posted: 09/10/2010 03:14:08
by David MICHEL (Standard support level)
Joined: 09/23/2009
Posts: 48

Indeed, this with solved my problem. There is no more difference.
I had not even thought of this parameter.

Thanks for you response,


Sincerely yours,
David MICHEL.

Reply

Statistics

Topic viewed 762 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!