Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Component for encryption

I need an encryption library (VCL or not) that will work with Delphi XE2 & unicode strings,
64 & 32 bit compiles.
I need it in order to store data in a database.

like image 925
Panos Kal. Avatar asked Mar 02 '12 09:03

Panos Kal.


3 Answers

The Delphi Cryptography Page (DCPCrypt) is an open source library written by David Barton ([email protected]) http://www.cityinthesky.co.uk/opensource/dcpcrypt that provides a collection of very comprehensive, free to export, symmetric key, cryptographic components.

like image 50
PA. Avatar answered Oct 31 '22 03:10

PA.


I found this in Embarcadero forum, a version of DCPCrypt that has been updated by a user.
Here is the code if anyone stumbles into the same problem.

I also found this library (TurboPower LockBox) that supports Delphi Xe2

like image 42
Panos Kal. Avatar answered Oct 31 '22 04:10

Panos Kal.


All standard encryption algorithms operate on bytes or bits. You should be able to use any implementation that supports Delphi XE2 Win32 and Win64, at least as long as you yourself take responsibility for decoding and encoding your unicode strings. There is a TEncoding class in the RTL SysUtils unit that you should use for converting your unicode strings to and from TBytes, using the encoding of your own choice.

The reason many Delphi implementations of encryption algorithms take string parameters, is mainly historical, and shouldn't be understood as if the implementations necessarily know what a character or a string is. Many Delphi versions ago, before the TBytes type was added to the VCL/RTL, there were five ways to declare such methods, and using strings was often the most convenient one.

  1. Untyped const and var parameters. This is what the Move procedure and TStream has used. The downside with this is that the most common usage error is to try to pass a reference typed variable, such as a string or a dynamic array, without dereferencing it first.
  2. Untyped pointers. Similar problem. Developers who come from e.g. a Basic or Java background aren't necessarily familiar with the concept of pointers and reference types.
  3. Open array parameters. Can be accessed by element only, so they mix badly with encryption algorithms that are implemented to operate on continuous blocks of memory.
  4. A library specific TBytes = array of Byte type. The Delphi language is strongly typed, so this would only work if the application developer used the same library specific type to begin with, which would rapidly grow infeasible, e.g. if the developer had to firstly grab a TnxBytes from a NexusDB database, convert it into a StreamSec tBytes to encrypt it, and then into an Indy TIdBytes to pass it over a TIdTCPConnection.
  5. (Ansi)strings. Let's face it. For all of the above reasons (and some more, such as language and RTL support), most developers used strings as variable sized memory buffers.
like image 20
Henrick Hellström Avatar answered Oct 31 '22 05:10

Henrick Hellström