---
title: Spark-SQL ORC数据源国密加解密
description: "使用OmniShield机密大数据特性执行Spark引擎业务，需通过启动Spark提交任务执行。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2400/bds/kunpengbds_omniruntime_20_0716.html
sourcePath: /source/zh/kunpengboostkithistory/2400/bds/kunpengbds_omniruntime_20_0716.html
indexId: 86385bf853e16342ee4d018d76021b434075fad7cd305a23c7e50dae9d0945d078
---
# Spark-SQL ORC数据源国密加解密

使用OmniShield机密大数据特性执行Spark引擎业务，需通过启动Spark提交任务执行。

为满足国内数据安全合规要求，Spark-SQL现已扩展ORC列存文件格式的支持能力，在原有数据加解密功能基础上新增国密算法实现，实现从文件存储到SQL查询的全流程国密合规化处理。

1. 部署Hadoop KMS服务，创建好所需的Primary Key。
  1 hadoop key create key3 -cipher 'SM4/GCM/NoPadding'

  Hadoop KMS的启动步骤与1中的相同。如果Hadoop KMS已经启动，创建Key时无需重复启动KMS。

2. 在“/opt/omnishield”目录下执行如下命令启动Spark-SQL。
  1 spark-sql --master local --conf spark.sql.extensions=com.huawei.analytics.shield.sql.DataSourceEncryptPlugin --conf spark.hadoop.io.compression.codecs=com.huawei.analytics.shield.crypto.CryptoCodec --conf spark.sql.orc.filterPushdown=false --jars omnishield-1.0-SNAPSHOT.jar,kms.jar --conf spark.executor.extraClassPath=omnishield-1.0-SNAPSHOT.jar:kms.jar --driver-class-path omnishield-1.0-SNAPSHOT.jar:kms.jar

3. 在Spark-SQL命令行执行如下SQL创建加密数据表。
  1 2 drop table if exists otest1; create table otest1 (name string) options ( hadoop.security.key.provider.path "kms://http@IP:PORT/kms", orc.key.provider "hadoop", orc.encrypt "key3:name") stored as orc;

  hadoop.security.key.provider.path是指定Hadoop KMS的地址和端口号。 orc.encrypt是指定加密的列。

4. 在Spark-SQL命令行执行如下SQL检测数据表是否为加密数据表。
  1 describe extended otest1;

  在SQL运行结果的Storage Properties中如果包含orc.encrypt项则为加密表。
