Transparent Data Encryption

Transparent Data Encryption

下面的介绍是来自联机文档。

Oracle Database uses  authentication, authorization, and auditing mechanisms to secure data in the database, but not in the operating system data files where data is stored. To protect these data files, Oracle Database provides Transparent Data Encryption (TDE). TDE encrypts sensitive data stored in data files. To prevent unauthorized decryption, TDE stores the encryption keys in a security module external to the database,which can be an Oracle wallet or Hardware Security Module (HSM)
在数据库中oracle database使用身份验证,授权与审计机制来保护数据,但不是存储在操作系统数据文件中的数据。为了保护这些数据文件,oracle数据库提供了Transparent Data Encrypton (TDE)。TED将存储在数据文件中的敏感的、重要的数据加密。预防未授权的、非法的解密,TDE将encryption keys 存储在了一个数据库外部的安全模块,此安全模块可以是oracle wallet 或 HSM。

Database users and applications do not need to manage key storage or create auxiliary tables, views, and triggers. An application that processes sensitive data can use TDE to provide strong data encryption with little or no change to the application.

Use TDE to protect confidential data, such as credit card and social security numbers, stored in table columns. You can also use TDE to encrypt entire  tablespaces.
用TDE保护机密的数据,例如存储在表列中的信用卡与社会保障号,也可以使用TDE加密全部的表空间。


Transparent Data Encryption 分类
1、TDE  column encryption :  enables you to encrypt sensitive data stored in select table columns
     TDE column encryption was first introduced in Oracle Database 10 g  release 2 (10.2).

2、TDE  tablespace encryption:  enables you to encrypt all data stored in a tablespace.
     TDE tablespace encryption was introduced in Oracle Database 11g release 1 (11.1). 

Note:

Oracle Database 11 g  Release 1 (11.1) and higher versions ensure greater security by protecting data in temporary tablespaces during operations such as  JOIN  and  SORT . The data in temporary tablespaces stays encrypted during these operations.
Oracle Database 11 g  Release 1 (11.1) 版本与更高版本中 有了较高的安全性,在做JOIN,SORT操作期间,临时表空间的数据仍然保持加密状态。

To start using TDE, the security administrator must create a wallet and set a master key. The wallet can be the default database wallet shared with other Oracle Database components, or a separate wallet specifically used by TDE. Oracle strongly recommends that you use a separate wallet to store the master encryption key.
使用TDE之前,必须要创建一个wallet和一个master key。wallet可以是数据库默认的wallet与数据库其它组件共享,也可以是一个单独的专门由TDE使用的wallet。Oracle强烈建议使用一 个单独的wallet来存储master encryption key。

一、配置wallet

1、 创建一个新目录,并指定为Wallet目录
    wallet 位置由sqlnet.ora参数文件中的ENCRYPTION_WALLET_LOCATION参数指定,如果此参数不存在则WALLET_LOCATION被使用,如果没有存在的wallet,则要创建 一个。sqlnet.ora参数文件位于 $ORACLE_HOME/network/admin 。
    如果未在sqlnet.ora参数文件中指定,则使用数据库默认的wallet路,默认路径为ORACLE_BASE/admin/DB_UNIQUE_NAME/wallet  或者  ORACLE_HOME/admin/DB_UNIQUE_NAME/wallet。  DB_UNIQUE_NAME 是参数文件中指定的唯一数据库名。

    /u01/ora_wallet
ENCRYPTION_WALLET_LOCATION=
  (SOURCE=(METHOD=FILE)(METHOD_DATA=
   (DIRECTORY=/u01/ora_wallet)))
2、 创建master key文件,指定wallet密码,使用SYS用户登入系统,建立加密文件
    * 如果指定目录没有加密wallet,则会创建一个加密wallet  (ewallet.p12 ),wallet被打开,并且TDE的master encryption key 被创建/重建。
    * 如果指定目录有wallet, wallet被打开,并且TDE的master encryption key  被创建/重建。
     Note:
  • The master encryption key should only be created once, unless you want to reencrypt your data with a new encryption key.

  • Only users with the ALTER SYSTEM privilege can create a master encryption key or open the wallet.

