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
Delphi tips navigator:
» LastPos function - last occurrence of one string within another
« How to add the "Select All (CTRL+A)" functionality to TMemo/TDBMemo

