Encrypting non-character values

Db2 supports encryption for numeric and datetime data types indirectly through casting. If non-character data is cast as VARCHAR or CHAR, the data can be encrypted.

Example

Suppose that you need to encrypt timestamp data and retrieve it in decrypted format. Perform the following steps:
  1. Create a table to store the encrypted values and set the column-level encryption password by using the following statements:
    CREATE TABLE ETEMP (C1 VARCHAR(124) FOR BIT DATA);
    SET ENCRYPTION PASSWORD :hv_pass;
  2. Cast, encrypt, and insert the timestamp data by using the following statement:
    INSERT INTO ETEMP VALUES ENCRYPT(CHAR(CURRENT TIMESTAMP));
  3. Recast, decrypt, and select the timestamp data by using the following statement:
    SELECT TIMESTAMP(DECRYPT_CHAR(C1)) FROM ETEMP;