GBase 8a在新版本里支持了SHA2的多个加密函数,本文介绍该函数的用法和样例,包括SHA-224,SHA-256,SHA-384和SHA-512等。
目录导航
测试版本
gbase> select version();
+---------------------------+
| version() |
+---------------------------+
| 9.5.3.28.4_patch.1bcc63ff |
+---------------------------+
1 row in set (Elapsed: 00:00:00.00)
语法
sha2(str String,mode int) return String
- str:字符串,可以包含中文,应为,数字等varchar支持的所有字符
- mode:加密模式.
- mode=224,对应SHA-224,返回varchar(56)
- mode=256,对应SHA-256,返回varchar(64)
- mode=384,对用SHA-384,返回varchar(96)
- mode=512,对应SHA-512,返回varchar(128)
说明
该函数针对输入的字符串加密,生成固定长度的字符串并输出。如果指定的mode不是四个数字,则返回null。
字符编码,请用UTF8。
样例
sha224
gbase> select sha2('GBase 8a',224);
+----------------------------------------------------------+
| sha2('GBase 8a',224) |
+----------------------------------------------------------+
| 7e3272023ef3e8edcbeb1daf2244529d806229d481753d45bd5bb524 |
+----------------------------------------------------------+
1 row in set (Elapsed: 00:00:00.00)
sha256
gbase> select sha2('GBase 8a',256);
+------------------------------------------------------------------+
| sha2('GBase 8a',256) |
+------------------------------------------------------------------+
| 37e28220f6937e7dd7afcf6511e35a72d835dc50bd8c363fec8054485933313b |
+------------------------------------------------------------------+
1 row in set (Elapsed: 00:00:00.00)
sha384
gbase> select sha2('GBase 8a',384);
+--------------------------------------------------------------------------------------------------+
| sha2('GBase 8a',384) |
+--------------------------------------------------------------------------------------------------+
| a1ea79415dc17396399a97d1e07c0553c775519be2f031333c9ef05d724341e4f2ed09cda8b890c595c1add5e8df2348 |
+--------------------------------------------------------------------------------------------------+
1 row in set (Elapsed: 00:00:00.00)
sha512
gbase> select sha2('GBase 8a',512);
+----------------------------------------------------------------------------------------------------------------------------------+
| sha2('GBase 8a',512) |
+----------------------------------------------------------------------------------------------------------------------------------+
| 66668c66c50b095b772fc69cc903881a6107187cf33d4d9b43016c3b7260115e99175b677c2d603675ac7edcc0cf5ec7436c905d1b126237ab5e7949e48b62ed |
+----------------------------------------------------------------------------------------------------------------------------------+
1 row in set (Elapsed: 00:00:00.00)
其它值
gbase> select sha2('GBase 8a',123);
+----------------------+
| sha2('GBase 8a',123) |
+----------------------+
| NULL |
+----------------------+
1 row in set, 1 warning (Elapsed: 00:00:00.00)
gbase> show warnings;
+---------+------+-------------------+
| Level | Code | Message |
+---------+------+-------------------+
| Warning | 1682 | numeric overflow. |
+---------+------+-------------------+
1 row in set (Elapsed: 00:00:00.00)