添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
气宇轩昂的香瓜  ·  Copy and transform ...·  3 月前    · 
鬼畜的水龙头  ·  nodejs 使用 ...·  9 月前    · 
玉树临风的楼房  ·  python ...·  2 年前    · 
威武的苦咖啡  ·  QPluginLoader - ...·  2 年前    · 
暂无图片
暂无图片
暂无图片
暂无图片

了解下openGauss的密态支持函数/存储过程

Gauss松鼠会 2022-05-26
330

上期我们介绍了密态查询和使用jdbc连接密态数据库的操作。本期来介绍密态支持函数/存储过程。openGauss 3.0.0版本只支持sql和PL/pgsql两种语言。由于密态支持存储过程中创建和执行函数/存储过程对用户是无感知的,因此使用时语法和非密态无区别。
密态等值查询支持函数存储过程特性新增了系统表gs_encrypted_proc,用于存储参数返回的原始数据类型。下面来看下一些示例。

创建并执行涉及加密列的函数/存储过程

  1. 创建密钥,详细步骤请参考 使用gsql操作密态数据库和使用JDBC操作密态数据库

  2. 创建加密表。

    openGauss=# CREATE TABLE creditcard_info (
        id_number int,
         name  text,
        credit_card varchar(19) encrypted with (column_encryption_key = ImgCEK1, encryption_type = DETERMINISTIC)
        ) with (orientation=row);
    CREATE TABLE
  3. 插入数据。
    openGauss=# insert into creditcard_info values(1, 'Avi', '1234567890123456');
    INSERT 0 1
    openGauss=# insert into creditcard_info values(2, 'Eli', '2345678901234567');
    INSERT 0 1
  4. 创建函数支持密态等值查询。
    openGauss=# CREATE FUNCTION f_encrypt_in_sql(val1 text, val2 varchar(19)) RETURNS text AS 'SELECT name from creditcard_info where name=$1 or credit_card=$2 LIMIT 1' LANGUAGE SQL;
    CREATE FUNCTION
    openGauss=# CREATE FUNCTION f_encrypt_in_plpgsql (val1 text, val2 varchar(19))
    RETURNS text AS $$
    DECLARE
    c text;
    BEGIN
     SELECT into c name from creditcard_info where name=$1 or credit_card =$2 LIMIT 1;
      RETURN c;
    END; $$
    LANGUAGE plpgsql;
    CREATE FUNCTION
  5. 执行函数。
    openGauss=# SELECT f_encrypt_in_sql('Avi','1234567890123456');
     f_encrypt_in_sql
    ------------------
    (1 row)
    openGauss=# SELECT f_encrypt_in_plpgsql('Avi', val2=>'1234567890123456');
     f_encrypt_in_plpgsql