All Products
Search
Document Center

PolarDB:DBMS_OBFUSCATION_TOOLKIT

Last Updated:Nov 06, 2025

DBMS_OBFUSCATION_TOOLKIT provides functions and stored procedures that support encryption, decryption, and hash value calculation for RAW and VARCHAR2 data types.

Note

The capabilities of DBMS_OBFUSCATION_TOOLKIT are fully included in DBMS_CRYPTO. Therefore, we recommend that you use DBMS_CRYPTO.

Subprograms

Subprogram

Description

DESEncrypt Function/Procedure

Encrypts data using the DES algorithm

DESDecrypt Function/Procedure

Decrypts data using the DES algorithm

DES3Encrypt Function/Procedure

Encrypts data using the 3DES algorithm

DES3Decrypt Function/Procedure

Decrypts data using the 3DES algorithm

MD5 Function/Procedure

Calculates the MD5 hash value of data

DESGetKey Function/Procedure

Generates a DES encryption key

DES3GetKey Function/Procedure

Generates a 3DES encryption key

Note

The DESEncrypt, DESDecrypt, DES3Encrypt, DES3Decrypt, DESGetKey, and DES3GetKey functions and procedures are only supported in cluster Oracle syntax compatibility 2.0 (minor engine version 2.0.14.17.34.0 and later).

DESEncrypt function

Encrypts VARCHAR2 or RAW type data using the DES algorithm.

VARCHAR2

Syntax

FUNCTION DESEncrypt(input_string     IN  VARCHAR2,
                    key_string       IN  VARCHAR2)
RETURN VARCHAR2;

Parameters

Parameter

Description

input_string

VARCHAR2 data that you want to encrypt.

key_string

VARCHAR2 encryption key.

RAW

Syntax

FUNCTION DESEncrypt(input            IN  RAW,
                    key              IN  RAW)
RETURN RAW;

Parameters

Parameter

Description

input

RAW data that you want to encrypt.

key

RAW encryption key.

Example

DECLARE
    input_data RAW(100);
    key_data RAW(8);
    encrypted_data RAW(200);
BEGIN
    input_data := UTL_RAW.CAST_TO_RAW('Hello World');
    key_data := UTL_RAW.CAST_TO_RAW('12345678');

    encrypted_data := DBMS_OBFUSCATION_TOOLKIT.DESEncrypt(
        input => input_data,
        key => key_data
    );

    DBMS_OUTPUT.PUT_LINE('Encrypted RAW: ' || encrypted_data);
END;

DESEncrypt procedure

Encrypts VARCHAR2 or RAW type data using the DES algorithm.

VARCHAR2

Syntax

PROCEDURE DESEncrypt(input_string     IN     VARCHAR2,
                     key_string       IN     VARCHAR2,
                     encrypted_string OUT    VARCHAR2);

Parameters

Parameter

Description

input_string

VARCHAR2 data that you want to encrypt.

key_string

VARCHAR2 encryption key.

encrypted_string

Output parameter, encrypted VARCHAR2 data.

RAW

Syntax

PROCEDURE DESEncrypt(input            IN     RAW,
                     key              IN     RAW,
                     encrypted_data   OUT    RAW);

Parameters

Parameter

Description

input

RAW data that you want to encrypt.

key

RAW encryption key.

encrypted_data

Output parameter, encrypted RAW data.

Example

DECLARE
    input_str VARCHAR2(100) := 'Hello World';
    key_str VARCHAR2(8) := '12345678';
    encrypted_str VARCHAR2(200);
BEGIN
    DBMS_OBFUSCATION_TOOLKIT.DESEncrypt(
        input_string => input_str,
        key_string => key_str,
        encrypted_string => encrypted_str
    );

    DBMS_OUTPUT.PUT_LINE('Original: ' || input_str);
    DBMS_OUTPUT.PUT_LINE('Encrypted: ' || encrypted_str);
END;

DESDecrypt function

Decrypts VARCHAR2 or RAW type data using the DES algorithm.

VARCHAR2

Syntax

FUNCTION DESDecrypt(input_string     IN     VARCHAR2,
                    key_string       IN     VARCHAR2)
RETURN VARCHAR2;

Parameters

Parameter

Description

input_string

VARCHAR2 data that you want to decrypt.

key_string

