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)
Return Value
Decrypted text.
Parameters
lcEncryptedText
The string to decrypt.
lcEncryptionKey
Optional - A pass-phrase used to encrypt the string.
If this string is not set the default static value set in the DLL is used. You can set the global default value at application startup using wwEncryption::SetEncryptionKey
The Encryption key is hashed via MD5 hashing to provide a valid key size for processing
llUseBinHex
Determines if the result binary value is returned as binHex (.T.) or base64 (.F. or default) string value
lcProvider
- TripleDES (default)
- AES
lcCipherMode
Optional cipher mode used to encrypt the value. Defaults to ECB which expects 16 byte keys.
- ECB - auto-sizes
- CBC - 16 bytes, 24 bytes
- CFB
- CTS
- OFB
The default used in wwEncryption use: ECB with MD5 encoding (no salt) which yields a 16 byte fixed length keys passed to the algorithm. When using other cipher modes be sure to check your specs for key length and hash encoding requirements as each mode has its own key size requirements.
lcEncryptionHashAlgorithm
Optionally specify an encryption key algorithm to hash the key to a specific key size (ie. MD5 = 16 bytes). Uses the same modes available in ComputeHash(). Note that key sizes have to match the key requirements of the provider and cipher. ECB cipher commonly works with MD5 hashes to provide the 16 byte key which lets you use non-exact keys.
lcEncryptionKeyHashSalt
Optional salt used to compute a hash for the encryption key.
lcIvKey
IV Vector for AES encryption. Should be 16 characters/bytes.
Example
DO wwEncryption
LOCAL loEnc as wwEncryption
loEnc = CREATEOBJECT("wwEncryption")
lcOrig = "Hello World"
? lcOrig
*** 32 byte key (works best with most formats)
lcKey = "12345678901234567890123456789012"
? lcKey
? LEN(lcKey)
*** Example using Default settings for TripleDES
lcVal = loEnc.EncryptString(lcOrig, lcKey)
? lcVal
lcOrig = loEnc.DecryptString(lcVal, lcKey)
? lcOrig
*** TripleDES explicit
lcVal = loEnc.EncryptString(lcOrig, lcKey, .F., "TripleDES", "ECB", "MD5")
? lcVal
lcOrig = loEnc.DecryptString(lcVal, lcKey, .F., "TripleDES", "ECB", "MD5")
? lcOrig
*** AES Example
*** 16 byte IvKey
lcIvKey = "1234567890123456"
*** Key must be 16 or 24 bytes
lcKey2 = PADR(lcKey, 24)
lcVal = loEnc.EncryptString(lcOrig, lcKey2, .F., "AES", "CBC","","",lcIvKey)
? lcVal
lcOrig = loEnc.EncryptString(lcVal, lcKey2, .F., "AES", "CBC","","",lcIvKey)
? lcOrig
See also:
Class wwEncryption | wwEncryption::EncryptString | TripleDES Encryption Example | AES Encyrption Example© West Wind Technologies, 2023 • Updated: 08/14/21
Comment or report problem with topic