SQL> ALTER SYSTEM SET ENCRYPTION KEY IDENTIFIED BY "wallet";

--  密码"wallet"不加引号时,后面使用时也不需要用引号

此时在设置的目录下,多出一个Personal Information Exchange类型的文件,相当于我们生成的master key文件。/u01/ora_wallet/ewallet.p12

3、 启动、关闭Wallet
SQL> ALTER SYSTEM SET ENCRYPTION WALLET OPEN IDENTIFIED BY "wallet";
SQL> ALTER SYSTEM SET ENCRYPTION WALLET CLOSE;

二、使用TDE进行数据加密

1、创建一个带有加密列的表,并插入数据

CREATE TABLE cust_payment_info 
  (first_name VARCHAR2(11), 
  last_name VARCHAR2(10), 
  order_number NUMBER(5), 
  credit_card_number VARCHAR2(16) ENCRYPT NO SALT,
  active_card VARCHAR2(3));
INSERT INTO cust_payment_info VALUES  ('Jon', 'Oldfield', 10001, '5446959708812985','YES');
INSERT INTO cust_payment_info VALUES  ('Chris', 'White', 10002, '5122358046082560','YES'); 
INSERT INTO cust_payment_info VALUES  ('Alan', 'Squire', 10003, '5595968943757920','YES');
INSERT INTO cust_payment_info VALUES  ('Mike', 'Anderson', 10004, '4929889576357400','YES');
INSERT INTO cust_payment_info VALUES  ('Annie', 'Schmidt', 10005, '4556988708236902','YES');
INSERT INTO cust_payment_info VALUES  ('Elliott', 'Meyer', 10006, '374366599711820','YES');
INSERT INTO cust_payment_info VALUES  ('Celine', 'Smith', 10007, '4716898533036','YES');
INSERT INTO cust_payment_info VALUES  ('Steve', 'Haslam', 10008, '340975900376858','YES');
INSERT INTO cust_payment_info VALUES  ('Albert', 'Einstein', 10009, '310654305412389','YES');
所有插入到credit_card_number列中的数据都以加密的形式存储在磁盘上。

2、在加密列上创建索引

如果加密列是NO SALT 则可以在加密列上创建索引;若为SALT,则不能在加密列上创建索引。
CREATE INDEX cust_payment_info_idx ON cust_payment_info (credit_card_number);
3、将表中已有的列修改为加密列

SQL> ALTER TABLE employees MODIFY (emp_ssn ENCRYPT);
修改后的状态

SQL> DESC employees
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 FIRSTNAME                                          VARCHAR2(11)
 LASTNAME                                           VARCHAR2(10)
 EMP_SSN                                            VARCHAR2(9) ENCRYPT
 DEPT                                               VARCHAR2(20)
4、创建加密表空间

TDE tablespace encryption enables you to encrypt an entire tablespace. All data stored in the tablespace is encrypted by default. Thus, if you create any table in an encrypted tablespace, it is encrypted by default. You do not need to perform a granular analysis of each table column to determine the columns that need encryption.

SQL> CREATE TABLESPACE securespace
  2  DATAFILE '/u01/oradata/orcl11/secure01.dbf'
  3  SIZE 150M
  4  ENCRYPTION
  5  DEFAULT STORAGE(ENCRYPT);
5、在加密表空间上创建表

    表中所有的数据都以加密形式存储在磁盘上
SQL> CREATE TABLE customer_payment_info
  2  (first_name VARCHAR2(11),
  3  last_name VARCHAR2(10),
  4  order_number NUMBER(5),
  5  credit_card_number VARCHAR2(16),
  6  active_card VARCHAR2(3))TABLESPACE securespace;

三、数据加密举例


四、相关的数据字典

·ALL_ENCRYPTED_COLUMNS
    显示可以访问当前用户表的加密列的加密信息。
Column Datatype NULL Description

OWNER

VARCHAR2(30)