VARCHAR2 decryption key.

RAW

Syntax

FUNCTION DESDecrypt(input            IN  RAW,
                    key              IN  RAW)
RETURN RAW;

Parameters

Parameter

Description

input

RAW data that you want to decrypt.

key

RAW decryption key.

Example

DECLARE
    input_str VARCHAR2(100) := 'Hello World';
    key_str VARCHAR2(8) := '12345678';
    encrypted_str VARCHAR2(200);
    decrypted_data VARCHAR2(200);
BEGIN
    encrypted_str := DBMS_OBFUSCATION_TOOLKIT.DESEncrypt(
        input_string => input_str,
        key_string => key_str
    );

    decrypted_data := DBMS_OBFUSCATION_TOOLKIT.DESDecrypt(
        input_string => encrypted_str,
        key_string => key_str
    );

    DBMS_OUTPUT.PUT_LINE('Original: ' || input_str);
    DBMS_OUTPUT.PUT_LINE('Decrypted: ' || decrypted_data);
END;

DESDecrypt procedure

Decrypts VARCHAR2 or RAW type data using the DES algorithm.

VARCHAR2

Syntax

PROCEDURE DESDecrypt(input_string     IN    VARCHAR2,
                     key_string       IN    VARCHAR2,
                     decrypted_string OUT   VARCHAR2);

Parameters

Parameter

Description

input_string

VARCHAR2 data that you want to decrypt.

key_string

VARCHAR2 decryption key.

decrypted_string

Output parameter, decrypted VARCHAR2 data.

RAW

Syntax

PROCEDURE DESDecrypt(input            IN      RAW,
                     key              IN      RAW,
                     decrypted_data   OUT     RAW);

Parameters

Parameter

Description

input

RAW data that you want to decrypt.

key

RAW decryption key.

decrypted_data

Output parameter, decrypted RAW data.

Example

DECLARE
    input_data RAW(100);
    key_data RAW(8);
    encrypted_data RAW(200);
    decrypted_data RAW(200);
BEGIN
    input_data := UTL_RAW.CAST_TO_RAW('Hello World');
    key_data := UTL_RAW.CAST_TO_RAW('12345678');

    DBMS_OBFUSCATION_TOOLKIT.DESEncrypt(
        input => input_data,
        key => key_data,
        encrypted_data => encrypted_data
    );

    DBMS_OBFUSCATION_TOOLKIT.DESDecrypt(
        input => encrypted_data,
        key => key_data,
        decrypted_data => decrypted_data
    );

    DBMS_OUTPUT.PUT_LINE('Input RAW: ' || input_data);
    DBMS_OUTPUT.PUT_LINE('Decrypted RAW: ' || decrypted_data);
END;

DES3Encrypt function

Encrypts VARCHAR2 or RAW type data using the 3DES algorithm.

VARCHAR2

Syntax

FUNCTION DES3Encrypt(input_string  IN VARCHAR2,
                     key_string    IN VARCHAR2,
                     which         IN PLS_INTEGER DEFAULT TwoKeyMode,
                     iv_string     IN VARCHAR2 DEFAULT NULL)
RETURN VARCHAR2;

Parameters

Parameter

Description

input_string

VARCHAR2 data that you want to encrypt.

key_string

VARCHAR2 encryption key.

which

Specifies the 3DES mode:

  • (default) TwoKeyMode.

  • ThreeKeyMode.

iv_string

Initialization vector

RAW

Syntax

FUNCTION DES3Encrypt(input IN RAW,
                     key   IN RAW,
                     which IN PLS_INTEGER DEFAULT TwoKeyMode,
                     iv    IN RAW DEFAULT NULL)
RETURN RAW;

Parameters

Parameter

Description

input

RAW data that you want to encrypt.

key

RAW encryption key.

which

Specifies the 3DES mode:

  • (default) TwoKeyMode.

  • ThreeKeyMode.

iv

Initialization vector

Example

DECLARE
    input_data RAW(100);
    key_data RAW(100);
    encrypted_data RAW(200);
BEGIN
    input_data := UTL_RAW.CAST_TO_RAW('Sensitive Data');
    key_data := UTL_RAW.CAST_TO_RAW('1234567890123456');

    encrypted_data := DBMS_OBFUSCATION_TOOLKIT.DES3Encrypt(
        input => input_data,
        key => key_data,
        which => DBMS_OBFUSCATION_TOOLKIT.TwoKeyMode
    );

    DBMS_OUTPUT.PUT_LINE('3DES Encrypted RAW: ' || encrypted_data);
