Delphi Crypto Wrapper

Provides a wrapper to common calls to the Microsoft Crypto API as well as other useful crypto related routines.

Public Interface
TwpsDigestType = (dtMD5, dtSHA1);

TwpsCrypto = class(TObject)
public
 function  DecryptValue(const Value: string; const SecretPhrase: string): string;
 function  EncryptValue(const Value: string; const SecretPhrase: string): string;
 function  DecodeFromBase64String(const Value: string): string;
 function  EncodeToBase64String(const Value: string): string;
 procedure GenerateRandomNumbers(ByteArray: array of byte);
 function  GenerateRandomString(Size: integer): string;
 function  GetMD5DigestValue(const Value: string): string;
 function  GetDigestValue(const Value: string; DigestType: TwpsDigestType): string;
end;
      
Base64 Sample Code
procedure Base64Sample;
var
  Crypto: TwpsCrypto;
  EncodedString: string;
  DecodedString: string;
  Value: string;
begin
  Value := 'This is text to be encoded.';

  Crypto := TwpsCrypto.Create;
  try
    // Encode value.
    EncodedString := Crypto.EncodeToBase64String(Value);

    // Decode encoded value.
    DecodedString := Crypto.DecodeFromBase64String(EncodedString);
  finally
    Crypto.Free;
  end;
end;
      
Encrypt Decrypt Sample Code
procedure EncryptDecryptValueSample;
const
  ValueToEncrypt = 'http://www.whitepeaksoftware.com/';
  SecretPhrase = 'White Peak Software';
var
  EncryptedValue: string;
  DecryptedValue: string;
  Crypto: TwpsCrypto;
begin
  Crypto := TwpsCrypto.Create;
  try
    EncryptedValue := Crypto.EncryptValue(ValueToEncrypt, SecretPhrase);
    DecryptedValue := Crypto.DecryptValue(EncryptedValue, SecretPhrase);
  finally
    Crypto.Free;
  end;
end;
      

Warranty

WPS Delphi Library software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

License

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the certain restrictions (see individual source code files for restrictions).

About White Peak Software | Site Map | Privacy Policy
Copyright © 2003-2008 White Peak Software Inc. All rights reserved.