Class wwEncryption

wwEncryption provides helper functions for two-way string encryption and decryption and one-way string Hash generation.

Two-way Encryption

Encryption refers to two-way encrypting and decrypting of data. Two-way encryption is useful for storing things like secret configuration values that need to be encrypted for storage, but have to be read back later for consumption. Very common for storing configuration values, where the values are significant and contain data needed by the application for later retrieval and usage.

This classes Uses TripleDES for two-way encryption using internal logic for two-way encoding, which is suitable only for encoding and decoding using this class (or the .NET wrapper).


One-way hashes are useful for storing authorization or validation data like passwords or document verification keys.

Hashing is always one way, which means you cannot retrieve the original value from a hashed key. To verify a hash the original value (like a password) has to be provided, which is then re-hashed to compare against a previously stored hash.

The most common use case for hashes is password encryption, where passwords are hashed and stored in a data store. Hashes are created when a password is initially created or generated for a user and that initial hash is saved and stored into a data store. Since the hash is one way the original password is not accessible and therefore can't be easily compromised. To verify the hash at runtime, a user provides the password (or whatever value) to verify in plain text. That input is then hashed using the same hashing values as the originally stored hash and compared to the hash in the data store for a match.

Hash Algorithms supported:

  • MD5
  • SHA1
  • SHA256
  • SHA384
  • SHA512
  • HMACSHA256
  • HMAC384
  • HMAC512

CheckSum Creation

There's also support for computing Checksum values from strings and files using MD5 and SHA256 algorithms.l



Relies uses the .NET Runtime and the wwDotnetBridge library

Class Members



Hashes are one-way encrypted values that can be used to store passwords and other secure data that needs to be verified, but does not need to be retrieved in its original format.

o.ComputeHash(lcText, lcAlgorithm, lvHashSalt, llUseBinHex)


Decrypts a string with a pass phrase using TripleDES encryption. The Decrypt function should use the same encryption key that was used to encrypt the string.

o.DecryptString(lcEncryptedText, lcEncryptionKey, llUseBinHex, lcProvider, lcCipherMode, lcEncryptionKeyHashAlgorithm, lcEncryptionKeyHashSalt)


Symmetric two-way encryption with using string key with TripleDES or AES encryption. There are number of configuration options for provider, cipher, IV and optional hash value.

o.EncryptString(lcInput, lcEncryptionKey, llUseBinHex, lcProvider, lcCipherMode, lcEncryptionKeyHashAlgorithm, lcEncryptionKeyHashSalt, lcIvKey)



Calculates a CheckSum from a binary blob using MD5 or SHA256.

o.GetChecksumFromBytes(lqBytes, lcMode)


Calculates a Checksum from a file using MD5 or SHA256.

o.GetCheckSumFromFile(lcFilename, lcMode)


Use this method to switch the global setting for output mode of binary string values for ComputeHash() and EncryptString() to either base64 (default) or binHex.



Retrieves the global setting for output mode of binary string values for ComputeHash() and EncryptString(). Returns .T. if using binHex mode, or .F if using the default base64.



Sets the SaltBytes for the ComputeHash() function globally so when you don't pass the parameter this value is used. Call this at the start of your application.



Sets the default Encryption key for the EncryptString() / DecryptString() methods if the pass phrase is not passed.



Sets the two-way encryption provider used for EncryptString() and DecryptString() as well as whether to optional encode the encryption key with MD5.



Assembly: wwencryption.prg

See also:

Class wwDotnetBridge

© West Wind Technologies, 2024 • Updated: 05/26/21
Comment or report problem with topic