Xceed Encryption Library Documentation
Examples / Encrypting and decrypting from file to file (Delphi example)
In This Topic
    Encrypting and decrypting from file to file (Delphi example)
    In This Topic

    Here are two examples for Delphi, one demonstrates encryption from file to file, the other demonstrates decryption from file to file. Both show how to use the Rijndael algorithm.

    Delphi - Encyption Copy Code

    uses XceedEncryptionLib_TLB 

    var
      xEnc : TXceedEncryption; 
      xRijndael : DXceedRijndaelEncryptionMethod; 
      vaBytesRead : OleVariant; 
    begin
      xEnc := TXceedEncryption.Create( self ); 
      xEnc.License( 'your license key' ); 

      xRijndael := CoXceedRijndaelEncryptionMethod.Create();  

      try 
        xRijndael.SetSecretKeyFromPassPhrase( 'This is a weak pass phrase!', 128 ); 

        xEnc. EncryptionMethod := xRijndael; 

        xEnc.ProcessFile( 'c:\temp\source.txt', 0, 0, efpEncrypt, true, 
                          'c:\temp\encrypted.aes', false, vaBytesRead );  

        ShowMessage( 'Encryption successful!' ); 

        xEnc.Free(); 
      except 
        on xErr : Exception do 
          ShowMessage( xErr.Message ); 
      end; 
    end;

    Delphi - Decryption Copy Code

    uses XceedEncryptionLib_TLB 

    var  xEnc : TXceedEncryption; 
      xRijndael : DXceedRijndaelEncryptionMethod; 
      vaBytesRead : OleVariant; 
    begin
      xEnc := TXceedEncryption.Create( self ); 
      xEnc.License( 'your license key' ); 

      xRijndael := CoXceedRijndaelEncryptionMethod.Create();  

      try 
        xRijndael.SetSecretKeyFromPassPhrase( 'This is a weak pass phrase!', 128 ); 

        xEnc. EncryptionMethod := xRijndael; 

        xEnc.ProcessFile( 'c:\temp\encrypted.aes', 0, 0, efpDecrypt, true, 
                        'c:\temp\decrypted.txt', false, vaBytesRead ); 

        ShowMessage( 'Decryption successful!' ); 

        xEnc.Free(); 

        except 
          on xErr : Exception do 
            ShowMessage( xErr.Message ); 
        end; 
    end;