Decrypting a file

Hi All,

I need to be able to decrypt the file created by this line of code:

openssl enc -e -aes256 -a -pass pass:xxxx -in *.zip -out *.cad

and also be able to encrypt a file in a similar manner.

Google tells me we can do OpenSSl in Delphi.

Can you point me to where I start looking?

regards

Brian

I asked ChatGPT how to do it and it came back with the following code. I haven’t tested it so it may or may not work - but hopefully it should give to a place to start.

uses
  IdHash, IdHashMessageDigest, System.Classes, IdCipher;

procedure DecryptFile(const InFile, OutFile, Password: string);
var
  Cipher: TIdCipher;
  Hash: TIdHashMessageDigest5;
  Key: TBytes;
  InStream, OutStream: TFileStream;
begin
  Hash := TIdHashMessageDigest5.Create;
  try
    Key := Hash.HashStringAsBytes(Password);
    Cipher := TIdCipher.Create(nil);
    try
      Cipher.CipherId := 'aes-256-cbc';
      Cipher.Mode := cmCBC;
      Cipher.Password := BytesToString(Key);
      InStream := TFileStream.Create(InFile, fmOpenRead);
      try
        OutStream := TFileStream.Create(OutFile, fmCreate);
        try
          Cipher.DecryptStream(InStream, OutStream, InStream.Size);
        finally
          OutStream.Free;
        end;
      finally
        InStream.Free;
      end;
    finally
      Cipher.Free;
    end;
  finally
    Hash.Free;
  end;
end;

I wonder if it’s plucking example from the Web.