END;

DES3Encrypt procedure

Encrypts VARCHAR2 or RAW type data using the 3DES algorithm.

VARCHAR2

Syntax

PROCEDURE DES3Encrypt(input_string     IN     VARCHAR2,
                      key_string       IN     VARCHAR2,
                      encrypted_string OUT    VARCHAR2,
                      which            IN     PLS_INTEGER DEFAULT TwoKeyMode,
                      iv_string        IN     VARCHAR2 DEFAULT NULL);

Parameters

Parameter

Description

input_string

VARCHAR2 data that you want to encrypt.

key_string

VARCHAR2 encryption key.

encrypted_data

Output parameter, encrypted VARCHAR2 data.

which

Specifies the 3DES mode:

  • (default) TwoKeyMode.

  • ThreeKeyMode.

iv_string

Initialization vector

Example

DECLARE
    input_str VARCHAR2(100) := 'Sensitive Data';
    key_str VARCHAR2(100) := '1234567890123456';  -- 16-character key
    encrypted_str VARCHAR2(200);
BEGIN
    DBMS_OBFUSCATION_TOOLKIT.DES3Encrypt(
        input_string => input_str,
        key_string => key_str,
        encrypted_string => encrypted_str,
        which => DBMS_OBFUSCATION_TOOLKIT.TwoKeyMode
    );

    DBMS_OUTPUT.PUT_LINE('Original: ' || input_str);
    DBMS_OUTPUT.PUT_LINE('3DES Encrypted: ' || encrypted_str);
END;

RAW

Syntax

PROCEDURE DES3Encrypt(input          IN     RAW,
                      key            IN     RAW,
                      encrypted_data OUT    RAW,
                      which          IN     PLS_INTEGER DEFAULT TwoKeyMode,
                      iv             IN     RAW DEFAULT NULL);

Parameters

Parameter

Description

input

RAW data that you want to encrypt.

key

RAW encryption key.

encrypted_data

Output parameter, encrypted RAW data.

which

Specifies the 3DES mode:

  • (default) TwoKeyMode.

  • ThreeKeyMode.

iv

Initialization vector

Example

DECLARE
    input_data RAW(100);
    key_data RAW(100);
    encrypted_data RAW(200);
BEGIN
    input_data := UTL_RAW.CAST_TO_RAW('Sensitive Data');
    key_data := UTL_RAW.CAST_TO_RAW('123456789012345678901234');

    DBMS_OBFUSCATION_TOOLKIT.DES3Encrypt(
        input => input_data,
        key => key_data,
        encrypted_data => encrypted_data,
        which => DBMS_OBFUSCATION_TOOLKIT.ThreeKeyMode
    );

    DBMS_OUTPUT.PUT_LINE('3DES Encrypted RAW: ' || encrypted_data);
END;

DES3Decrypt function

Decrypts VARCHAR2 or RAW type data using the 3DES algorithm.

VARCHAR2

Syntax

FUNCTION DES3Decrypt(input_string IN VARCHAR2,
                     key_string   IN VARCHAR2,
                     which        IN PLS_INTEGER DEFAULT TwoKeyMode,
                     iv_string    IN VARCHAR2 DEFAULT NULL)
RETURN VARCHAR2;

Parameters

Parameter

Description

input_string

VARCHAR2 data that you want to decrypt.

key_string

VARCHAR2 decryption key.

which

Specifies the 3DES mode:

  • (default) TwoKeyMode.

  • ThreeKeyMode.

iv_string

Initialization vector

RAW

Syntax

FUNCTION DES3Decrypt(input IN RAW,
                     key   IN RAW,
                     which IN PLS_INTEGER DEFAULT TwoKeyMode,
                     iv    IN RAW DEFAULT NULL)
RETURN RAW;

Parameters

Parameter

Description

input

RAW data that you want to decrypt.

key

RAW decryption key.

which

Specifies the 3DES mode:

  • (default) TwoKeyMode.

  • ThreeKeyMode.

iv

Initialization vector

Example

