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

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.

For more detailed info please see EncryptString().

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

EncryptString

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

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

o.SetComputeHashSaltBytes(lvSalt)

SetEncryptionKey

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

Set during application startup which makes the key global for the application.

o.SetEncryptionKey(lcKey)

SetEncryptionProvider

o.SetEncryptionProvider(lcProvider,llUseMd5Hashkey)

Requirements

Assembly: wwencryption.prg

See also:

Class wwDotnetBridge

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