DECRYPT

The DECRYPT function decrypts strings.

COMMAND SYNTAX

    DECRYPT(string, key, method)

SYNTAX ELEMENTS

string specifies the string to be decrypted.

Key is the value used to decrypt the string. Its use depends on method.

method is a value, which indicates the encryption mechanism to use (see below).

The ENCRYPT and DECRYPT functions that are part of jBC now support the following cipher methods (Defined in JBC.h)

ValueDescription
JBASE_CRYPT_GENERALGeneral-purpose encryption scheme
JBASE_CRYPT_ROT13Simple ROT13 algorithm. (Key not used)
JBASE_CRYPT_XOR11XOR MOD11 algorithm. Uses the first
character of a key as a seed value
JBASE_CRYPT_RC2RC2 algorithm
JBASE_CRYPT_DESDES algorithm
JBASE_CRYPT_3DESThree Key, Triple DES algorithm
JBASE_CRYPT_BLOWFISHBlowfish algorithm
JBASE_CRYPT_AESAES algorithm
JBASE_CRYPT_BASE64(See below)

BASE64 is not really an encryption method, but more of an encoding. The reason for this is that the output of an encryption often results in a binary string. It allows binary data to be represented as a character string. BASE64 operation is not required but is performed in addition to the primary algorithm. e.g. JBASE_CRYPT_RC2_BASE64

ENCRYPT with this method is the same as a DECRYPT with method JBASE_CRYPT_RC2 followed by DECRYPT with method JBASE_CRYPT_BASE64.

DECRYPT with this method is the same as a DECRYPT with method JBASE_CRYPT_BASE64 followed by DECRYPT with method JBASE_CRYPT_RC2.

ValueDescription
JBASE_CRYPT_RC2_BASE64RC2 algorithm
JBASE_CRYPT_DES_BASE64DES algorithm
JBASE_CRYPT_3DES_BASE64Triple DES algorithm
JBASE_CRYPT_BLOWFISH_BASE64Blowfish algorithm

NOTES

See also: ENCRYPT

TAFJ note: JBASE_CRYPT_XOR11 gives the error "java.security.InvalidKeyException: Wrong key size".

TAFJ note 2: JBASE_CRYPT_BLOWFISH_BASE64 gives the result that differs from one in TAFC.

EXAMPLES

    INCLUDE JBC.h
    //
    IF DECRYPT('rknzcyr', '', JBASE_CRYPT_ROT13) = "example" THEN
      CRT "ROT13 ok"
    END
    //
    IF ENCRYPT('g{ehvkm', '9', JBASE_CRYPT_XOR11) = "example" THEN
      CRT "XOR.MOD11 ok"
    END
    //
    cipher = JBASE_CRYPT_BLOWFISH_BASE64
    key    = "Our Very Secret Key"
    str    = "String to encrypt"
    enc = ENCRYPT( str, key, cipher )
    CRT "Encrypted: " : enc
    dec = DECRYPT( enc, key, cipher )
    CRT "Decrypted: " : dec

Displays as output:

     ROT13 ok
     XOR.MOD11 ok
     Encrypted: xuy6DXxUkD32spyfsKEvUtXrsjP7mC+R
     Decrypted: String to encrypt

Last update: Tue, 30 Aug 2022 12:26