DECLARE
    input_data RAW(100);
    key_data RAW(100);
    encrypted_data RAW(200);
    decrypted_data RAW(200);
BEGIN
    input_data := UTL_RAW.CAST_TO_RAW('Sensitive Data');
    key_data := UTL_RAW.CAST_TO_RAW('1234567890123456');

    encrypted_data := DBMS_OBFUSCATION_TOOLKIT.DES3Encrypt(
        input => input_data,
        key => key_data,
        which => DBMS_OBFUSCATION_TOOLKIT.TwoKeyMode
    );

    decrypted_data := DBMS_OBFUSCATION_TOOLKIT.DES3Decrypt(
        input => encrypted_data,
        key => key_data,
        which => DBMS_OBFUSCATION_TOOLKIT.TwoKeyMode
    );

    DBMS_OUTPUT.PUT_LINE('3DES Input RAW: ' || input_data);
    DBMS_OUTPUT.PUT_LINE('3DES Decrypted RAW: ' || decrypted_data);
END;

DES3Decrypt procedure

Decrypts VARCHAR2 or RAW type data using the 3DES algorithm.

VARCHAR2

Syntax

PROCEDURE DES3Decrypt(input_string     IN     VARCHAR2,
                      key_string       IN     VARCHAR2,
                      decrypted_string OUT    VARCHAR2,
                      which            IN     PLS_INTEGER DEFAULT TwoKeyMode,
                      iv_string        IN     VARCHAR2 DEFAULT NULL);

Parameters

Parameter

Description

input_string

VARCHAR2 data that you want to decrypt.

key_string

VARCHAR2 decryption key.

decrypted_string

Output parameter, decrypted VARCHAR2 data.

which

Specifies the 3DES mode:

  • (default) TwoKeyMode.

  • ThreeKeyMode.

iv_string

Initialization vector

RAW

Syntax

PROCEDURE DES3Decrypt(input          IN     RAW,
                      key            IN     RAW,
                      decrypted_data OUT    RAW,
                      which          IN     PLS_INTEGER DEFAULT TwoKeyMode,
                      iv             IN     RAW DEFAULT NULL);

Parameters

Parameter

Description

input

RAW data that you want to decrypt.

key

RAW decryption key.

decrypted_data

Output parameter, decrypted RAW data.

which

Specifies the 3DES mode:

  • (default) TwoKeyMode.

  • ThreeKeyMode.

iv

Initialization vector

Example

DECLARE
    input_data RAW(100);
    key_data RAW(100);
    encrypted_data RAW(200);
    decrypted_data RAW(200);
BEGIN
    input_data := UTL_RAW.CAST_TO_RAW('Sensitive Data');
    key_data := UTL_RAW.CAST_TO_RAW('1234567890123456');

    DBMS_OBFUSCATION_TOOLKIT.DES3Encrypt(
        input => input_data,
        key => key_data,
        which => DBMS_OBFUSCATION_TOOLKIT.TwoKeyMode,
        encrypted_data => encrypted_data
    );

    DBMS_OBFUSCATION_TOOLKIT.DES3Decrypt(
        input => encrypted_data,
        key => key_data,
        which => DBMS_OBFUSCATION_TOOLKIT.TwoKeyMode,
        decrypted_data => decrypted_data
    );

    DBMS_OUTPUT.PUT_LINE('3DES Input RAW: ' || input_data);
    DBMS_OUTPUT.PUT_LINE('3DES Decrypted RAW: ' || decrypted_data);
END;

MD5 function

Calculates the MD5 hash value of VARCHAR2 or RAW type data.

VARCHAR2

Syntax

FUNCTION md5(input_string IN VARCHAR2) RETURN VARCHAR2;

Parameters

Parameter

Description

input

VARCHAR2 data for which you want to calculate the hash value.

Example

DECLARE
    input_str VARCHAR2(100) := 'Hello World';
    hash_result VARCHAR2(100);
BEGIN
    hash_result := DBMS_OBFUSCATION_TOOLKIT.MD5(input_string => input_str);

    DBMS_OUTPUT.PUT_LINE('Input: ' || input_str);
    DBMS_OUTPUT.PUT_LINE('MD5 Hash: ' || hash_result);
END;

RAW

Syntax

FUNCTION md5(input IN RAW) RETURN RAW;

Parameters

Parameter

Description

input

