<<<<<<< HEAD decrypt | H2 | SQLDoc
Skip to main content

decrypt

1. DECRYPT Function

======= decrypt | H2 Function | SQLDoc

decrypt

1. DECRYPT Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The DECRYPT function in H2 database is used to decrypt a string using the specified algorithm and passphrase.

2. Syntax

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

DECRYPT(algorithm, passphrase, encrypted_string)

Arguments

  • algorithm: The encryption algorithm to be used for decryption. It should be a string value representing a valid encryption algorithm supported by H2 database.
  • passphrase: The passphrase or key used for decryption. It should be a string value.
  • encrypted_string: The string that needs to be decrypted. It should be a string value representing the encrypted data.

Return

  • The DECRYPT function returns the decrypted string.

3. Notes

  • The DECRYPT function in H2 database uses the specified algorithm and passphrase to decrypt the encrypted string.
  • The algorithm parameter should be a valid encryption algorithm supported by H2 database, such as AES, DES, or RSA.
  • The passphrase is the secret key used for decryption. Make sure to use a strong and secure passphrase.
  • If the decryption fails due to an incorrect passphrase or algorithm, the DECRYPT function will return NULL.
  • Ensure that the encrypted string is in the correct format and matches the algorithm and passphrase used for encryption.

4. Examples

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

Example 1 - Decrypting a string using AES algorithm:

SELECT DECRYPT('AES', 'myPassphrase', 'U2FsdGVkX1+U2+Dojz5zl0C6BQG4Xg==') AS decrypted_string;

Output:

decrypted_string
----------------
Hello, World!

Example 2 - Decrypting a column of encrypted values:

CREATE TABLE encrypted_data (
id INT PRIMARY KEY,
encrypted_string VARCHAR
);

INSERT INTO encrypted_data VALUES (1, 'U2FsdGVkX1+U2+Dojz5zl0C6BQG4Xg=='), (2, 'U2FsdGVkX1+U2+Dojz5zl0C6BQG4Xg==');

SELECT id, encrypted_string, DECRYPT('AES', 'myPassphrase', encrypted_string) AS decrypted_string
FROM encrypted_data;

Output:

id | encrypted_string                  | decrypted_string
---+----------------------------------+-----------------
1 | U2FsdGVkX1+U2+Dojz5zl0C6BQG4Xg== | Hello, World!
2 | U2FsdGVkX1+U2+Dojz5zl0C6BQG4Xg== | Hello, World!
  • encrypt - Encrypt a string using a specified algorithm and passphrase.