title: How to AES-128 encrypt a string using a password in Delphi and decrypt in C#?
body: <p>I'd like to AES-128 encrypt a string in Delphi with a password.  I'd like to upload this to my server and be able to decrypt given the same password in C#.  </p>
  
  <p>In Delphi, I'm using TurboPower LockBox 3:</p>
  
  <pre><code>function EncryptText_AES_128(input: string; password: string): string;
  var
    Codec: TCodec;
    CipherText: AnsiString;
  begin
    Codec := TCodec.Create(nil);
    try
      Codec.CryptoLibrary := TCryptographicLibrary.Create(Codec);
      //
      Codec.StreamCipherId := BlockCipher_ProgID;
      Codec.BlockCipherId := Format(AES_ProgId, [128]);
      Codec.ChainModeId := CBC_ProgId;
      //
      Codec.Password := Password;
      Codec.EncryptString(input, CipherText);
      //
      Result := string(CipherText);
    finally
      Codec.Free;
    end;
  end;
  </code></pre>
  
  <p><strong>How can I decrypt the resulting string in C#?</strong>  I can change the Delphi code.  Nothing is in production yet.  I'm not even stuck on using LockBox.  But, I would like to avoid putting this in a DLL for P/Invoke.</p>
  
  <p>(My example shows that my encrypted sequence is itself a string.  This is not a requirement for me.  A stream of bytes is fine.)</p>