RAW data for which you want to calculate the hash value.

Example

DECLARE
    input_data RAW(100);
    hash_result RAW(100);
BEGIN
    input_data := UTL_RAW.CAST_TO_RAW('Hello World');
    hash_result := DBMS_OBFUSCATION_TOOLKIT.MD5(input => input_data);

    DBMS_OUTPUT.PUT_LINE('Input RAW: ' || input_data);
    DBMS_OUTPUT.PUT_LINE('MD5 Hash RAW: ' || hash_result);
END;

MD5 procedure

Calculates the MD5 hash value of VARCHAR2 or RAW type data.

VARCHAR2

Syntax

PROCEDURE md5(input_string IN VARCHAR2, checksum_string INOUT VARCHAR2);

Parameters

Parameter

Description

input_string

VARCHAR2 data for which you want to calculate the hash value.

checksum_string

Output parameter, VARCHAR2 type, returns the MD5 hash value.

Example

DECLARE
    input_str VARCHAR2(100) := 'Hello World';
    hash_result VARCHAR2(100);
BEGIN
    DBMS_OBFUSCATION_TOOLKIT.MD5(input_string => input_str, checksum_string => hash_result);

    DBMS_OUTPUT.PUT_LINE('Input: ' || input_str);
    DBMS_OUTPUT.PUT_LINE('MD5 Hash: ' || hash_result);
END;

RAW

Syntax

PROCEDURE md5(input IN RAW, checksum INOUT RAW);

Parameters

Parameter

Description

input

RAW data for which you want to calculate the hash value.

checksum

Output parameter, RAW type, returns the MD5 hash value.

Example

DECLARE
    input_data RAW(100);
    hash_result RAW(100);
BEGIN
    input_data := UTL_RAW.CAST_TO_RAW('Hello World');
    DBMS_OBFUSCATION_TOOLKIT.MD5(input => input_data, checksum => hash_result);

    DBMS_OUTPUT.PUT_LINE('Input RAW: ' || input_data);
    DBMS_OUTPUT.PUT_LINE('MD5 Hash RAW: ' || hash_result);
END;

DESGetKey function

Generates a DES encryption key for VARCHAR2 or RAW format data.

VARCHAR2

Syntax

FUNCTION DESGetKey(seed_string IN VARCHAR2) RETURN VARCHAR2;

Parameters

Parameter

Description

seed

Optional seed value used to generate the key.

Example

DECLARE
    des_key VARCHAR2(100);
    custom_seed VARCHAR2(10) := 'myseed123';
BEGIN
    des_key := DBMS_OBFUSCATION_TOOLKIT.DESGetKey(seed_string => custom_seed);
    DBMS_OUTPUT.PUT_LINE('Generated DES Key with seed: ' || des_key);
END;

RAW

Syntax

FUNCTION DESGetKey(seed IN RAW) RETURN RAW;

Parameters

Parameter

Description

seed

Optional seed value used to generate the key.

Example

DECLARE
    des_key RAW(100);
    custom_seed RAW(10);
BEGIN
    custom_seed := UTL_RAW.CAST_TO_RAW('myseed123');

    des_key := DBMS_OBFUSCATION_TOOLKIT.DESGetKey(seed => custom_seed);
    DBMS_OUTPUT.PUT_LINE('Generated DES Key RAW with seed: ' || des_key);
END;

DESGetKey procedure

Generates a DES encryption key for VARCHAR2 or RAW format data.

VARCHAR2

Syntax

PROCEDURE DESGetKey(seed_string IN     VARCHAR2,
                    key         OUT    VARCHAR2);

Parameters

Parameter

Description

seed_string

Optional seed value used to generate the key.

key

Output parameter, the generated key.

Example

DECLARE
    des_key VARCHAR2(100);
    custom_seed VARCHAR2(10) := 'myseed123';
BEGIN
    DBMS_OBFUSCATION_TOOLKIT.DESGetKey(seed_string => custom_seed, key => des_key);
    DBMS_OUTPUT.PUT_LINE('Generated DES Key with seed: ' || des_key);
END;

RAW

Syntax

PROCEDURE DESGetKey(seed  IN     RAW,
                    key   OUT    RAW);

Parameters

Parameter

Description

seed

Optional seed value used to generate the key.

key

Output parameter, the generated key.

