Dev.to Security 🔐 Cybersecurity 👁 0 📖 1 min read

GBase 8a sha2: Built‑in SHA‑224, SHA‑256, SHA‑384, and SHA‑512 Hashing

The sha2 function in GBase 8a provides native support for multiple SHA‑2 hash algorithms. You can compute cryptographic hashes directly in SQL, which is useful for data integrity verification and secure storage in a gbas

The sha2 function in GBase 8a provides native support for multiple SHA‑2 hash algorithms. You can compute cryptographic hashes directly in SQL, which is useful for data integrity verification and secure storage in a gbase database.

Syntax

sha2(str, mode)
  • str: The input string. Supports Chinese, English, digits, and all characters allowed by the VARCHAR type.
  • mode: The hash algorithm selector. Only four values are accepted:
    • 224 → SHA‑224
    • 256 → SHA‑256
    • 384 → SHA‑384
    • 512 → SHA‑512

Any other value returns NULL. The input string should use UTF‑8 encoding.

mode Algorithm Return Length
224 SHA‑224 varchar(56)
256 SHA‑256 varchar(64)
384 SHA‑384 varchar(96)
512 SHA‑512 varchar(128)

Examples

-- SHA-224
gbase> SELECT sha2('GBase 8a', 224);
+----------------------------------------------------------+
| sha2('GBase 8a',224)                                     |
+----------------------------------------------------------+
| 7e3272023ef3e8edcbeb1daf2244529d806229d481753d45bd5bb524 |
+----------------------------------------------------------+

-- SHA-256
gbase> SELECT sha2('GBase 8a', 256);
+------------------------------------------------------------------+
| sha2('GBase 8a',256)                                             |
+------------------------------------------------------------------+
| 37e28220f6937e7dd7afcf6511e35a72d835dc50bd8c363fec8054485933313b |
+------------------------------------------------------------------+

-- SHA-384
gbase> SELECT sha2('GBase 8a', 384);
+--------------------------------------------------------------------------------------------------+
| sha2('GBase 8a',384)                                                                             |
+--------------------------------------------------------------------------------------------------+
| a1ea79415dc17396399a97d1e07c0553c775519be2f031333c9ef05d724341e4f2ed09cda8b890c595c1add5e8df2348 |
+--------------------------------------------------------------------------------------------------+

-- SHA-512
gbase> SELECT sha2('GBase 8a', 512);
+----------------------------------------------------------------------------------------------------------------------------------+
| sha2('GBase 8a',512)                                                                                                             |
+----------------------------------------------------------------------------------------------------------------------------------+
| 66668c66c50b095b772fc69cc903881a6107187cf33d4d9b43016c3b7260115e99175b677c2d603675ac7edcc0cf5ec7436c905d1b126237ab5e7949e48b62ed |
+----------------------------------------------------------------------------------------------------------------------------------+

-- Invalid mode
gbase> SELECT sha2('GBase 8a', 123);
+----------------------+
| sha2('GBase 8a',123) |
+----------------------+
| NULL                 |
+----------------------+

The sha2 function brings multiple SHA‑2 variants directly into your SQL toolkit. Whether you're hashing passwords or verifying row‑level integrity, you can do it inline without leaving the gbase database engine.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.