NOT NULL

Owner of the table

TABLE_NAME

VARCHAR2(30)

NOT NULL

Name of the table

COLUMN_NAME

VARCHAR2(30)

NOT NULL

Name of the column

ENCRYPTION_ALG

VARCHAR2(29)

 

Encryption algorithm used to protect secrecy of data in this table:

  • 3 Key Triple DES 168 bits key

  • AES 128 bits key

  • AES 192 bits key

  • AES 256 bits key

SALT

VARCHAR2(3)

 

Indicates whether the column is encrypted with SALT (YES) or not (NO)

INTEGRITY_ALG

VARCHAR2(12)

 

Integrity algorithm used for the table:

  • SHA-1

  • NOMAC


·DBA_ENCRYPTED_COLUMNS
    显示数据库中所有的加密列的加密信息。此视图的详细信息与ALL_ENCRYPTED_COLUMNS视图是相同的。
·USER_ENCRYPTED_COLUMNS
    比ALL_ENCRYPTED_COLUMNS视图少了OWNER列,只属于用户表的数据被显示。
·V$ENCRYPTED_TABLESPACES
    显示被加密的表空间的信息。
    

Column Datatype Description

TS#

NUMBER

Tablespace number

ENCRYPTIONALG

VARCHAR2(7)

Encryption algorithm:

  • NONE

  • 3DES168

  • AES128

  • AES192

  • AES256

ENCRYPTEDTS

VARCHAR2(3)

Indicates whether the tablespace is encrypted (YES) or not (NO)


· V$WALLET
     displays metadata information for a PKI certificate, which may be used as a master key for TDE
· V$ENCRYPTION_WALLET
    显示wallet状态信息与wallet位置信息。
Column Datatype Description

WRL_TYPE

VARCHAR2(20)

Type of the wallet resource locator (for example, FILE)

WRL_PARAMETER

VARCHAR2(4000)

Parameter of the wallet resource locator (for example, absolute filename ifWRL_TYPE = FILE)

STATUS

VARCHAR2(9)

Status of the wallet:

  • OPEN

  • CLOSED

  • UNDEFINED

  • OPEN_NO_MASTER_KEY


五、遇到的问题


1、ORA-28368:不能自动创建wallet

  SQL> ALTER SYSTEM SET ENCRYPTION KEY IDENTIFIED BY "wallet";
  ORA-28368:不能自动创建wallet

     原因:缺少相关路径。我没有使用sqlnet.ora指定路径,使用的是默认路径。后来才发现默认路径下没有wallet文件夹,手动在默认路径下创建也wallet文件夹,问题解决。

2、ORA-28353: 无法打开 wallet
   
 SQL> ALTER SYSTEM SET ENCRYPTION KEY IDENTIFIED BY "wallet1";
 ORA-28353: 无法打开 wallet

    原因:已经存在了一个旧的WALLET文件,因此如果要建立新的WALLET,则删除了旧的WALLET。

3、ORA-28362:未找到主键
 
 SQL>SELECT * FROM EMP;    -- ename字段加密了
 ORA-28362:未找到主键

    原因:因为前边创建了默认路径的wallet,现在想创建一个指定路径的wallet,则把默认路径下的wallet文件夹给删除了。没办法恢复了,即使再创建一个wallet,使用相同的密码也是不能惰性的,还是会报此错误。

4、删除旧的wallet后,在sqlnet.ora文件中指定了wallet路径,然后执行下面的语句,还是报错

SQL> ALTER SYSTEM SET ENCRYPTION KEY IDENTIFIED BY "wallet";
  ORA-28368:不能自动创建wallet

经试验,是系统去默认的路径去找wallet文件夹了。不知道为什么设置了指定的路径后还会去寻找默认的路径,还请知道原因的朋友给予指点。



我找到原因 了:因为我设置的路径下的文件夹是ora_wallet,这样是不行的,不管是在什么路径下,最终的文件夹名称都要是wallet,我改后就可以了。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27661381/viewspace-1338792/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27661381/viewspace-1338792/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值