|
|
|
Delphi - Encryption, ciphers and hashes (3)
Cipher.Burn - Once we have finished encrypting we use the Burn method to erase all keying information.
Cipher.Free - Finally, as all good programmers should know, we must destroy our objects otherwise they consume memory.
So thats it, we've encrypted a string. How do we get the original unencrypted string back? Good question, lets take a look at another method I made earlier:
function TForm1.DecryptThis(anEncryptedString : string) : string;
var
Cipher: TDCP_cast256;
KeyStr: string;
begin
KeyStr:= 'AcceleratedKeyString';
Cipher:= TDCP_cast256.Create(Self);
Cipher.InitStr(KeyStr,TDCP_sha1);
result := Cipher.DecryptString(aString);
Cipher.Burn;
Cipher.Free;
end;
|
You will notice that it looks almost exactly the same as the encrypt method. Well, you're right, that's the beauty of the encryption library it makes life so simple. The only difference is that we must call the DecryptString method instead. The returned result of the DecryptString function will be our original unencrypted string again. Notice though that our method isn't very good, we have stored the key phrase as another variable. It would be quite easy to make a mistype and end up in all sorts of trouble. The best location to store your key phrase is either in the Windows registry or as an interface variable inside your application. Thus all classes will access the same variable for encrypting and decrypting every time.So now you know how to encrypt and decrypt strings. Lets take this encryption further and explore the methods for file encryption. Imagine the possibilities for you Delphi applications if you can master encrypting configuration files, text files or sensitive reports. Lets take a look at a file encryption method I made earlier: (continued page 4)
|
|
Featured |
Other popular Delphi resources. Why not try them for yourself?
|
|
Delphi Knowledge Base. Best practices, walkthroughs, tutorials, component advice and more. Solutions and professional designs for Delphi 4, Delphi 5, Delphi 6 and Delphi, 7. Word COM, Excel COM, Outlook COM including code examples for Word OLE, Excel OLE and Outlook OLE. Automating Outlook to create MailItem and send attachments in Delphi. ActiveX, Com. ADO Data Architecture, TMS component pack walk through and code examples. Using Developer Express and example walkthroughs. Date & time conversion routines, video playback and frame manipulation. COM articles, papers, tips, techniques and hints. How to create Word reports and excel spreadsheets using Delphi code and OLE automation. Understanding Delphi encryption and using ciphers, with source code examples of Blowfish, Twofish, and Rijndael. Securing application data and confidential information using open source encryption components. Free encryption dll component. Accessing and managing MS Excel sheets with Delphi. How to retrieve, display and edit Microsoft Excel spreadsheets with Delphi automation. Accessing and managing MS Word documents with Delphi. How to retrieve, display and edit Microsoft Word documents using Delphi automation. Read and write Excel spreadsheets using Delphi code. How to read and write registry entries using Delphi code. Source code examples using Delphi 5, Delphi 6 and Delphi 7. Working with VCL Developer Express components. How to apply grid styles and themes to Delphi applications. Using image columns and shading to improve the grid and treeview appearances. Including examples from ExpressQuantumPack, for Delphi, ExpressPack for Delphi. Developer guides for Developer Express components. All our articles are written by our senior Delphi professionals to help you get the best from your legacy Delphi applications |
|