| 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
|