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

Hashing

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
  • HMACMD5
  • HMACSHA1
  • HMACSHA256
  • HMAC384
  • HMAC512

CheckSum Creation

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

Custom
  wwEncryption

Remarks

Relies uses the .NET Runtime and the wwDotnetBridge library

Class Members

MemberDescription

ComputeHash

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)

DecryptString

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)

EncryptString

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)

o.wwEncryption.

GetChecksumFromBytes

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

o.GetChecksumFromBytes(lqBytes, lcMode)

GetCheckSumFromFile

Calculates a Checksum from a file using MD5 or SHA256.

o.GetCheckSumFromFile(lcFilename, lcMode)

SetBinHexMode

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.

o.SetBinHexMode(llBinHex)

SetBinHexMode

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.

o.GetBinHexMode()

SetComputeHashSaltBytes

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.

o.SetComputeHashSaltBytes(lvSalt)

SetEncryptionKey

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

o.SetEncryptionKey(lcKey)

SetEncryptionProvider

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

o.SetEncryptionProvider(lcProvider,llUseMd5Hashkey)

Requirements

Assembly: wwencryption.prg

See also:

Class wwDotnetBridge

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