Skip to main content


1. ENCRYPT Function

The ENCRYPT function in H2 database is used to encrypt a given value using the specified encryption algorithm and key.

2. Syntax

The syntax for the ENCRYPT function in H2 database is as follows:

ENCRYPT(value, algorithm, key)


  • value: The value to be encrypted. It can be a string or binary value.
  • algorithm: The encryption algorithm to be used. It should be a valid algorithm supported by H2 database.
  • key: The encryption key. It should be a string or binary value representing the encryption key.


  • The ENCRYPT function returns the encrypted value.

3. Notes

  • The ENCRYPT function in H2 database supports various encryption algorithms such as AES, DES, and Blowfish. Please refer to the H2 database documentation for a complete list of supported algorithms.
  • The encryption key should be a valid key for the chosen encryption algorithm. If an invalid key is provided, the ENCRYPT function may return an error or produce unexpected results.
  • The encrypted value returned by the ENCRYPT function is binary data. You may need to convert it to a suitable format (e.g., Base64) if you plan to store or transmit it as a string.

4. Examples

Here are a few examples demonstrating the usage of the ENCRYPT function in H2 database:

Example 1 - Encrypting a string value using AES algorithm:

SELECT ENCRYPT('Hello, World!', 'AES', 'mysecretkey') AS encrypted_value;



Example 2 - Encrypting a binary value using Blowfish algorithm:

SELECT ENCRYPT(X'0123456789ABCDEF', 'BLOWFISH', 'mykey') AS encrypted_value;



There are no directly related functions to the ENCRYPT function in H2 database. However, you may find the following functions useful for working with encrypted data:

  • decrypt - Decrypts an encrypted value using the specified algorithm and key.
  • hash - Generates a hash value for a given input using various hashing algorithms.
  • RANDOM_BYTES - Generates a specified number of random bytes. Useful for generating encryption keys.

Note: The availability and usage of these functions may vary in different databases.