Search results for 'CryptoConfig'. 1 post(s) found.

  1. 2007/10/04 How to encrypt a string
2007/10/04 08:13

How to encrypt a string


If you need to encrypt a string in Delphi for .NET you can use the System.Security.Cryptography namespace. Here's a sample function:

Note: the example below uses MD5 algorithm implementation, for a list of possible implementations read MSDN help for System.Security.Cryptography namespace.

uses System.Security.Cryptography, System.Text;

function Encrypt(const cleanString: string): string;
var
   ue : UnicodeEncoding;
   clearBytes, hashedBytes : array of Byte;
begin
   ue := UnicodeEncoding.Create;
   clearBytes := ue.GetBytes(cleanString) ;
   hashedBytes := (CryptoConfig.CreateFromName('MD5') AS HashAlgorithm).ComputeHash(clearBytes) ;
   Result := BitConverter.ToString(hashedBytes) ;

   //Remove "-"'s
   Result := Result.Replace('-',System.String.Empty) ;
end; (* Encrypt *)


Usage sample:
HashedString := Encrypt('http://delphi.about.com') ;
// HashedString = DC31A33D559C4B6609EEA9A6DA137486

Trackback 3 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 06:08 delete

    moneyideas

  2. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 14:38 delete

    moneyideas

  3. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:41 delete

    moneyideas