Example

DECLARE
    des_key RAW(100);
    custom_seed RAW(10);
BEGIN
    custom_seed := UTL_RAW.CAST_TO_RAW('myseed123');

    DBMS_OBFUSCATION_TOOLKIT.DESGetKey(seed => custom_seed, key => des_key);
    DBMS_OUTPUT.PUT_LINE('Generated DES Key RAW with seed: ' || des_key);
END;

DES3GetKey function

Generates a 3DES encryption key for VARCHAR2 or RAW format data.

VARCHAR2

Syntax

FUNCTION DES3GetKey(which        IN PLS_INTEGER DEFAULT TwoKeyMode,
                    seed_string  IN VARCHAR2)
RETURN VARCHAR2;

Parameters

Parameter

Description

which

Specifies the 3DES mode:

  • (default) TwoKeyMode.

  • ThreeKeyMode.

seed_string

Optional seed value used to generate the key.

Example

DECLARE
    des3_key VARCHAR2(100);
    custom_seed VARCHAR2(10) := 'myseed123';
BEGIN
    des3_key := DBMS_OBFUSCATION_TOOLKIT.DES3GetKey(
        which => DBMS_OBFUSCATION_TOOLKIT.ThreeKeyMode,
        seed => custom_seed
    );
    DBMS_OUTPUT.PUT_LINE('Generated 3DES ThreeKey: ' || des3_key);
END;

RAW

Syntax

FUNCTION DES3GetKey(which IN PLS_INTEGER DEFAULT TwoKeyMode,
                    seed  IN RAW)
RETURN RAW;

Parameters

Parameter

Description

which

Specifies the 3DES mode:

  • (default) TwoKeyMode.

  • ThreeKeyMode.

seed

Optional seed value used to generate the key.

Example

DECLARE
    des3_key RAW(100);
    custom_seed RAW(10);
BEGIN
    custom_seed := UTL_RAW.CAST_TO_RAW('myseed123');

    des3_key := DBMS_OBFUSCATION_TOOLKIT.DES3GetKey(
        which => DBMS_OBFUSCATION_TOOLKIT.ThreeKeyMode,
        seed => custom_seed
    );
    DBMS_OUTPUT.PUT_LINE('Generated 3DES ThreeKey RAW: ' || des3_key);
END;

DES3GetKey procedure

Generates a 3DES encryption key for VARCHAR2 or RAW format data.

VARCHAR2

Syntax

PROCEDURE DES3GetKey(which       IN     PLS_INTEGER DEFAULT TwoKeyMode,
                     seed_string IN     VARCHAR2,
                     key         OUT    VARCHAR2);

Parameters

Parameter

Description

which

Specifies the 3DES mode:

  • (default) TwoKeyMode.

  • ThreeKeyMode.

seed_string

Optional seed value used to generate the key.

key

Output parameter, the generated key.

Example

DECLARE
    des3_key VARCHAR2(100);
    custom_seed VARCHAR2(10) := 'myseed123';
BEGIN
    DBMS_OBFUSCATION_TOOLKIT.DES3GetKey(
        which => DBMS_OBFUSCATION_TOOLKIT.ThreeKeyMode,
        seed => custom_seed,
        key => des3_key
    );
    DBMS_OUTPUT.PUT_LINE('Generated 3DES ThreeKey: ' || des3_key);
END;

RAW

Syntax

PROCEDURE DES3GetKey(which IN     PLS_INTEGER DEFAULT TwoKeyMode,
                     seed  IN     RAW,
                     key   OUT    RAW);

Parameters

Parameter

Description

which

Specifies the 3DES mode:

  • (default) TwoKeyMode.

  • ThreeKeyMode.

seed

Optional seed value used to generate the key.

key

Output parameter, the generated key.

Example

DECLARE
    des3_key RAW(100);
    custom_seed RAW(10);
BEGIN
    custom_seed := UTL_RAW.CAST_TO_RAW('myseed123');

    DBMS_OBFUSCATION_TOOLKIT.DES3GetKey(
        which => DBMS_OBFUSCATION_TOOLKIT.ThreeKeyMode,
        seed => custom_seed,
        key => des3_key
    );
    DBMS_OUTPUT.PUT_LINE('Generated 3DES ThreeKey RAW: ' || des3_key);
END;