CN118363986A - Encryption and decryption method and device for secret database - Google Patents
Encryption and decryption method and device for secret database Download PDFInfo
- Publication number
- CN118363986A CN118363986A CN202410470688.3A CN202410470688A CN118363986A CN 118363986 A CN118363986 A CN 118363986A CN 202410470688 A CN202410470688 A CN 202410470688A CN 118363986 A CN118363986 A CN 118363986A
- Authority
- CN
- China
- Prior art keywords
- data
- column
- name
- key
- statement
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2453—Query optimisation
- G06F16/24534—Query rewriting; Transformation
- G06F16/24547—Optimisations to support specific applications; Extensibility of optimisers
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2455—Query execution
- G06F16/24553—Query execution of query operations
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/60—Protecting data
- G06F21/602—Providing cryptographic facilities or services
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/60—Protecting data
- G06F21/62—Protecting access to data via a platform, e.g. using keys or access control rules
- G06F21/6218—Protecting access to data via a platform, e.g. using keys or access control rules to a system of files or objects, e.g. local or distributed file system or database
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- Databases & Information Systems (AREA)
- General Health & Medical Sciences (AREA)
- Software Systems (AREA)
- Computer Security & Cryptography (AREA)
- Computer Hardware Design (AREA)
- Bioethics (AREA)
- Health & Medical Sciences (AREA)
- Computational Linguistics (AREA)
- Data Mining & Analysis (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Storage Device Security (AREA)
Abstract
Description
技术领域Technical Field
本申请涉及密态数据库领域,尤其涉及密态数据库的加密和解密方法以及装置。The present application relates to the field of secret databases, and in particular to encryption and decryption methods and devices for secret databases.
背景技术Background technique
数据库的核心任务是数据资产的管理,包括数据的分类、组织、编码、储存、检索和维护。在数据信息爆发式增长的今天,数据库承担了越来越多的数据处理与分析职责,以数据赋能的形式不断促进应用创新,助力数字化发展进程。The core task of a database is the management of data assets, including data classification, organization, coding, storage, retrieval, and maintenance. With the explosive growth of data information today, databases are taking on more and more data processing and analysis responsibilities, continuously promoting application innovation in the form of data empowerment and facilitating the process of digital development.
密态数据库是指存储和管理密态数据的数据库管理系统,数据以加密形态存储在数据库中,其中数据存储、计算、检索、管理均在密文形态下完成,而与数据库管理相关的语法解析、事务ACID等能力均集成传统数据库能力。密态数据库是数据库系统、加密技术及数学算法深度结合的产物。密态数据库的核心任务是保护数据全生命周期的安全,并支持密态数据的检索和计算。随机化加密可以保证密态数据库中的数据的安全性,但是随机加密后的数据失去了运算的灵活性,无法进行排序、大小比较查询等数据库操作。A secret database refers to a database management system that stores and manages secret data. Data is stored in an encrypted form in the database, where data storage, calculation, retrieval, and management are all completed in ciphertext form, and capabilities such as syntax parsing and transaction ACID related to database management are integrated with traditional database capabilities. A secret database is the product of a deep combination of database systems, encryption technology, and mathematical algorithms. The core task of a secret database is to protect the security of data throughout its life cycle and to support the retrieval and calculation of secret data. Randomized encryption can ensure the security of data in a secret database, but the randomly encrypted data loses the flexibility of calculation and cannot perform database operations such as sorting, size comparison queries, etc.
发明内容Summary of the invention
本申请提供密态数据库的加密和解密以及装置,以解决密态数据库中的数据随机加密后无法进行正确排序、大小比较查询等数据库操作的技术问题。The present application provides encryption and decryption of a secret database and a device to solve the technical problem that after the data in the secret database is randomly encrypted, it is impossible to perform database operations such as correct sorting, size comparison query, etc.
第一方面,提供一种数据库操作方法,应用于数据交互终端,所述方法包括:In a first aspect, a database operation method is provided, which is applied to a data interaction terminal, and the method includes:
获取作用于目标数据库的第一结构化查询(structured query language,SQL)语句,所述第一结构化查询语句为数据操作语句;Obtaining a first structured query language (SQL) statement acting on a target database, wherein the first structured query statement is a data operation statement;
对所述第一结构化查询语句进行重写,得到第二结构化查询语句,所述第二结构化查询语句中的数据为对所述第一结构化查询语句中的数据进行保序加密得到;Rewriting the first structured query statement to obtain a second structured query statement, wherein data in the second structured query statement is obtained by performing order-preserving encryption on the data in the first structured query statement;
向所述目标数据库发送所述第二结构化查询语句,以使所述目标数据库执行所述第二结构化查询语句对应的数据库操作;Sending the second structured query statement to the target database, so that the target database executes the database operation corresponding to the second structured query statement;
接收所述目标数据库执行所述数据库操作后返回的第一操作结果数据;Receiving first operation result data returned by the target database after executing the database operation;
对所述第一操作结果数据进行数据还原,得到所述第一结构化查询语句对应的第二操作结果数据。The first operation result data is restored to obtain second operation result data corresponding to the first structured query statement.
第二方面,提供一种密态数据库的加密和解密装置,应用于数据交互终端,所述装置包括:In a second aspect, a device for encrypting and decrypting a secret database is provided, which is applied to a data interaction terminal, and the device comprises:
获取模块,用于获取作用于目标数据库的第一结构化查询语句,所述第一结构化查询语句为数据操作语句;An acquisition module, used to acquire a first structured query statement acting on a target database, wherein the first structured query statement is a data operation statement;
重写模块,用于对所述第一结构化查询语句进行重写,得到第二结构化查询语句,所述第二结构化查询语句中的数据为对所述第一结构化查询语句中的数据进行保序加密得到;A rewriting module, configured to rewrite the first structured query statement to obtain a second structured query statement, wherein the data in the second structured query statement is obtained by performing order-preserving encryption on the data in the first structured query statement;
发送模块,用于向所述目标数据库发送所述第二结构化查询语句,以使所述目标数据库执行所述第二结构化查询语句对应的数据库操作;A sending module, configured to send the second structured query statement to the target database, so that the target database executes the database operation corresponding to the second structured query statement;
接收模块,用于接收所述目标数据库执行所述数据库操作后返回的第一操作结果数据;A receiving module, used for receiving first operation result data returned by the target database after executing the database operation;
还原模块,用于对所述第一操作结果数据进行数据还原,得到所述第一结构化查询语句对应的第二操作结果数据。The restoration module is used to restore the first operation result data to obtain the second operation result data corresponding to the first structured query statement.
第三方面,提供一种计算机设备,包括存储器以及一个或多个处理器,所述存储器连接至所述一个或多个处理器,一个或多个处理器用于执行存储在存储器中的一个或多个计算机程序,一个或多个处理器在执行一个或多个计算机程序时,使得该计算机设备实现上述第一方面的数据库操作方法。In a third aspect, a computer device is provided, comprising a memory and one or more processors, wherein the memory is connected to the one or more processors, and the one or more processors are used to execute one or more computer programs stored in the memory, and when the one or more processors execute the one or more computer programs, the computer device implements the database operation method of the first aspect.
第四方面,提供一种计算机可读存储介质,计算机可读存储介质存储有计算机程序,计算机程序包括程序指令,上述程序指令当被处理器执行时使上述处理器执行上述第一方面的数据库操作方法。In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor executes the database operation method of the first aspect.
本申请可以实现如下技术效果:在获取到作用于目标数据库的第一结构化查询语句后,对第一结构化查询语句进行重写,得到第二结构化查询语句,第二结构化查询语句中的数据为对第一结构查询语句中的数据进行保序加密得到,然后将第二结构化查询语句发送给目标数据库,以使目标数据库执行第二结构化查询语句对应的数据库操作;再接收目标数据库执行第二结构化语句对应的将数据库操作后返回的第一操作结果数据;最后对第一操作结果数据进行数据还原,得到第一结构化查询语句对应的第二操作结果数据。由于是对SQL语句进行改写后发送给数据库执行,加密和数据还原均在数据交互终端侧进行,数据库服务端只需进行常规的数据库操作,无需对数据库服务端进行修改;由于改写后的SQL语句中的数据是对改写前的SQL语句中的数据进行保序加密得到,加密后的数据之间的顺序关系与加密前的数据之间的顺序关系相同,因而能够进行排序和大小比较查询等数据库操作。The present application can achieve the following technical effects: after obtaining the first structured query statement acting on the target database, the first structured query statement is rewritten to obtain a second structured query statement, the data in the second structured query statement is obtained by encrypting the data in the first structured query statement in order-preserving manner, and then the second structured query statement is sent to the target database so that the target database executes the database operation corresponding to the second structured query statement; then the target database executes the first operation result data returned after the database operation corresponding to the second structured query statement is received; finally, the first operation result data is restored to obtain the second operation result data corresponding to the first structured query statement. Since the SQL statement is rewritten and then sent to the database for execution, encryption and data restoration are both performed on the data interaction terminal side, and the database server only needs to perform conventional database operations without modifying the database server; since the data in the rewritten SQL statement is obtained by encrypting the data in the SQL statement before rewriting in order-preserving manner, the order relationship between the encrypted data is the same as the order relationship between the data before encryption, so database operations such as sorting and size comparison query can be performed.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
为了更清楚地说明本申请实施例的技术方案,下面将对本申请实施例的描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
图1为本申请实施例提供的一种密态数据库系统的系统架构示意图;FIG1 is a schematic diagram of a system architecture of a confidential database system provided in an embodiment of the present application;
图2为本申请实施例提供的一种保序加密的示意图;FIG2 is a schematic diagram of an order-preserving encryption provided in an embodiment of the present application;
图3为本申请实施例提供的一种数据库操作方法的流程示意图;FIG3 is a schematic diagram of a flow chart of a database operation method provided in an embodiment of the present application;
图4为本申请实施例提供的另一种数据库操作方法的流程示意图;FIG4 is a flow chart of another database operation method provided in an embodiment of the present application;
图5为本申请实施例提供的又一种数据库操作方法的流程示意图;FIG5 is a schematic diagram of a flow chart of another database operation method provided in an embodiment of the present application;
图6为本申请实施例提供的又一种数据库操作方法的流程示意图;FIG6 is a flow chart of another database operation method provided in an embodiment of the present application;
图7为本申请实施例提供的一种密态数据库的加密和解密装置的结构示意图;FIG7 is a schematic diagram of the structure of an encryption and decryption device for a secret database provided in an embodiment of the present application;
图8是本申请实施例提供的一种计算机设备的结构示意图。FIG8 is a schematic diagram of the structure of a computer device provided in an embodiment of the present application.
具体实施方式Detailed ways
为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处所描述的具体实施例仅用以解释本申请,并不用于限定本申请。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。In order to make the purpose, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.
需要说明的是,如果不冲突,本申请实施例中的各个特征可以相互结合,均在本申请的保护范围之内。另外,虽然在装置示意图中进行了功能模块划分,在流程图中示出了逻辑顺序,但是在某些情况下,可以以不同于装置中的模块划分,或流程图中的顺序执行所示出或描述的步骤。再者,本申请所采用的“第一”、“第二”、“第三”等字样并不对数据和执行次序进行限定,仅是对功能和作用基本相同的相同项或相似项进行区分。It should be noted that, if there is no conflict, the various features in the embodiments of the present application can be combined with each other, all within the scope of protection of the present application. In addition, although the functional module division is performed in the device schematic diagram and the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in a sequence different from the module division in the device or the flow chart. Furthermore, the words "first", "second", "third", etc. used in this application do not limit the data and execution order, but only distinguish the same items or similar items with basically the same functions and effects.
本申请的技术方案可应用于密态数据库系统。参见图1,图1为本申请实施例提供的一种密态数据库系统的系统架构示意图,如图1所示,密态数据库系统包括数据交互终端101和数据库102,数据交互终端101为面向用户的交互终端,数据交互终端101上运行有数据库客户端,用户可以向数据库客户端下发SQL语句,数据库客户端用于对SQL语句进行接收、词法语法解析处理、SQL语句发送和结果接收处理。数据交互终端101中还可以设置有加密子系统,加密子系统用于对SQL语句和结果进行加解密处理。其中,加密子系统中包括可搜索加密算法模块、密钥管理、加密表元数据管理模块、SQL加密处理(重写)和结果解密处理等模块,以支持加密数据的相关处理。数据库102为用于存储各种数据的存储容器,数据库102可执行数据库客户端发送的SQL语句对应的数据库操作,并向数据库客户端返回执行SQL语句对应的数据库操作所得到的执行结果。The technical solution of the present application can be applied to a secret database system. Referring to FIG. 1 , FIG. 1 is a schematic diagram of the system architecture of a secret database system provided by an embodiment of the present application. As shown in FIG. 1 , the secret database system includes a data interaction terminal 101 and a database 102. The data interaction terminal 101 is a user-oriented interaction terminal. A database client is running on the data interaction terminal 101. The user can send SQL statements to the database client. The database client is used to receive SQL statements, perform lexical and grammatical analysis, send SQL statements, and receive results. An encryption subsystem can also be provided in the data interaction terminal 101, and the encryption subsystem is used to perform encryption and decryption processing on SQL statements and results. Among them, the encryption subsystem includes modules such as a searchable encryption algorithm module, a key management module, an encryption table metadata management module, an SQL encryption processing (rewriting), and a result decryption processing module to support the related processing of encrypted data. The database 102 is a storage container for storing various data. The database 102 can execute the database operation corresponding to the SQL statement sent by the database client, and return the execution result obtained by executing the database operation corresponding to the SQL statement to the database client.
为便于理解,先对本申请涉及的一些名词进行介绍。To facilitate understanding, some terms involved in this application are first introduced.
1、SQL语句1. SQL statements
SQL语句是具有数据操作和数据定义等多种功能的数据库语言。SQL语句包括数据定义语句(data definition language,DDL)和数据操作语句(data manipulationlanguage,DML)。SQL statements are database languages with multiple functions such as data manipulation and data definition. SQL statements include data definition language (DDL) and data manipulation language (DML).
其中,数据定义语句用于定义数据对象,具体可用于定义数据库、数据库中的数据表以及数据表中的字段(列名称);DML用于对数据库中的数据表中的数据进行增加、删除、修改、查询等。Among them, data definition statements are used to define data objects, specifically to define databases, data tables in databases, and fields (column names) in data tables; DML is used to add, delete, modify, and query data in data tables in databases.
2、主密钥2. Master Key
本申请中,主密钥为数据交互终端根据主密钥创建命令创建的密钥,主密钥用于对列密钥进行加密和解密。In the present application, the master key is a key created by the data interaction terminal according to a master key creation command, and the master key is used to encrypt and decrypt the column key.
3、主密钥元数据3. Master Key Metadata
本申请中,主密钥元数据是指与主密钥相关的一些数据,主密钥元数据主要包括主密钥名称、密钥库提供者名称、密钥路径以及算法名称。主密钥元数据中的主密钥名称用于指示主密钥。主密钥元数据中的密钥库提供者名称用于指示主密钥的提供者;本申请中,主密钥的提供者可分为本地密钥库提供者和第三方密钥库提供者,本地密钥库提供者是在数据交互终端本地的密钥管理模块,数据交互终端本地的密钥管理模块属于数据交互终端中的加密子系统;第三方密钥库提供者是指数据交互终端之外的其他管理密钥的密钥管理模块。主密钥元数据中的密钥路径是指主密钥的存储路径。主密钥元数据中的算法名称是指主密钥对应的加解密算法的名称。主密钥对应的加解密算法用于对本申请的列密钥进行加密和解密。In this application, master key metadata refers to some data related to the master key, and the master key metadata mainly includes the master key name, key library provider name, key path and algorithm name. The master key name in the master key metadata is used to indicate the master key. The key library provider name in the master key metadata is used to indicate the provider of the master key; in this application, the provider of the master key can be divided into a local key library provider and a third-party key library provider. The local key library provider is a key management module local to the data interaction terminal, and the key management module local to the data interaction terminal belongs to the encryption subsystem in the data interaction terminal; the third-party key library provider refers to other key management modules outside the data interaction terminal. The key path in the master key metadata refers to the storage path of the master key. The algorithm name in the master key metadata refers to the name of the encryption and decryption algorithm corresponding to the master key. The encryption and decryption algorithm corresponding to the master key is used to encrypt and decrypt the column key of this application.
4、列密钥4. Column Key
本申请中,列密钥为数据交互终端密钥根据列密钥创建指令创建的密钥,列密钥用于对数据表中的数据列进行加密和解密。In the present application, the column key is a key created by the data exchange terminal key according to a column key creation instruction, and the column key is used to encrypt and decrypt data columns in a data table.
5、列密钥元数据5. Column Key Metadata
本申请中,列密钥元数据是指与列密钥相关的一些数据,列密钥元数据主要包括主密钥名称、列密钥名称和算法名称。列密钥元数据中的列密钥名称用于指示列密钥。列密钥元数据中的主密钥名称用于指示对列密钥进行加密和解密所采用的主密钥。列密钥元数据中的算法名称是指列密钥对应的加解密算法的名称。列密钥对应的加解密算法用于对数据表中的数据列进行加密和解密。本申请中,列密钥对应的加解密算法可包括保序对称加密(order-preserving symmetric encryption,ope)算法和其他的加解密算法。In this application, column key metadata refers to some data related to the column key, and the column key metadata mainly includes the master key name, column key name and algorithm name. The column key name in the column key metadata is used to indicate the column key. The master key name in the column key metadata is used to indicate the master key used to encrypt and decrypt the column key. The algorithm name in the column key metadata refers to the name of the encryption and decryption algorithm corresponding to the column key. The encryption and decryption algorithm corresponding to the column key is used to encrypt and decrypt the data column in the data table. In this application, the encryption and decryption algorithm corresponding to the column key may include order-preserving symmetric encryption (OPE) algorithm and other encryption and decryption algorithms.
6、加密列密钥6. Encrypted column keys
本申请中,加密列密钥是指采用列密钥元数据中的主密钥名称对应的主密钥,对列密钥元数据中的列密钥名称对应的列密钥进行加密得到的列密钥。In the present application, the encrypted column key refers to a column key obtained by encrypting a column key corresponding to a column key name in the column key metadata using a master key corresponding to a master key name in the column key metadata.
7、表加密元数据7. Table encryption metadata
本申请中,表加密元数据是指加密的数据相关的数据。表加密元数据包括数据库中的数据表中的列加密信息,表加密元数据主要包括表名称、原始列名称、替换列名称、列密钥名称、原始数据类型大小、新数据类型大小。表名称用于在数据库中指示数据表;原始列名称是指数据表中要加密的数据列的名称,用于在未加密的数据表中指示一个数据列;替换列名称是指数据表中加密后的数据列的名称,用于在加密的数据表中指示加密数据列;表加密元数据中的列密钥名称是指用于加密数据列采用的列密钥的名称。原始数据类型大小,是指未经加密的数据列中原始数据的类型和大小;新数据类型大小是指经过加密的加密数据列中的加密数据的类型和大小。可选地,新数据类型大小也可以不包含在表加密元数据中,新数据类型大小可以根据原数据类型大小和列密钥的加密算法在处理时直接得到。In this application, table encryption metadata refers to data related to encrypted data. Table encryption metadata includes column encryption information in a data table in a database. Table encryption metadata mainly includes table name, original column name, replacement column name, column key name, original data type size, and new data type size. The table name is used to indicate a data table in a database; the original column name refers to the name of the data column to be encrypted in a data table, and is used to indicate a data column in an unencrypted data table; the replacement column name refers to the name of the encrypted data column in a data table, and is used to indicate an encrypted data column in an encrypted data table; the column key name in the table encryption metadata refers to the name of the column key used to encrypt the data column. The original data type size refers to the type and size of the original data in an unencrypted data column; the new data type size refers to the type and size of the encrypted data in an encrypted data column. Optionally, the new data type size may not be included in the table encryption metadata, and the new data type size may be directly obtained during processing based on the original data type size and the encryption algorithm of the column key.
8、ope算法8. ope algorithm
ope算法通过对数据进行数学转换来实现加密和保序的目的,用于支持数值型和字符型的比较运算符,即支持数据型和字符型数据的可检索。The OPE algorithm achieves the purpose of encryption and order preservation by performing mathematical transformation on data. It is used to support comparison operators of numeric and character types, that is, it supports the retrieval of numeric and character data.
ope算法将明文空间的值通过超几何分布(hyper geometric distribution,HGD)进行伪随机化处理,并按照一定的顺序映射到密文空间。使用伪随机化可以解决明文频率分布的隐藏问题,即通过随机化操作,隐藏明文的统计特征。同时,顺序的映射保持了明文的顺序关系,即使得在加密后的密文中,明文之间的相对顺序仍然能够被保留。The ope algorithm pseudo-randomizes the values in the plaintext space through hyper geometric distribution (HGD) and maps them to the ciphertext space in a certain order. The use of pseudo-randomization can solve the problem of hiding the frequency distribution of plaintext, that is, hiding the statistical characteristics of the plaintext through randomization operations. At the same time, the sequential mapping maintains the order relationship of the plaintext, so that the relative order between the plaintexts can still be retained in the encrypted ciphertext.
伪随机化是基于HGD实现的,并且在密钥确定的情况下是确定性的,是无状态的。Pseudo-randomization is based on HGD and is deterministic and stateless when the key is known.
对于数值型数据,HGD算法即函数x=HGD(D,R,y,cc),解释为:For numerical data, the HGD algorithm, i.e., the function x=HGD(D, R, y, cc), is interpreted as:
从一个有R个球的箱子里面抽出球,箱子中有D个黑球,R-D个白球。抽出y个球,这个函数返回其中的黑球数x。HGD是一个实现采样算法的函数,它的输出x是满足超几何分布的随机变量。在计算机实现时,D、R和y确定后,基于随机数cc,生成的x是满足超几何分布的随机变量(即根据所有的cc,计算得到x的集合,其中x=x*的概率是PHGD(x*;R,D,y))。cc为密钥k、D和R通过伪随机函数PRF(可以将k、D和R进行MAC计算,然后把计算结果再通过AES加密来实现)计算得到的随机数。Draw balls from a box with R balls, there are D black balls and R-D white balls in the box. Draw y balls, and this function returns the number of black balls x. HGD is a function that implements a sampling algorithm, and its output x is a random variable that satisfies the hypergeometric distribution. When implemented on a computer, after D, R and y are determined, the generated x is a random variable that satisfies the hypergeometric distribution based on the random number cc (that is, based on all cc, the set of x is calculated, where the probability of x=x* is PHGD(x*; R, D, y)). cc is a random number calculated by the pseudo-random function PRF (k, D and R can be MAC calculated, and then the calculation result can be implemented by AES encryption).
对于一个明文m,密钥为k,求密文c的具体加密步骤如下:For a plaintext m, the key is k, and the specific encryption steps for the ciphertext c are as follows:
(1)根据数据类型初始化明密文域为给定的区间,密文域大小为明文域大小比特数的两倍。如数据的类型为int类型,则明文域区间domain=[0,2^32),密文域区间range=[0,2^64),即明文域大小D=2^32,密文域大小R=2^64。(1) Initialize the plaintext and ciphertext domains to a given interval according to the data type. The ciphertext domain size is twice the number of bits of the plaintext domain size. For example, if the data type is int, the plaintext domain interval domain = [0, 2^32), and the ciphertext domain interval range = [0, 2^64), that is, the plaintext domain size D = 2^32, and the ciphertext domain size R = 2^64.
(2)y=R/2,cc=PRF(k,D,R),计算x=HGD(D,R,y,cc)。(2) y = R/2, cc = PRF(k, D, R), calculate x = HGD(D, R, y, cc).
(3)如果m<min(domain)+x,则domain=[min(domain),min(domain)+x),range=[min(range),min(range)+y);否则,domain=[min(domain)+x,max(domain)],range=[min(range)+y,max(range)]。(3) If m<min(domain)+x, then domain=[min(domain),min(domain)+x), range=[min(range),min(range)+y); otherwise, domain= [min(domain)+x,max(domain)], range=[min(range)+y,max(range)].
其中,min(),max()分别是求给定区间的最小值和最大值的函数。Among them, min() and max() are functions for finding the minimum and maximum values of a given interval respectively.
(4)更新明文域大小和密文域大小:D=domain大小,R=range大小。(4) Update the plaintext domain size and ciphertext domain size: D = domain size, R = range size.
(5)如果D=1,则执行步骤(6);否则,返回执行步骤(2)。(5) If D=1, execute step (6); otherwise, return to execute step (2).
(6)根据明文m计算hash值,然后使用AES加密hash值,再将加密结果模R,最后将模R的结果+min(range)为最后的密文c。(6) Calculate the hash value based on the plaintext m, then use AES to encrypt the hash value, then apply the modulus R to the encrypted result, and finally add min(range) to the result of the modulus R to obtain the final ciphertext c.
保序加密的一个示例可参见图2。An example of order-preserving encryption can be seen in Figure 2.
假设m=25,把[0,100)这个区间的明文加密映射到[0,1000)中。Assume that m=25, encrypt and map the plaintext in the interval [0,100) to [0,1000).
具体步骤为:The specific steps are:
第一步:HGD(100,1000,500,cc)输出44,因为25<44,所以重新调整domain和range别为[0,44),[0,500);Step 1: HGD(100,1000,500,cc) outputs 44. Since 25<44, the domain and range are readjusted to [0,44) and [0,500) respectively.
第二步:调整后,继续重复进行上述过程。第二次HGD(44,500,250,cc)输出23。因为25>23,所以重新调整domain和range别为[23,44),[250,500)。就这样反复几轮,最后第8步domain为[25,26),大小收敛到1。Step 2: After adjustment, continue to repeat the above process. The second HGD (44,500,250,cc) outputs 23. Because 25>23, the domain and range are readjusted to [23,44) and [250,500) respectively. This is repeated several times, and finally in step 8, the domain is [25,26), and the size converges to 1.
第三步:最后从range区间[298,305]中按上述算法中步骤(6)计算,得到数301作为25的密文。Step 3: Finally, calculate from the range [298,305] according to step (6) of the above algorithm and obtain the number 301 as the ciphertext of 25.
对于密文c,密钥为k,求明文m的具体解密步骤如下:For ciphertext c, key k, the specific decryption steps for plaintext m are as follows:
(1)根据数据类型初始化明密文域为给定的区间,密文域大小为明文域大小比特数的两倍。如数据的类型为int类型,则明文域区间domain=[0,2^32),密文域区间range=[0,2^64),即明文域大小D=2^32,密文域大小R=2^64(1) Initialize the plaintext and ciphertext domain to a given interval according to the data type. The ciphertext domain size is twice the number of bits of the plaintext domain size. For example, if the data type is int, the plaintext domain interval domain = [0, 2^32), and the ciphertext domain interval range = [0, 2^64), that is, the plaintext domain size D = 2^32, and the ciphertext domain size R = 2^64
(2)y=R/2,cc=PRF(k,D,R),计算x=HGD(D,R,y,cc)。(2) y = R/2, cc = PRF(k, D, R), calculate x = HGD(D, R, y, cc).
(3)如果c<min(range)+y,则domain=[min(domain),min(domain)+x),range=[min(range),min(range)+y);否则,domain=[min(domain)+x,max(domain)],range=[min(range)+y,max(range)]。(3) If c<min(range)+y, then domain=[min(domain),min(domain)+x), range=[min(range),min(range)+y); otherwise, domain= [min(domain)+x,max(domain)], range=[min(range)+y,max(range)].
其中min(),max()分别是求给定区间的最小值和最大值的函数。Among them, min() and max() are functions for finding the minimum and maximum values of a given interval respectively.
(4)更新明文域大小和密文域大小:D=domain大小,R=range大小。(4) Update the plaintext domain size and ciphertext domain size: D = domain size, R = range size.
(5)如果D=1,则执行步骤(6)计算明文;否则,返回执行步骤转到(2)。(5) If D=1, execute step (6) to calculate the plaintext; otherwise, return to step (2).
(6)根据min(domain)计算hash值,然后使用AES加密hash值,再将加密结果模R,最后将模R的结果+min(range),如果最后结果等于密文c,则m=min(domain);否则解密失败。(6) Calculate the hash value based on min(domain), then use AES to encrypt the hash value, then apply modulo R to the encrypted result, and finally add min(range) to the result of modulo R. If the final result is equal to the ciphertext c, then m = min(domain); otherwise, the decryption fails.
第(6)步中的校验过程,可以用来发现密文被篡改的情况。如果不考虑密文被篡改的情况,第(6)步可以省略所有的hash和AES加密等过程,直接令m=min(domain)。The verification process in step (6) can be used to detect tampering of the ciphertext. If tampering of the ciphertext is not considered, all hashing and AES encryption processes can be omitted in step (6), and m = min(domain) can be directly set.
本申请的总体技术思路如下:在数据交互终端侧采用保序算法对数值型和字符型数据进行加密,密文与明文的顺序相同,以支持在密文上执行各类比较运算,同时支持使用数据库的索引能力在密文上直接建立索引。而服务端不感知数据加密特性,服务端不做修改。与传统加密技术不同,保序加密可以在不破坏数据顺序的前提下对数据进行加密。这意味着对于需要按照数据顺序进行查询、排序或比较的应用场景,可以在加密状态下继续使用这些功能。The overall technical idea of this application is as follows: an order-preserving algorithm is used on the data interaction terminal side to encrypt numerical and character data. The order of the ciphertext is the same as that of the plaintext to support various comparison operations on the ciphertext, and to support the use of the database's indexing capabilities to directly create indexes on the ciphertext. The server is not aware of the data encryption feature and does not make any modifications. Unlike traditional encryption technology, order-preserving encryption can encrypt data without destroying the order of the data. This means that for application scenarios that require querying, sorting, or comparison in data order, these functions can continue to be used in an encrypted state.
本申请接下来对以下过程进行具体介绍:(1)数据交互终端通过命令创建主密钥。主密钥可以保存在客户端的本地密钥管理系统或第三方密钥管理系统中,数据交互终端将主密钥元数据保存数据库中。(2)数据交互终端通过命令创建列密钥。列密钥通过主密钥加密后保存在数据库中,列密钥元数据也可以保存数据库中。(3)数据交互终端在建表时定义列的加密属性。数据交互终端将这些加密属性作为表加密元数据,保存到数据库中。数据交互终端进行加密元数据缓存处理,将从数据库中查询到的列密钥、密钥属性信息和列加密属性等在客户端进行缓存。(4)数据交互终端进行SQL语句解析处理,根据缓存中的列加密属性元数据,识别加密字段,进行加密处理并进行SQL重写。数据交互终端对查询结果进行处理,根据数据库的返回结果查询加密元数据,获取加密字段对应的列密钥,并对结果进行解密处理。This application will then specifically introduce the following process: (1) The data interaction terminal creates a master key through a command. The master key can be saved in the client's local key management system or a third-party key management system, and the data interaction terminal saves the master key metadata in the database. (2) The data interaction terminal creates a column key through a command. The column key is encrypted with the master key and saved in the database, and the column key metadata can also be saved in the database. (3) The data interaction terminal defines the encryption attributes of the column when creating a table. The data interaction terminal saves these encryption attributes as table encryption metadata in the database. The data interaction terminal performs encryption metadata caching and caches the column keys, key attribute information, and column encryption attributes queried from the database on the client. (4) The data interaction terminal performs SQL statement parsing and identifies the encrypted fields based on the column encryption attribute metadata in the cache, performs encryption processing, and performs SQL rewriting. The data interaction terminal processes the query results, queries the encryption metadata based on the return results of the database, obtains the column keys corresponding to the encrypted fields, and decrypts the results.
本申请可以在不破坏数据顺序的前提下对数据进行加密,能够在实现数据安全的同时,保障数据库查询、比较等业务应用,对于数据库安全有着较强的应用价值,同时不用修改数据库服务端软件,兼容性高。This application can encrypt data without destroying the data order, and can ensure business applications such as database query and comparison while achieving data security. It has strong application value for database security, and at the same time, there is no need to modify the database server software, and it has high compatibility.
以下具体介绍本申请的方案。The solution of this application is described in detail below.
一、过程(4)的详细实施方案1. Detailed implementation plan of process (4)
参见图3,图3为本申请实施例提供的一种数据库操作方法的流程示意图,该方法可以应用于密态数据库系统,如图3所示,该方法包括如下步骤:Referring to FIG. 3 , FIG. 3 is a flow chart of a database operation method provided in an embodiment of the present application. The method can be applied to a secret database system. As shown in FIG. 3 , the method includes the following steps:
S201,数据交互终端获取作用于目标数据库的第一结构化查询语句。S201: The data interaction terminal obtains a first structured query statement acting on a target database.
这里,目标数据库可以为任意一个数据库。Here, the target database can be any database.
第一结构化查询语句为数据操作语句,即前述介绍的DML。The first structured query statement is a data operation statement, namely the DML introduced above.
第一结构化查询语句包括第一表名称、第一列名称和第一数据。第一表名称用于指示第一结构化查询语句作用的数据表(以下称第二数据表),第二数据表可以为目标数据库中的任意一个数据表。第一列名称用于指示第一结构化查询语句指向的数据列(以下称第一数据列),第一数据列是指第一结构化语句在该第二数据表中作用的数据列,也即第二数据表需要进行增加、删除、修改以及查询中的其中一项或多项操作的数据列。第一数据属于第一列名称对应的数据列,即第一数据属于第一数据列中的数据。应理解的是,第一结构化查询语句中包含的表名称、列名称和数据均可以有一个或多个。The first structured query statement includes a first table name, a first column name and a first data. The first table name is used to indicate the data table (hereinafter referred to as the second data table) on which the first structured query statement acts, and the second data table can be any data table in the target database. The first column name is used to indicate the data column (hereinafter referred to as the first data column) pointed to by the first structured query statement, and the first data column refers to the data column in the second data table on which the first structured statement acts, that is, the data column in the second data table that needs to perform one or more operations of adding, deleting, modifying and querying. The first data belongs to the data column corresponding to the first column name, that is, the first data belongs to the data in the first data column. It should be understood that the table name, column name and data contained in the first structured query statement can be one or more.
第一结构化查询语句的一个示例如下:insert into t1(c1,c2)values(100,200),t1为第一表名称,c1和c2均为第一数据表中的第一列名称,100和200分别为第一数据表中的c1列中的数据和c2列中的数据。An example of the first structured query statement is as follows: insert into t1(c1, c2) values(100, 200), where t1 is the name of the first table, c1 and c2 are both the names of the first columns in the first data table, and 100 and 200 are the data in the c1 column and the data in the c2 column in the first data table respectively.
在获取到第一结构化查询语句后,数据交互终端对第一结构化查询语句进行解析,得到第一结构化查询语句中的第一列名称,然后查询目标数据库对应的表加密元数据中是否存在第一结构化查询语句中的第一列名称;如果目标数据库对应的表加密元数据中存在该第一列名称,说明第一数据列中的数据为加密数据,执行步骤S202;如果目标数据库对应的表加密元数据中不存在第一列名称,说明第一数据列中的数据不为加密数据,数据交互终端可以将第一结构化查询语句直接发送给目标数据库,以使得目标数据库执行第一结构化查询语句对应的数据库操作。After obtaining the first structured query statement, the data interaction terminal parses the first structured query statement to obtain the first column name in the first structured query statement, and then queries whether the first column name in the first structured query statement exists in the table encryption metadata corresponding to the target database; if the first column name exists in the table encryption metadata corresponding to the target database, it means that the data in the first data column is encrypted data, and step S202 is executed; if the first column name does not exist in the table encryption metadata corresponding to the target database, it means that the data in the first data column is not encrypted data, and the data interaction terminal can send the first structured query statement directly to the target database, so that the target database executes the database operation corresponding to the first structured query statement.
其中,目标数据库对应的表加密元数据中包含有目标数据库中的数据表对应的列加密信息,有关于列加密信息的具体内容,可参考前述对于表加密元数据的介绍。The table encryption metadata corresponding to the target database includes the column encryption information corresponding to the data table in the target database. For the specific content of the column encryption information, please refer to the above introduction to the table encryption metadata.
在对第一结构化查询语句进行解析后,数据交互终端可以先确定目标数据库对应的表加密元数据中是否存在第一结构化查询语句中的第一表名称;如果目标数据库对应的表加密元数据中存在第一结构化查询语句中的第一表名称,再确定第一表名称对应的表加密元数据中是否存在第一结构化查询语句中的第一列名称;如果目标数据库对应的表加密元数据中不存在第一结构化查询语句中的第一表名称,则说明第一数据表中不含加密数据列,数据交互终端可以将第一结构化查询语句直接发送给目标数据库,以使得目标数据库执行第一结构化查询语句对应的数据库操作。After parsing the first structured query statement, the data interaction terminal can first determine whether the first table name in the first structured query statement exists in the table encryption metadata corresponding to the target database; if the first table name in the first structured query statement exists in the table encryption metadata corresponding to the target database, then determine whether the first column name in the first structured query statement exists in the table encryption metadata corresponding to the first table name; if the first table name in the first structured query statement does not exist in the table encryption metadata corresponding to the target database, it means that the first data table does not contain encrypted data columns, and the data interaction terminal can send the first structured query statement directly to the target database, so that the target database executes the database operation corresponding to the first structured query statement.
目标数据库对应的表加密元数据由数据交互终端通过表加密元数据生成和存储过程保存到目标数据库中,有关于表加密元数据的生成和存储过程,将在后续图4对应的实施例进行详细描述,此处不做过多描述。The table encryption metadata corresponding to the target database is saved to the target database by the data interaction terminal through the table encryption metadata generation and storage process. The generation and storage process of the table encryption metadata will be described in detail in the embodiment corresponding to Figure 4 later, and no further description will be given here.
其中,数据交互终端可以从目标数据库处获取目标数据库对应的表加密元数据;或者,数据交互终端在通过表加密元数据生成和存储过程生成目标数据库对应的表加密元数据后,也可以将目标数据库对应的表加密元数据缓存在本地,这样,数据交互终端也可以从本地缓存中获取目标数据库对应的表加密元数据。Among them, the data interaction terminal can obtain the table encryption metadata corresponding to the target database from the target database; or, after the data interaction terminal generates the table encryption metadata corresponding to the target database through the table encryption metadata generation and storage process, the data interaction terminal can also cache the table encryption metadata corresponding to the target database locally, so that the data interaction terminal can also obtain the table encryption metadata corresponding to the target database from the local cache.
S202,数据交互终端对第一结构化查询语句进行重写,得到第二结构化查询语句,第二结构化查询语句中的数据为对第一结构化查询语句中的数据进行保序加密得到。S202: The data interaction terminal rewrites the first structured query statement to obtain a second structured query statement, where the data in the second structured query statement is obtained by performing order-preserving encryption on the data in the first structured query statement.
这里,数据交互终端对第一结构化查询语句进行重写,得到第二结构化查询语句,是指将第一结构化查询语句中的第一列名称,替换为加密数据列对应的列名称,并对第一结构化查询语句中的第一数据进行保序加密,得到加密数据,将第一结构化查询语句中的第一数据替换为加密数据,以此得到第二结构化查询语句。保序加密为:将明文空间的值按照一定的顺序映射到密文空间,使得在加密后的密文中,明文之间的相对顺序仍然能够被保留,在进行映射时,明文的统计特征被隐藏,以保证算法的安全性。对第一数据进行保序加密,得到加密数据是指,采用前述介绍的ope算法对第一数据进行加密。Here, the data interaction terminal rewrites the first structured query statement to obtain the second structured query statement, which means replacing the first column name in the first structured query statement with the column name corresponding to the encrypted data column, and performing order-preserving encryption on the first data in the first structured query statement to obtain encrypted data, and replacing the first data in the first structured query statement with the encrypted data to obtain the second structured query statement. Order-preserving encryption is: mapping the values of the plaintext space to the ciphertext space in a certain order, so that in the encrypted ciphertext, the relative order between the plaintexts can still be retained, and when mapping, the statistical characteristics of the plaintext are hidden to ensure the security of the algorithm. Performing order-preserving encryption on the first data to obtain encrypted data means encrypting the first data using the ope algorithm introduced above.
数据交互终端可以通过如下步骤A1-A4对第一结构化查询语句进行重写,得到第二结构化查询语句:The data interaction terminal may rewrite the first structured query statement through the following steps A1-A4 to obtain a second structured query statement:
A1、根据目标数据库对应的表加密元数据,确定第一列名称对应的第一列密钥名称和第二列名称。A1. According to the table encryption metadata corresponding to the target database, determine the first column key name and the second column name corresponding to the first column name.
其中,数据交互终端可以根据第一结构化查询语句中的第一表名称,在目标数据库对应的表加密元数据中,确定第一表名称对应的表加密元数据;然后将第一表名称对应的表加密元数据中的列密钥名称,确定为第一列名称对应的第一列密钥名称,并将第一表名称对应的表加密元数据中的替换列名称,确定为第一列名称对应的第二列名称。Among them, the data interaction terminal can determine the table encryption metadata corresponding to the first table name in the table encryption metadata corresponding to the target database according to the first table name in the first structured query statement; then determine the column key name in the table encryption metadata corresponding to the first table name as the first column key name corresponding to the first column name, and determine the replacement column name in the table encryption metadata corresponding to the first table name as the second column name corresponding to the first column name.
A2、根据第一列密钥名称,获取第一列名称对应的第一列密钥。A2. According to the key name of the first column, obtain the key of the first column corresponding to the name of the first column.
其中,数据交互终端可以通过如下步骤A21-A24获取第一列名称对应的第一列密钥:The data interaction terminal can obtain the first column key corresponding to the first column name through the following steps A21-A24:
A21、获取第一列密钥名称对应的第一列密钥元数据和第一加密列密钥。A21. Obtain first column key metadata and first encrypted column key corresponding to the first column key name.
这里,第一列密钥元数据包括第一主密钥名称、第一列密钥名称以及第三算法名称。第一主密钥名称为对第一列密钥名称对应的第一列密钥进行加密和解密所采用的主密钥的名称;第三算法名称为采用第一列密钥对第一列名称对应的数据列进行加密和解密的算法名称,本申请中,第三算法名称可以为ope算法的名称,也可以为其他加密算法的算法名称;第一加密列密钥为采用第一主密钥名称对应的主密钥对第一列名称对应的第一列密钥进行加密得到。Here, the first column key metadata includes the first master key name, the first column key name, and the third algorithm name. The first master key name is the name of the master key used to encrypt and decrypt the first column key corresponding to the first column key name; the third algorithm name is the name of the algorithm that uses the first column key to encrypt and decrypt the data column corresponding to the first column name. In this application, the third algorithm name can be the name of the ope algorithm or the algorithm name of other encryption algorithms; the first encrypted column key is obtained by encrypting the first column key corresponding to the first column name using the master key corresponding to the first master key name.
列密钥元数据和加密列密钥由数据交互终端通过列密钥和列密钥元数据的生成和存储过程保存到目标数据库中,有关于列密钥和列密钥元数据的生成和存储过程,将在后续图5对应的实施例中进行详细描述,此处不做过多描述。The column key metadata and encrypted column key are saved to the target database by the data interaction terminal through the generation and storage process of the column key and column key metadata. The generation and storage process of the column key and column key metadata will be described in detail in the subsequent embodiment corresponding to Figure 5, and no further description will be given here.
在确定第一列密钥名称后,数据交互终端可以从目标数据库处获取第一列密钥名称对应的第一列密钥元数据和第一加密列密钥;或者,数据交互终端在通过列密钥和列加密密钥的生成和存储过程生成列密钥元数据和加密列密钥后,也可以将列密钥元数据和加密列密钥保存缓存在本地,这样,数据交互终端也可以从本地缓存中获取第一列密钥名称对应的第一列密钥元数据和第一加密列密钥。应理解的是,包含该第一列密钥名称的列密钥元数据即为第一列密钥名称对应的第一列密钥元数据,第一列密钥元数据对应的加密列密钥即为第一加密列密钥。After determining the first column key name, the data interaction terminal can obtain the first column key metadata and the first encrypted column key corresponding to the first column key name from the target database; or, after generating the column key metadata and the encrypted column key through the generation and storage process of the column key and the column encryption key, the data interaction terminal can also save the column key metadata and the encrypted column key in the local cache, so that the data interaction terminal can also obtain the first column key metadata and the first encrypted column key corresponding to the first column key name from the local cache. It should be understood that the column key metadata containing the first column key name is the first column key metadata corresponding to the first column key name, and the encrypted column key corresponding to the first column key metadata is the first encrypted column key.
A22、获取第一主密钥名称对应的第一主密钥元数据。A22. Obtain first master key metadata corresponding to the first master key name.
这里,第一主密钥元数据包括第一算法名称和第一密钥路径,第一算法名称为主密钥对应的加解密算法的名称,此处的主密钥对应的加解密算法是指采用第一主密钥名称对应的主密钥对第一列密钥进行加密和解密的算法名称;第一密钥路径为主密钥对应的存储路径,此处的存储路径为第一主密钥名称对应的主密钥的存储路径。第一主密钥元数据还包括第一主密钥名称和主密钥库提供者名称,主密钥库提供者名称是指产生的该第一主密钥名称对应的主密钥的密钥管理模块的名称。Here, the first master key metadata includes the first algorithm name and the first key path. The first algorithm name is the name of the encryption and decryption algorithm corresponding to the master key. The encryption and decryption algorithm corresponding to the master key here refers to the algorithm name for encrypting and decrypting the first column key using the master key corresponding to the first master key name; the first key path is the storage path corresponding to the master key. The storage path here is the storage path of the master key corresponding to the first master key name. The first master key metadata also includes the first master key name and the master key library provider name. The master key library provider name refers to the name of the key management module of the master key corresponding to the first master key name.
主密钥元数据由数据交互终端通过主密钥生成和存储过程保存到目标数据库中,有关于主密钥生成和存储过程,将在后续图6对应的实施例中进行详细描述,此处不做过多描述。The master key metadata is saved to the target database by the data interaction terminal through the master key generation and storage process. The master key generation and storage process will be described in detail in the embodiment corresponding to Figure 6 later, and will not be described in detail here.
在从第一列密钥元数据中获取到第一主密钥名称后,数据交互终端可以从目标数据库处获取第一主密钥名称对应的第一主密钥元数据;或者,数据交互终端在通过主密钥生成和存储过程生成主密钥元数据后,也可以将主密钥元数据缓存在本地,这样,数据交互终端也可以从缓存中获取第一主密钥名称对应的第一主密钥元数据。应理解的是,包含该第一主密钥名称的主密钥元数据即为第一主密钥名称对应的第一主密钥元数据。After obtaining the first master key name from the first column key metadata, the data interaction terminal can obtain the first master key metadata corresponding to the first master key name from the target database; or, after generating the master key metadata through the master key generation and storage process, the data interaction terminal can also cache the master key metadata locally, so that the data interaction terminal can also obtain the first master key metadata corresponding to the first master key name from the cache. It should be understood that the master key metadata containing the first master key name is the first master key metadata corresponding to the first master key name.
A23、根据第一密钥路径和第一主密钥名称,确定第一主密钥名称对应的第一主密钥。A23. Determine the first master key corresponding to the first master key name according to the first key path and the first master key name.
其中,如果第一主密钥元数据中的密钥库提供者名称为本地密钥管理模块的名称,则数据交互终端中的本地密钥管理模块可以根据第一密钥路径和第一主密钥名称,获取该第一主密钥。If the key library provider name in the first master key metadata is the name of the local key management module, the local key management module in the data interaction terminal can obtain the first master key according to the first key path and the first master key name.
可选地,如果第一主密钥元数据中的密钥库提供者名称为第三方密钥管理模块的名称,则数据交互终端可以将第一主密钥元数据发送给第三方密钥管理模块,由第三方密钥管理模块根据第一密钥路径和第一主密钥名称,获取该第一主密钥。Optionally, if the key library provider name in the first master key metadata is the name of a third-party key management module, the data interaction terminal can send the first master key metadata to the third-party key management module, and the third-party key management module obtains the first master key based on the first key path and the first master key name.
A24、根据第一主密钥和第一算法名称对应的加解密算法,对第一加密列密钥进行解密,得到第一列密钥。A24. Decrypt the first encrypted column key according to the encryption/decryption algorithm corresponding to the first master key and the first algorithm name to obtain a first column key.
其中,如果第一主密钥元数据中的密钥库提供者名称为本地密钥管理模块的名称,则数据交互终端中的本地密钥管理模块可以根据第一主密钥和第一算法名称对应的加解密算法,对第一加密列密钥进行解密,获得解密后的列密钥,得到第一列密钥。Among them, if the key library provider name in the first master key metadata is the name of the local key management module, the local key management module in the data interaction terminal can decrypt the first encrypted column key according to the encryption and decryption algorithm corresponding to the first master key and the first algorithm name, obtain the decrypted column key, and obtain the first column key.
可选地,如果第一主密钥元数据中的密钥库提供者名称为第三方密钥管理模块的名称,则数据交互终端可以将第一主密钥元数据和第一加密列密钥发送给第三方密钥管理模块,第三方密钥管理模块根据第一密钥路径和第一主密钥名称获取到第一主密钥后,采用第一主密钥和第一算法名称对应的加解密算法,对第一加密列密钥进行解密,获得解密后的列密钥;第三方密钥管理模块将解密后的列密钥发送给数据交互终端,得到第一列密钥。Optionally, if the key library provider name in the first master key metadata is the name of a third-party key management module, the data interaction terminal may send the first master key metadata and the first encrypted column key to the third-party key management module. After the third-party key management module obtains the first master key according to the first key path and the first master key name, it uses the encryption and decryption algorithm corresponding to the first master key and the first algorithm name to decrypt the first encrypted column key to obtain the decrypted column key; the third-party key management module sends the decrypted column key to the data interaction terminal to obtain the first column key.
A3、根据第一列名称对应的第一列密钥对第一数据进行保序加密,得到第二数据。A3. Perform order-preserving encryption on the first data according to the first column key corresponding to the first column name to obtain second data.
这里,根据第一列名称对应的第一列密钥对第一数据进行保序加密,是指将第一列密钥作为加密密钥,采用ope算法对第一数据进行加密,有关于ope算法的具体原理,可参见前述对ope算法的介绍,此处不再赘述。Here, the first data is encrypted in an order-preserving manner according to the first column key corresponding to the first column name, which means that the first column key is used as the encryption key and the first data is encrypted using the OPE algorithm. For the specific principles of the OPE algorithm, please refer to the aforementioned introduction to the OPE algorithm, which will not be repeated here.
第一数据的数据类型不同,对第一数据进行保序加密的具体实现方式会有所不同,以下进行分别介绍。The specific implementation methods of performing order-preserving encryption on the first data may be different depending on the data type of the first data, which are introduced separately below.
第一种情况:第一数据为整数(int)型数据。The first case: the first data is integer (int) type data.
在此种情况下,数据交互终端可以计算第一数据与第二预设负整数的差值,得到第一差值;将第一差值作为无符号整数进行处理,根据第一列名称对应的第一列密钥对第一差值进行保序加密,得到第二数据。第二预设负整数可根据第一列名称对应的原始数据类型大小确定。In this case, the data interaction terminal can calculate the difference between the first data and the second preset negative integer to obtain the first difference; process the first difference as an unsigned integer, and encrypt the first difference in order according to the first column key corresponding to the first column name to obtain the second data. The second preset negative integer can be determined according to the size of the original data type corresponding to the first column name.
以第一列名称对应的第一数据列中的数据为单字节整数为例,单字节整数的最小负整数为-128,则第二预设负整数为-128,对于第一数据1和-1,计算第一数据与-128的差值,得到第一差值:1-(-128)=129(二进制编码为1000 0001),-1-(-128)=127(二进制编码为0111 1111);将第一差值作为无符号整数进行处理,根据第一列密钥进行保序加密,即ope(1)=ope(10000001),ope(-1)=ope(0111 1111);即ope(1)=ope(1000 0001)>ope(-1)=ope(0111 1111)。Taking the case where the data in the first data column corresponding to the first column name is a single-byte integer, the minimum negative integer of the single-byte integer is -128, and the second preset negative integer is -128. For the first data 1 and -1, the difference between the first data and -128 is calculated to obtain the first difference: 1-(-128)=129 (binary encoding is 1000 0001), -1-(-128)=127 (binary encoding is 0111 1111); the first difference is processed as an unsigned integer and encrypted in order according to the first column key, that is, ope(1)=ope(10000001), ope(-1)=ope(0111 1111); that is, ope(1)=ope(1000 0001)>ope(-1)=ope(0111 1111).
可见,对于整数型数据,通过先计算整数型数据与最小负整数的差值,再对差值进行保序加密,能够使得加密前后的数据之间的顺序性一致。It can be seen that for integer data, by first calculating the difference between the integer data and the smallest negative integer and then encrypting the difference in order, the order of the data before and after encryption can be made consistent.
第二种情况:第一数据为浮点(float)型数据The second case: the first data is floating point data
在此种情况下,如果第一数据为正浮点型数据,数据交互终端可以存储第一数据的字节作为整数处理所得到的整数,得到第一整数;计算第一整数与最小编码的差值,得到待加密编码;将待加密编码作为无符号整数进行处理,根据第一列名称对应的第一列密钥对待加密编码进行保序加密,得到第二数据。其中,最小编码为第一数据所占字节数对应的最小负整数的二进制编码。如果该第一数据为单精度浮点数,则第一数据所占字节数为4字节,最小编码的位数为32位,最小编码为:1 0000 0000 0000 0000 0000 0000 0000 000;如果该第一数据为双精度浮点数,则第一数据所占字节数为8字节,最小编码的位数为64位,最小编码为:1 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 00000000 0000 0000 000。In this case, if the first data is positive floating point data, the data exchange terminal can store the bytes of the first data as an integer obtained by integer processing to obtain the first integer; calculate the difference between the first integer and the minimum code to obtain the code to be encrypted; process the code to be encrypted as an unsigned integer, and encrypt the code to be encrypted in order according to the first column key corresponding to the first column name to obtain the second data. Among them, the minimum code is the binary code of the smallest negative integer corresponding to the number of bytes occupied by the first data. If the first data is a single-precision floating-point number, the number of bytes occupied by the first data is 4 bytes, the minimum number of bits of the encoding is 32 bits, and the minimum encoding is: 1 0000 0000 0000 0000 0000 0000 0000 000; if the first data is a double-precision floating-point number, the number of bytes occupied by the first data is 8 bytes, the minimum number of bits of the encoding is 64 bits, and the minimum encoding is: 1 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 00000000 0000 0000 0000 0000 0000 0000.
以第一列名称对应的第一数据列中的数据为单精度浮点数为例,假设第一数据为单精度浮点数85.125。首先,按IEEE754标准,存储第一数据的字节为第一整数:0 10000101 01010100 1000 0000 0000 000;再计算第一整数与最小编码的差值,得到待加密编码,待加密编码为:1 1000 0101 0101 0100 1000 0000 0000 000;将待加密编码作为无符号整数进行处理,对待加密编码进行ope保序加密,即ope(85.125)=ope(1 1000 01010101 0100 1000 0000 0000000)。Taking the data in the first data column corresponding to the first column name as a single-precision floating-point number as an example, assuming that the first data is a single-precision floating-point number 85.125. First, according to the IEEE754 standard, the byte storing the first data is the first integer: 0 10000101 01010100 1000 0000 0000 000; then calculate the difference between the first integer and the minimum code to obtain the code to be encrypted, which is: 1 1000 0101 0101 0100 1000 0000 0000 000; treat the code to be encrypted as an unsigned integer, and perform ope order-preserving encryption on the code to be encrypted, that is, ope(85.125)=ope(1 1000 01010101 0100 1000 0000 0000000).
如果第一数据为负浮点型数据,数据交互终端可以计算第一数据对应的第一整数的二进制补码,得到第一补码,第一数据对应的第一整数为将存储第一数据的字节作为整数处理所得到的整数;计算第一补码与最小编码的差值,得到待加密编码;根据第一列密钥,将待加密编码作为无符号整数进行处理,对待加密编码进行保序加密,得到第二数据。最小编码为第一数据所占字节数对应的最小负整数的二进制编码,第一数据所占字节数对应的最小负整数可根据第一列名称对应的原始数据类型大小确定。If the first data is negative floating-point data, the data interaction terminal can calculate the binary complement of the first integer corresponding to the first data to obtain the first complement, and the first integer corresponding to the first data is the integer obtained by treating the bytes storing the first data as integers; calculate the difference between the first complement and the minimum code to obtain the code to be encrypted; according to the first column key, treat the code to be encrypted as an unsigned integer, encrypt the code to be encrypted in order to obtain the second data. The minimum code is the binary code of the smallest negative integer corresponding to the number of bytes occupied by the first data, and the smallest negative integer corresponding to the number of bytes occupied by the first data can be determined according to the size of the original data type corresponding to the first column name.
仍以第一列名称对应的第一数据列中的数据为单精度浮点数为例,假设第一数据为单精度浮点数-85.125,第一数据对应的第一整数的二进制编码表示为:11000010101010100100000000000000;对其除了符号位以外求反码为:10111101010101011011111111111111,再进行+1得到第一补码为:1 0111 1010 1010 10111000 0000 0000000,对其减去最小负整数:1 0000 0000 0000 0000 0000 0000 0000000,得到的值为:0 01111010 1010 1011 1000 0000 0000 000,对该值进行ope保序加密,即ope(-85.125)=ope(0 01111010 1010 1011 1000 0000 0000 000)。Still taking the data in the first data column corresponding to the first column name as a single-precision floating-point number as an example, assuming that the first data is a single-precision floating-point number -85.125, the binary code of the first integer corresponding to the first data is: 11000010101010100100000000000000; the inverse code except the sign bit is: 101111010101010101101111111111111, and then adding 1 to get the first complement code: 1 0111 1010 1010 10111000 0000 0000000, subtract the smallest negative integer: 1 0000 0000 0000 0000 0000 0000 0000000, and the value obtained is: 0 01111010 1010 1011 1000 0000 0000 000, perform ope order-preserving encryption on the value, that is, ope(-85.125)=ope(0 01111010 1010 1011 1000 0000 0000 000).
对于浮点型数据,对正浮点型数据和负浮点型数据进行预处理后再进行保序加密,能够使得保序加密后的排序结果与加密前的排序结果相同。For floating-point data, positive floating-point data and negative floating-point data are preprocessed and then encrypted in an order-preserving manner, so that the sorting result after the order-preserving encryption is the same as the sorting result before encryption.
第三种情况:第一数据为字符型数据The third case: the first data is character data
在此种情况下,数据交互终端可以在第一数据的右侧填充预设字符,得到第一数据对应的标准字符,第一数据对应的标准字符的字符长度为预设字符长度;根据第一列名称对应的第一列密钥,将第一数据对应的标准字符的ASCII编码作为无符号整数进行处理,对第一数据对应的标准字符的ASCII编码进行保序加密,得到第二数据。预设字符长度为第一列名称对应的数据列所定义的最大字符长度,预设字符长度由第一列名称对应的原始数据类型大小确定。In this case, the data interaction terminal can fill the right side of the first data with preset characters to obtain the standard characters corresponding to the first data, and the character length of the standard characters corresponding to the first data is the preset character length; according to the first column key corresponding to the first column name, the ASCII code of the standard characters corresponding to the first data is processed as an unsigned integer, and the ASCII code of the standard characters corresponding to the first data is encrypted in an order-preserving manner to obtain the second data. The preset character length is the maximum character length defined by the data column corresponding to the first column name, and the preset character length is determined by the size of the original data type corresponding to the first column name.
其中,如果第一数据为定长字符型数据(char),预设字符为空格的ASCII字符,可以在第一数据的右侧填充ASCII编码为32的空格字符,直至第一数据的字符长度为预设字符长度(即字符字段宽度),得到第一数据对应的标准字符。Among them, if the first data is fixed-length character data (char), and the preset character is an ASCII character of a space, a space character with an ASCII code of 32 can be filled on the right side of the first data until the character length of the first data is the preset character length (i.e., the character field width) to obtain the standard character corresponding to the first data.
例如,预设字符长度为3。对于字符‘a’,其字符长度为1,在字符‘a’右侧填充2个空格字符后得到的标准字符为‘a’,a的ASCII编码为0x61,空格字符的ASCII编码0x20,则标准字符的ASCII编码为:0x61 20 20,再对标准字符的的ASCII编码进行ope保序加密,即ope(a)=ope(0x61 20 20)。对于字符串‘abc’,其字符长度为3,字符串‘abc’即为标准字符,a的ASCII为0x61,b为0x62,c为0x63,则标准字符的ASCII编码为:0x61 62 63;再对标准字符的ASCII编码进行ope保序加密,即ope(abc)=ope(0x61 62 63)。For example, the preset character length is 3. For the character ‘a’, its character length is 1. After padding 2 space characters on the right side of the character ‘a’, the standard character obtained is ‘a’. The ASCII code of a is 0x61, and the ASCII code of the space character is 0x20. The ASCII code of the standard character is: 0x61 20 20. Then the ASCII code of the standard character is ope-order-preserving encryption, that is, ope(a)=ope(0x61 20 20). For the string ‘abc’, its character length is 3. The string ‘abc’ is the standard character. The ASCII code of a is 0x61, b is 0x62, and c is 0x63. Then the ASCII code of the standard character is: 0x61 62 63. Then the ASCII code of the standard character is ope-order-preserving encryption, that is, ope(abc)=ope(0x61 62 63).
如果第一数据为变长字符型数据(varchar),预设字符为任一小于空格的ASCII字符,可以在第一数据的右侧填充ASCII编码小于空格的字符,直至第一数据的字符长度为预设字符长度(即字符字段宽度)度,得到第一数据对应的标准字符。例如可以在第一数据的右侧填充ASCII编码为31的不可见字符。If the first data is variable-length character data (varchar), and the preset character is any ASCII character that is smaller than a space, characters whose ASCII codes are smaller than a space may be padded on the right side of the first data until the character length of the first data reaches the preset character length (i.e., the character field width), thereby obtaining the standard characters corresponding to the first data. For example, an invisible character whose ASCII code is 31 may be padded on the right side of the first data.
仍以预设字符长度为3为例,ASCII编码为31的不可见字符的ASCII编码为1F,对于字符‘a’,其对应的标准字符对应的ASCII编码为0x61 1F 1F。Still taking the preset character length of 3 as an example, the ASCII code of the invisible character with ASCII code 31 is 1F. For the character 'a', the ASCII code corresponding to the standard character is 0x61 1F 1F.
第四种情况:第一数据为定长数值(Numeric)型数据。The fourth case: the first data is fixed-length numeric data.
在此种情况下,在一种可行的实施方式中,数据交互终端可以将第一数据减去第一预设负数,得到第一数据对应的第一正数;对第一数据对应的第一正数进行小数补零处理,得到第二正数,第二正数的小数位数为预设位数;根据第一列密钥,对第二正数对应的第一正整数进行保序加密,得到第二数据,第一正整数为忽略第二正数中的小数点得到的整数,也即将第二正数中的小数点忽略不计,视为整数看待。预设位数为第一列名称对应的数据列所定义的小数位数,第一预设负数为任一小于或等于第一负数的负数,第一负数为第一列名称对应的数据列所定义的最小负数。第一预设负数和预设位数由第一列名称对应的原始数据类型大小确定。例如,第一列名称对应的数据列的定义为Numeric(4,2),即所有的数字位数为4位,小数位数为2,则预设位数为2,第一预设负数可以为-99.99,或者,第一预设负数也可以为-100,或者,也可以为-101,等等;又如,第一列名称对应的数据列的定义为Numeric(7,3),即所有的数字位数为7位,小数位数为3,则预设位数为3,第一预设负数可以为-9999.999,或者,第一预设负数也可以为-10000,等等。In this case, in a feasible implementation, the data interaction terminal can subtract the first preset negative number from the first data to obtain the first positive number corresponding to the first data; perform zero padding on the first positive number corresponding to the first data to obtain a second positive number, and the number of decimal places of the second positive number is the preset number of places; according to the first column key, the first positive integer corresponding to the second positive number is encrypted in an order-preserving manner to obtain the second data, and the first positive integer is an integer obtained by ignoring the decimal point in the second positive number, that is, the decimal point in the second positive number is ignored and regarded as an integer. The preset number of places is the number of decimal places defined by the data column corresponding to the first column name, the first preset negative number is any negative number less than or equal to the first negative number, and the first negative number is the minimum negative number defined by the data column corresponding to the first column name. The first preset negative number and the preset number of places are determined by the size of the original data type corresponding to the first column name. For example, the definition of the data column corresponding to the first column name is Numeric(4,2), that is, all the digits are 4 digits and the number of decimal places is 2, then the preset number of digits is 2, and the first preset negative number can be -99.99, or the first preset negative number can also be -100, or -101, and so on; for another example, the definition of the data column corresponding to the first column name is Numeric(7,3), that is, all the digits are 7 digits and the number of decimal places is 3, then the preset number of digits is 3, and the first preset negative number can be -9999.999, or the first preset negative number can also be -10000, and so on.
以第一数据为10.0为例,假设第一列名称对应的数据列的定义为Numeric(4,2),第一预设负数为-99.99。将第一数据减去第一预设负数,得到第一数据对应的第一正数为:109.99;由于109.99的小数位数为2位,正好为预设位数,则第二正数为109.99;忽略第二正数中的小数点,得到第一正整数为10999;再对第一正整数进行保序加密,即ope(10.0)=ope(10999)。Take the first data 10.0 as an example, assuming that the definition of the data column corresponding to the first column name is Numeric(4,2), and the first preset negative number is -99.99. Subtract the first preset negative number from the first data, and the first positive number corresponding to the first data is: 109.99; since the decimal place of 109.99 is 2, which is exactly the preset place, the second positive number is 109.99; ignore the decimal point in the second positive number, and the first positive integer is 10999; then perform order-preserving encryption on the first positive integer, that is, ope(10.0)=ope(10999).
以第一数据为10.0为例,假设第一列名称对应的数据列的定义为Numeric(4,2),第一预设负数为-100。将第一数据减去第一预设负数,得到第一数据对应的第一正数为:110.0;由于110.0的小数位数为1位,小数位不足2位,则对第一正数进行小数补零处理,得到的第二正数为110.00;忽略第二正数中的小数点,得到第一正整数为11000;再对第一正整数进行保序加密,即ope(10.0)=ope(11000)。Take the first data 10.0 as an example, assuming that the definition of the data column corresponding to the first column name is Numeric(4,2), and the first preset negative number is -100. Subtract the first preset negative number from the first data, and the first positive number corresponding to the first data is: 110.0; since the decimal place of 110.0 is 1, and the decimal place is less than 2, the first positive number is padded with zeros, and the second positive number is 110.00; the decimal point in the second positive number is ignored, and the first positive integer is 11000; and the first positive integer is encrypted in order, that is, ope(10.0)=ope(11000).
在另一种可行的实施方式中,数据交互终端也可以对第一数据进行小数补零处理,得到标准数字,标准数字的小数位数为预设位数;将标准数字对应的第二整数减去第一预设负整数,得到第一正整数,标准数字对应的第二整数为忽略标准数字中的小数点所得到的整数;根据第一列密钥,对第一正整数进行保序加密,得到第二数据。预设位数为第一列名称对应的数据列所定义的小数位数,第一预设负整数为任一小于或等于目标负数的负整数,目标负数为第一列名称的数据列所定义的所有数字位数能表达的最小负数,预设位数和第一预设负整数由第一列名称对应的原始数据类型大小确定。例如,第一列名称对应的数据列的定义为Numeric(4,2),即所有的数字位数为4位,小数位数为2,则预设位数为2,第一预设负整数可以为-9999;或者,第一预设负数也可以为-10000,或者,也可以为-10001,等等;又如,第一列名称对应的数据列的定义为Numeric(7,3),即所有的数字位数为7位,小数位数为3,则预设位数为3,第一预设负整数可以为-9999999,或者,第一预设负整数也可以为-10000000,等等。In another feasible implementation, the data interaction terminal may also perform zero padding on the first data to obtain a standard number, the number of decimal places of the standard number is a preset number of places; the first positive integer is obtained by subtracting the first preset negative integer from the second integer corresponding to the standard number, the second integer corresponding to the standard number is the integer obtained by ignoring the decimal point in the standard number; the first positive integer is encrypted in order according to the first column key to obtain the second data. The preset number of places is the number of decimal places defined by the data column corresponding to the first column name, the first preset negative integer is any negative integer less than or equal to the target negative number, the target negative number is the minimum negative number that can be expressed by all the digits defined by the data column of the first column name, and the preset number of places and the first preset negative integer are determined by the size of the original data type corresponding to the first column name. For example, the definition of the data column corresponding to the first column name is Numeric(4,2), that is, all the digits are 4 digits and the number of decimal places is 2, then the preset number of digits is 2, and the first preset negative integer can be -9999; or, the first preset negative number can also be -10000, or, it can also be -10001, and so on; for another example, the definition of the data column corresponding to the first column name is Numeric(7,3), that is, all the digits are 7 digits and the number of decimal places is 3, then the preset number of digits is 3, and the first preset negative integer can be -9999999, or, the first preset negative integer can also be -10000000, and so on.
仍以第一数据10.0为例,假设第一列名称对应的数据列的定义为Numeric(4,2),第一预设负整数为-9999,则对第一数据进行小数补零处理,得到标准数字10.00;忽略标准数字中的小数点,得到第二正数1000;减去第一预设负整数-9999,得到第一正整数为10999;再对第一正整数进行保序加密,即ope(10.0)=ope(10999)。Still taking the first data 10.0 as an example, assuming that the definition of the data column corresponding to the first column name is Numeric(4,2), and the first preset negative integer is -9999, the first data is padded with zeros to obtain the standard number 10.00; the decimal point in the standard number is ignored to obtain the second positive number 1000; the first preset negative integer -9999 is subtracted to obtain the first positive integer 10999; and the first positive integer is encrypted in an order-preserving manner, that is, ope(10.0)=ope(10999).
其中,在根据第一列密钥,对第一正整数进行保序加密,得到第二数据的过程中,数据交互终端还可以从第一正整数的最低位开始,对第一正整数进行合并,得到第二正整数;根据第一列密钥,对第二正整数进行加密,得到第二数据。其中,可以将相邻两个字节中的高位字节的将相邻两个字节中的高位字节的低4位作为合并字节的高4位,并将低位字节的低4位作为合并字节的低4位,即相邻2字节中,高位字节作为合并字节的高4位,低位字节的低4为作为合并字节的低4位对第一正整数进行合并,得到第二正整数。In the process of encrypting the first positive integer in order according to the first column key to obtain the second data, the data interaction terminal can also merge the first positive integer starting from the lowest bit of the first positive integer to obtain the second positive integer; and encrypt the second positive integer according to the first column key to obtain the second data. In the process of encrypting the first positive integer in order according to the first column key to obtain the second data, the data interaction terminal can also merge the first positive integer starting from the lowest bit of the first positive integer to obtain the second positive integer; and encrypt the second positive integer according to the first column key to obtain the second data. In the process of encrypting the first positive integer in order according to the first column key to obtain the second data, the low 4 bits of the high byte of the high byte of the two adjacent bytes can be used as the high 4 bits of the merged byte, and the low 4 bits of the low byte can be used as the low 4 bits of the merged byte, that is, in the adjacent 2 bytes, the high byte is used as the high 4 bits of the merged byte, and the low 4 bits of the low byte are used as the low 4 bits of the merged byte to merge the first positive integer to obtain the second positive integer.
例如对于11711,将其看为大整数,合并前为0x01 0107 0101,合并后为0X011711。合并后存储开销减少,加密的计算量也大为减少。For example, for 11711, it is considered as a large integer, which is 0x01 0107 0101 before merging and 0X011711 after merging. After merging, the storage overhead is reduced and the amount of encryption calculation is also greatly reduced.
需要说明的是,如果第一列密钥元数据中的第三算法名称为其他加密算法的名称,则可以将第一密钥作为加密密钥,采用该其他加密算法对第一数据进行加密。It should be noted that if the third algorithm name in the first column of key metadata is the name of another encryption algorithm, the first key can be used as an encryption key, and the other encryption algorithm can be used to encrypt the first data.
可选地,在根据第一列名称对应的第一列密钥对第一数据进行保序加密,得到第二数据之后,还可以对第二数据进行基于扩展编码方式进行编码,得到第三数据,扩展编码方式为基于标准Base64编码的扩展编码方式。其中,对第二数据进行基于扩展编码方式进行编码,得到第三数据,包括:按基于标准Base64编码的扩展编码表,对第二数据进行编码,得到第二数据对应的Base64扩展码,基于标准Base64编码的扩展编码表为将ASCII标准中的可见字符任意取出64个,并按值大小顺序排列得到;将Base64扩展码对应的ASCII编码,作为第三数据。Optionally, after the first data is encrypted in order according to the first column key corresponding to the first column name to obtain the second data, the second data can also be encoded based on an extended encoding method to obtain third data, and the extended encoding method is an extended encoding method based on standard Base64 encoding. Among them, encoding the second data based on the extended encoding method to obtain the third data includes: encoding the second data according to an extended encoding table based on standard Base64 encoding to obtain the Base64 extended code corresponding to the second data, and the extended encoding table based on standard Base64 encoding is obtained by randomly taking out 64 visible characters in the ASCII standard and arranging them in order of value size; using the ASCII code corresponding to the Base64 extended code as the third data.
示例性地,基于标准Base64编码的扩展编码表可以如下表所示。Exemplarily, an extended encoding table based on standard Base64 encoding may be shown in the following table.
例如,第二数据为二进制编码x和y,x=000000,y=110100;基于表中所示的扩展编码表对x和y进行Base64扩展编码,得到第二数据对应的Base64扩展码:base64_ope(x)=+,base64_ope(y)=o;然后将Base64扩展码对应的ASCII编码,作为第三数据,x对应的第三数据为0x2B;y对应的第三数据为0x6f。For example, the second data is binary code x and y, x=000000, y=110100; based on the extended coding table shown in the table, x and y are Base64 extended encoded to obtain the Base64 extended code corresponding to the second data: base64_ope(x)=+, base64_ope(y)=o; then the ASCII code corresponding to the Base64 extended code is used as the third data, the third data corresponding to x is 0x2B; the third data corresponding to y is 0x6f.
应理解的是,上述仅为本申请提供的基于Base64编码的扩展编码表的其中一种实现方式;凡是将ASCII标准中的可见字符任意取出64个,并按值大小顺序排列得到的基于Base64编码的扩展编码表均在本申请的保护范围内,例如,还可以将表1中的“+”,替换为“(”,得到一张新的扩展编码表。It should be understood that the above is only one of the implementation methods of the extended code table based on Base64 encoding provided by this application; any extended code table based on Base64 encoding obtained by randomly taking out 64 visible characters in the ASCII standard and arranging them in order of value size is within the protection scope of this application. For example, the "+" in Table 1 can also be replaced with "(" to obtain a new extended code table.
还需要说明的是,在按照上述方式对第二数据进行处理得到第三数据的情况下,数据交互终端在从目标数据库中查询到第三数据后,需要对第三数据进行反向解码,将查询到的结果恢复为原本的第二数据。例如,从目标数据库中查询到的第三数据对应的Base64扩展码为“+”,再根据上表确定第二数据为000000。It should also be noted that, when the second data is processed in the above manner to obtain the third data, after the data interaction terminal queries the third data from the target database, it is necessary to reversely decode the third data and restore the query result to the original second data. For example, the Base64 extension code corresponding to the third data queried from the target database is "+", and the second data is determined to be 000000 according to the above table.
A4、将第一结构化查询语句中的第一列名称重写为第二列名称,并将第一结构化查询语句中的第一数据重写为第二数据,得到第二结构化查询语句。A4. Rewrite the first column name in the first structured query statement into the second column name, and rewrite the first data in the first structured query statement into the second data, to obtain a second structured query statement.
例如,第一结构化查询语句为:insert into t1(c1,c2)values(100,200),假设c1列是加密列,c1为第一列名称,其对应的第二列名称为d1,对值100进行保序加密得到的加密值为78,则重写得到的第二结构化查询语句为insert into t1(d1,c2)values(78,200)。For example, the first structured query statement is: insert into t1(c1, c2) values(100, 200). Assume that column c1 is an encrypted column, c1 is the name of the first column, and its corresponding second column name is d1. The encrypted value obtained by encrypting the value 100 in an order-preserving manner is 78. Then the rewritten second structured query statement is insert into t1(d1, c2) values(78, 200).
其中,在根据第一列名称对应的第一列密钥对第一数据进行保序加密,得到第二数据之后,还对第二数据进行基于扩展编码方式进行编码,得到第三数据的情况下,在对第一结构化查询语句进行重写的过程中,是将第一结构化查询语句中的第一数据重写为第三数据,得到第二结构化查询语句,即上述步骤A4替换为:将第一结构化查询语句中的第一列名称重写为第二列名称,并将第一结构化查询语句中的第一数据重写为第三数据,得到第二结构化查询语句。Among them, after the first data is encrypted in an order-preserving manner according to the first column key corresponding to the first column name to obtain the second data, the second data is also encoded based on the extended encoding method to obtain the third data. In the process of rewriting the first structured query statement, the first data in the first structured query statement is rewritten into the third data to obtain the second structured query statement, that is, the above step A4 is replaced by: rewriting the first column name in the first structured query statement into the second column name, and rewriting the first data in the first structured query statement into the third data to obtain the second structured query statement.
S203,数据交互终端向目标数据库发送第二结构化查询语句,目标数据库接收第二结构化查询语句。S203: The data interaction terminal sends a second structured query statement to the target database, and the target database receives the second structured query statement.
S204,目标数据库执行第二结构化查询语句对应的数据库操作,得到第一操作结果数据。S204: The target database executes the database operation corresponding to the second structured query statement to obtain first operation result data.
其中,第一操作结果数据包括第二列名称和第四数据,第四数据为加密数据。The first operation result data includes the second column name and fourth data, and the fourth data is encrypted data.
S205,目标数据库向数据交互终端发送第一操作结果数据,数据交互终端接收接第一操作结果数据。S205: The target database sends first operation result data to the data interaction terminal, and the data interaction terminal receives the first operation result data.
S206,数据交互终端对第一操作结果数据进行数据还原,得到第一结构化查询语句对应的第二操作结果数据。S206: The data interaction terminal restores the first operation result data to obtain second operation result data corresponding to the first structured query statement.
这里,数据交互终端对第一操作结果数据进行数据还原,是指将第一操作结果数据中的第二列名称还原为第一列名称,以及对第三数据解密得到原始数据的过程。Here, the data interaction terminal performs data restoration on the first operation result data, which refers to a process of restoring the second column name in the first operation result data to the first column name, and decrypting the third data to obtain the original data.
其中,在第一操作结果数据中的第四数据为经过扩展编码处理后的数据的情况下,第四数据的形式与前述步骤A3中介绍的第三数据的形式相同,数据交互终端在接收到第一操作结果数据之后,还需要对第一操作结果数据中的第四数据进行扩展解码,得到其对应的原始操作结果数据,再对原始操作结果数据进行数据还原。对第四数据进行扩展解码,得到其对应的原始操作结果数据的方法可参考前述步骤A3的有关描述。Wherein, in the case where the fourth data in the first operation result data is data after extended coding processing, the form of the fourth data is the same as the form of the third data introduced in the aforementioned step A3. After receiving the first operation result data, the data interaction terminal needs to perform extended decoding on the fourth data in the first operation result data to obtain the corresponding original operation result data, and then restore the original operation result data. The method of performing extended decoding on the fourth data to obtain the corresponding original operation result data can refer to the relevant description of the aforementioned step A3.
数据交互终端可以通过如下步骤B1-B4对第一操作结果数据(可以是指扩展解码后的原始操作结果数据)进行数据还原,得到第一结构化查询语句对应的第二操作结果数据:The data interaction terminal may restore the first operation result data (which may refer to the original operation result data after extended decoding) through the following steps B1-B4 to obtain the second operation result data corresponding to the first structured query statement:
B1、根据目标数据库对应的表加密元数据确定第二列名称对应的第一列名称和第二列名称对应的第一列密钥名称。B1. Determine the first column name corresponding to the second column name and the first column key name corresponding to the second column name according to the table encryption metadata corresponding to the target database.
这里,数据交互终端在目标数据库对应的表加密元数据中,确定第二列名称对应的表加密元数据,第二列名称对应的表加密元数据包含该第二列名称;然后将第二列名称对应的表加密元数据中的列密钥名称,确定为第二列名称对应的第一列密钥名称,并将第二列名称对应的表加密元数据中的原始列名称,确定为第二列名称对应的第一列名称。Here, the data interaction terminal determines the table encryption metadata corresponding to the second column name in the table encryption metadata corresponding to the target database, and the table encryption metadata corresponding to the second column name includes the second column name; then the column key name in the table encryption metadata corresponding to the second column name is determined as the first column key name corresponding to the second column name, and the original column name in the table encryption metadata corresponding to the second column name is determined as the first column name corresponding to the second column name.
B2、数据交互终端根据第一列密钥名称,获取第二列名称对应的第一列密钥。B2. The data interaction terminal obtains the first column key corresponding to the second column name according to the first column key name.
这里,数据交互终端根据第一列密钥名称,获取第一列密钥的具体实现原理,可参考前述步骤A21-A24的描述,此处不再赘述。Here, the data interaction terminal obtains the specific implementation principle of the first column key according to the first column key name. Please refer to the description of the above steps A21-A24, which will not be repeated here.
B3、数据交互终端根据第二列名称对应的第一列密钥,对第四数据进行解密,得到第五数据。B3. The data interaction terminal decrypts the fourth data according to the first column key corresponding to the second column name to obtain the fifth data.
这里,根据第二列名称对应的第一列密钥,对第三数据进行解密,是指将第一列密钥作为解密密钥,采用ope算法对第四数据进行解密,有关于ope算法的具体原理,可参见前述对ope算法的介绍,此处不再赘述。Here, decrypting the third data according to the first column key corresponding to the second column name means using the first column key as the decryption key and using the OPE algorithm to decrypt the fourth data. For the specific principles of the OPE algorithm, please refer to the aforementioned introduction to the OPE algorithm, which will not be repeated here.
B4、数据交互终端将第一列名称和第五数据确定为第一结构化查询语句对应的第二操作结果数据。B4. The data interaction terminal determines the first column name and the fifth data as the second operation result data corresponding to the first structured query statement.
需要说明的是,由于数据交互终端在对数据进行保序加密时,是将数据处理为数值型数据后再进行保序加密(参见前述步骤A3的有关介绍),因此,第四数据和第五数据均为数值型数据,而数据的原始类型可以为前述介绍的整数型数据、浮点型数据、字符型数据以及数值型数据中的其中一种数据,在解密得到第五数据后,还需将第五数据还原为其原始的数据类型,将数据还原为原始的数据类型为前述步骤A3介绍的保序加密的四种情况的逆运算。It should be noted that, since the data interaction terminal processes the data into numerical data and then performs order-preserving encryption on the data (see the relevant introduction of the aforementioned step A3), the fourth data and the fifth data are both numerical data, and the original type of the data can be one of the integer data, floating-point data, character data and numerical data introduced above. After decrypting the fifth data, the fifth data needs to be restored to its original data type. Restoring the data to its original data type is the inverse operation of the four cases of order-preserving encryption introduced in the aforementioned step A3.
例如,第五数据对应的原始数据类型为整数型,在解密得到第五数据后,需将第五数据与原始数据类型对应的预设负整数求和,将第五数据还原为原始的整数型数据。又如,第四数据对应的原始数据类型为变长字符型,则在得到第四数据后,需移除填充的字符。For example, if the original data type corresponding to the fifth data is an integer type, after decrypting and obtaining the fifth data, the fifth data needs to be summed with the preset negative integer corresponding to the original data type to restore the fifth data to the original integer type data. For another example, if the original data type corresponding to the fourth data is a variable-length character type, after obtaining the fourth data, the padding characters need to be removed.
在上述图3对应的技术方案中,在获取到作用于目标数据库的第一结构化查询语句后,对第一结构化查询语句进行重写,得到第二结构化查询语句,第二结构化查询语句中的数据为对第一结构查询语句中的数据进行保序加密得到,然后将第二结构化查询语句发送给目标数据库,以使目标数据库执行第二结构化查询语句对应的数据库操作;再接收目标数据库执行第二结构化语句对应的将数据库操作后返回的第一操作结果数据;最后对第一操作结果数据进行数据还原,得到第一结构化查询语句对应的第二操作结果数据。由于是对SQL语句进行改写后发送给数据库执行,加密和数据还原均在数据交互终端侧进行,数据库服务端只需进行常规的数据库操作,数据库服务端软件不需要修改;由于改写后的SQL语句中的数据是对改写前的SQL语句中的数据进行保序加密得到,加密后的数据之间的顺序关系与加密前的数据之间的顺序关系相同,因而能够进行排序和大小比较查询等数据库操作。In the technical solution corresponding to the above-mentioned Figure 3, after obtaining the first structured query statement acting on the target database, the first structured query statement is rewritten to obtain a second structured query statement, and the data in the second structured query statement is obtained by encrypting the data in the first structured query statement in order-preserving manner, and then the second structured query statement is sent to the target database so that the target database executes the database operation corresponding to the second structured query statement; then the target database receives the first operation result data returned after the database operation corresponding to the second structured query statement is executed; finally, the first operation result data is restored to obtain the second operation result data corresponding to the first structured query statement. Since the SQL statement is rewritten and then sent to the database for execution, encryption and data restoration are both performed on the data interaction terminal side, and the database server only needs to perform conventional database operations, and the database server software does not need to be modified; since the data in the rewritten SQL statement is obtained by encrypting the data in the SQL statement before rewriting in order-preserving manner, the order relationship between the encrypted data is the same as the order relationship between the data before encryption, so that database operations such as sorting and size comparison query can be performed.
二、过程(3)的详细实施方案,即表加密元数据的生成和存储过程。2. Detailed implementation plan of process (3), i.e., the process of generating and storing table encryption metadata.
参见图4,图4为本申请实施例提供的另一种数据库操作方法的流程示意图,该方法可以应用于密态数据库系统,如图4所示,该方法包括如下步骤:Referring to FIG. 4 , FIG. 4 is a flow chart of another database operation method provided in an embodiment of the present application. The method can be applied to a secret database system. As shown in FIG. 4 , the method includes the following steps:
S301,数据交互终端获取作用于目标数据库的第三结构化查询语句,第三结构化查询语句包括第三列名称。S301: The data interaction terminal obtains a third structured query statement acting on a target database, where the third structured query statement includes a third column name.
这里,第三结构化查询语句为增强数据定义语句,增强数据定义语句为支持定义加密的数据定义语句,第三结构化查询语句用于在目标数据库中创建第一数据表,第三结构化查询语句包括第三列名称,第三列名称对应的数据列为第一数据表中的加密数据列;第三结构查询语句还包括第二表名称和第三列名称对应的第二列密钥名称,第二表名称为第一数据表的名称,第三列名称对应的第二列密钥名称是指加密第三列名称对应的数据列所采用的列密钥的名称。增强数据定义语句是相对标准数据定义语句而言,标准数据定义语句为常规的数据定义语句,增强数据定义语句在标准数据定义语句的基础上定义了加密属性。Here, the third structured query statement is an enhanced data definition statement, which is a data definition statement that supports the definition of encryption. The third structured query statement is used to create a first data table in the target database. The third structured query statement includes a third column name, and the data column corresponding to the third column name is an encrypted data column in the first data table; the third structured query statement also includes a second table name and a second column key name corresponding to the third column name. The second table name is the name of the first data table, and the second column key name corresponding to the third column name refers to the name of the column key used to encrypt the data column corresponding to the third column name. The enhanced data definition statement is relative to the standard data definition statement. The standard data definition statement is a conventional data definition statement. The enhanced data definition statement defines encryption attributes based on the standard data definition statement.
本申请中,第三结构化查询语句为增强DDL,第三结构化查询语句可定义列的加密属性。通过增强DDL语句,在建表时指定对表中的一列或多列进行加密。命令参数包括在列定义时,指定对列进行加密,以及列加密密钥名称。In the present application, the third structured query statement is an enhanced DDL statement, and the third structured query statement can define the encryption attribute of the column. Through the enhanced DDL statement, one or more columns in the table are specified to be encrypted when the table is created. The command parameters include specifying the encryption of the column when defining the column, and the column encryption key name.
增强DDL的格式如下:The format of the enhanced DDL is as follows:
在CREATE TABLE的column_constraint中,增加语法:In the column_constraint of CREATE TABLE, add the following syntax:
COLUMN_ENCRYPTION_KEY:指定用于加密对应列的列密钥名称COLUMN_ENCRYPTION_KEY: Specifies the column key name used to encrypt the corresponding column
第三结构化查询语句的一个具体示例(示例1)如下:A specific example (Example 1) of the third structured query statement is as follows:
该示例表示的含义为:创建表名称为“creditcard_info”的数据表,数据表中的列名称为“name”的数据列为加密数据列,加密列名称为“name”的数据列所采用的列密钥的名称为“ImgCEK1”。This example means: a data table named "creditcard_info" is created, a data column named "name" in the data table is an encrypted data column, and the name of the column key used by the encrypted data column named "name" is "ImgCEK1".
在一些可能的情况中,一个数据列还可以对应有多个列密钥,即第三列名称对应的第二列密钥名称有多个,不同的列密钥名称可对应不同的加密算法。第三结构化查询语句的另一个具体示例(示例2)如下:In some possible cases, a data column may correspond to multiple column keys, that is, there are multiple second column key names corresponding to the third column name, and different column key names may correspond to different encryption algorithms. Another specific example (Example 2) of the third structured query statement is as follows:
该示例表示的含义为:创建表名称为“salary_info”的数据表,加密数据列所采用的列密钥的名称为“ImgCEK1”和“ImgCEK2”。This example means: a data table named "salary_info" is created, and the names of the column keys used to encrypt data columns are "ImgCEK1" and "ImgCEK2".
S302,数据交互终端对第三结构化查询语句进行重写,得到第四结构化查询语句,第四结构化查询语句中的第四列名称为对第三列名称进行变换得到。S302: The data interaction terminal rewrites the third structured query statement to obtain a fourth structured query statement, wherein the fourth column name in the fourth structured query statement is obtained by transforming the third column name.
这里,数据交互终端可以将第三结构化查询语句中的第三列名称,变更为替换列名称,得到第四名称;将第三结构化查询语句中的原始数据类型,变更为替换数据类型,得到第四结构化查询语句。第四结构化查询语句为标准数据定义语句。Here, the data interaction terminal can change the third column name in the third structured query statement to the replacement column name to obtain a fourth name; change the original data type in the third structured query statement to the replacement data type to obtain a fourth structured query statement. The fourth structured query statement is a standard data definition statement.
例如,对于上述步骤S301中的第三结构化查询语句的示例1,重写得到的第四结构化查询语句为:For example, for Example 1 of the third structured query statement in step S301 above, the fourth structured query statement obtained by rewriting is:
CREATE TABLE creditcard_infoCREATE TABLE creditcard_info
{id_number int,{id_number int,
name_cx3579 varchar(268)}name_cx3579 varchar(268)}
其中,第三结构化查询语句中可以包含多个第二列密钥名称,不同的第二列密钥名称对应不同的加密算法。如果第三结构化查询语句中包含多个第二列密钥名称,则在对第三结构化查询语句进行重写时,需对第三结构化查询语句中的第三列名称,根据第三结构化查询语句中的每个列密钥名称,采用其对应的加密算法,生成第三结构化查询语句中的每个列密钥名称对应的替换列名称,以此得到多个第四名称。The third structured query statement may include multiple second column key names, and different second column key names correspond to different encryption algorithms. If the third structured query statement includes multiple second column key names, when rewriting the third structured query statement, the third column name in the third structured query statement needs to be generated according to each column key name in the third structured query statement, using its corresponding encryption algorithm, and generating a replacement column name corresponding to each column key name in the third structured query statement, thereby obtaining multiple fourth names.
例如,对于上述步骤S301中的第三结构化查询语句的示例2,重写得到的第四结构化查询语句为:For example, for Example 2 of the third structured query statement in step S301 above, the fourth structured query statement obtained by rewriting is:
如果针对第一数据表的数据操作语句为插入类型的数据操作语句,将插入类型的数据操作语句中的列名称替换为多个第四列名称,并将插入类型的数据操作语句中的数据使用第一表加密元数据中的每个第二列密钥名称对应的加密算法进行分别加密,得到多个加密数据,将插入类型的数据操作语句中的数据替换为多个加密数据。即对于目标数据表(即原始数据列对应多个替换列的数据表),在向此类数据表插入数据时,数据交互终端需要把SQL语句中这一原始列,改写为多个替换列,对于这一原始列对应的值,按加密定义,使用多个密钥单独加密,得到多个加密的值。If the data operation statement for the first data table is an insert type data operation statement, the column name in the insert type data operation statement is replaced with multiple fourth column names, and the data in the insert type data operation statement is encrypted separately using the encryption algorithm corresponding to each second column key name in the first table encryption metadata to obtain multiple encrypted data, and the data in the insert type data operation statement is replaced with multiple encrypted data. That is, for the target data table (i.e., the data table where the original data column corresponds to multiple replacement columns), when inserting data into such a data table, the data interaction terminal needs to rewrite the original column in the SQL statement into multiple replacement columns, and for the value corresponding to the original column, according to the encryption definition, use multiple keys to encrypt separately to obtain multiple encrypted values.
例如,对于如下SQL语句:For example, for the following SQL statement:
insert into salary_info(id_number,salary)values(101,18010),insert into salary_info(id_number,salary)values(101,18010),
将其改写为:Rewrite it as:
insert into salary_info(id_number,salary_cx3579,salary_cx8351)values(101,’U++/7KfGO+==’,’0x1259e25a152b.....’);insert into salary_info(id_number,salary_cx3579,salary_cx8351)values(101,’U++/7KfGO+===’,’0x1259e25a152b....’);
如果针对所述第一数据表的数据操作语句为查询类型的数据操作语句,对于所述查询类型的数据操作语句中的第一表达式,所述第一表达式为where子句或having子句中的表达式,如果所述第一表达式中的运算符为保序算法支持的大小比较类运算符,将所述查询类型的数据操作语句中的所述第一表达式的列名称替换为采用保序算法加密的替换列名称,并对所述查询类型的数据操作语句中的所述第一表达式中的数据使用保序算法加密,如果所述第一表达式中的运算符为除保序算法以外的其他加密算法支持的运算符,将所述查询类型的数据操作语句中的所述第一表达式中的列名称替换为采用所述其他加密算法加密的替换列名称,并对所述查询类型的数据操作语句中的所述第一表达式中的数据使用所述其他加密算法加密;如果所述查询类型的数据操作语句中的表达式仅包含列名称,根据所述查询类型的数据操作语句中的所述表达式的位置,将所述查询类型的数据操作语句中的所述表达式中的列名称替换为采用所述第一表加密元数据中的最合适的第二列密钥名称对应的替换列名称;对于数据库操作后返回的第一操作结果数据,如果其对应结果表达式中的运算符为保序算法支持的大小比较类运算符,所述结果表达式为select语句中的select和from之间的表达式,所述目标数据库返回的操作结果数据为使用保序算法加密后的运算结果,所述使用保序算法加密后的运算结果无需进一步处理,如果其对应结果表达式中的运算符为所述其他加密算法支持的运算符,所述目标数据库返回的操作结果数据为使用所述其他加密算法加密后的运算结果,所述使用所述其他加密算法加密后的运算结果需要进行解密,如果其对应结果表达式仅包含列名称,所述目标数据库返回的操作结果数据为采用所述最合适的第二列密钥名称对应的列密钥加密后的结果,所述采用所述最合适的第二列密钥名称对应的列密钥加密后的结果需要进行解密;对于需要解密的运算结果,采用对应的加密算法和密钥进行解密。即对于包含由多个第二列密钥名称加密得到多个替换列名称的原始数据列的数据表,对于查询类SQL语句中的表达式(例如select语句中的where,having等子句中的表达式),根据其中的运算符,如果是保序支持的大小比较类运算,则列名替换为保序算法加密的列名,对应的值使用保序算法加密;如果是其它算法支持的运算(例如加法),则列名替换为对应算法(例如支持加法同态的加密算法)加密的列名,对应的值使用对应算法进行加密(例如支持加法同态的加密算法)。如果表达式仅含列名(这种情况通常出现在select语句中select和from之间的表达式),则根据表达式的位置,采用最合适的算法相关的列密钥元数据中的新列名进行替换。例如select salaryfrom salary_info,将salary使用保序算法相关的列密钥元数据中的新列名进行替换,即重写SQL为select salary_cx3579 from salary_info。对于目标数据表(即原始数据列对应多个替换列的数据表),对于SQL语句中的查询结果,按照上述的处理,根据SQL语句中的表达式及运算符,如果是保序支持的大小比较类运算,则服务端返回保序加密处理的值;否则返回其它算法加密处理的值。如果表达式仅含列名,则服务端返回最合适的算法相关的列密钥加密的列的值。在解密时,使用对应的算法进行解密。If the data operation statement for the first data table is a query-type data operation statement, for the first expression in the query-type data operation statement, the first expression is an expression in a where clause or a having clause, if the operator in the first expression is a size comparison operator supported by the order-preserving algorithm, the column name of the first expression in the query-type data operation statement is replaced with a replacement column name encrypted by the order-preserving algorithm, and the data in the first expression in the query-type data operation statement is encrypted using the order-preserving algorithm; if the operator in the first expression is an operator supported by other encryption algorithms other than the order-preserving algorithm, the column name in the first expression in the query-type data operation statement is replaced with a replacement column name encrypted by the other encryption algorithm, and the data in the first expression in the query-type data operation statement is encrypted using the other encryption algorithm; if the expression in the query-type data operation statement only contains column names, the column name in the expression in the query-type data operation statement is replaced according to the position of the expression in the query-type data operation statement. The replacement is referred to as the replacement column name corresponding to the most appropriate second column key name in the first table encryption metadata; for the first operation result data returned after the database operation, if the operator in the corresponding result expression is a size comparison operator supported by the order-preserving algorithm, and the result expression is an expression between select and from in the select statement, the operation result data returned by the target database is the operation result encrypted by the order-preserving algorithm, and the operation result encrypted by the order-preserving algorithm does not need to be further processed; if the operator in the corresponding result expression is an operator supported by the other encryption algorithm, the operation result data returned by the target database is the operation result encrypted by the other encryption algorithm, and the operation result encrypted by the other encryption algorithm needs to be decrypted; if the corresponding result expression only contains the column name, the operation result data returned by the target database is the result encrypted by the column key corresponding to the most appropriate second column key name, and the result encrypted by the column key corresponding to the most appropriate second column key name needs to be decrypted; for the operation result that needs to be decrypted, the corresponding encryption algorithm and key are used for decryption. That is, for a data table containing original data columns encrypted with multiple second column key names to obtain multiple replacement column names, for expressions in query SQL statements (such as expressions in where, having and other clauses in select statements), according to the operators therein, if it is a size comparison operation supported by order preservation, the column name is replaced with the column name encrypted by the order preservation algorithm, and the corresponding value is encrypted using the order preservation algorithm; if it is an operation supported by other algorithms (such as addition), the column name is replaced with the column name encrypted by the corresponding algorithm (such as an encryption algorithm that supports additive homomorphism), and the corresponding value is encrypted using the corresponding algorithm (such as an encryption algorithm that supports additive homomorphism). If the expression only contains column names (this situation usually occurs in the expression between select and from in a select statement), the new column name in the column key metadata related to the most appropriate algorithm is used for replacement according to the position of the expression. For example, select salary from salary_info, and replace salary with the new column name in the column key metadata related to the order preservation algorithm, that is, rewrite the SQL to select salary_cx3579 from salary_info. For the target data table (i.e., the data table where the original data column corresponds to multiple replacement columns), for the query results in the SQL statement, according to the above processing, based on the expression and operator in the SQL statement, if it is a size comparison operation supported by order preservation, the server returns the value processed by order preservation encryption; otherwise, it returns the value processed by other algorithms. If the expression only contains the column name, the server returns the value of the column encrypted with the column key related to the most appropriate algorithm. When decrypting, use the corresponding algorithm for decryption.
如果针对所述第一数据表的数据操作语句为更新类型的数据操作语句,对于所述更新类型的数据操作语句中的where子句部分,与所述查询类型的数据操作语句中的where子句的处理相同,对于所述更新类型的数据操作语句中的其他部分,与所述插入类型的数据操作语句的处理相同。If the data operation statement for the first data table is an update type data operation statement, the where clause part in the update type data operation statement is processed in the same way as the where clause in the query type data operation statement, and the other parts in the update type data operation statement are processed in the same way as the insert type data operation statement.
如果针对所述第一数据表的数据操作语句为删除类型的数据操作语句,对于所述删除类型中的数据操作语句中的where子句部分,与所述查询类型的数据操作语句中的where子句的处理相同。If the data operation statement for the first data table is a delete type data operation statement, the processing of the where clause in the delete type data operation statement is the same as that of the where clause in the query type data operation statement.
S303a,数据交互终端向目标数据库发送第四结构化查询语句,目标数据库接收第四结构化查询语句。S303a, the data interaction terminal sends a fourth structured query statement to the target database, and the target database receives the fourth structured query statement.
S303b,数据交互终端向目标数据库发送第一表加密元数据,目标数据库接收第一表加密元数据。S303b, the data interaction terminal sends the first table encrypted metadata to the target database, and the target database receives the first table encrypted metadata.
其中,第一表加密元数据包括第一数据表对应的列加密信息,第一数据表对应的列加密信息包括第三列名称、第四列名称以及第二列密钥名称;第一数据表对应的列加密信息还包括第一数据表的名称、第三列名称对应的数据列中的原始数据的类型和大小,以及第四列名称对应的加密数据列中的加密数据的类型和大小等。Among them, the first table encryption metadata includes column encryption information corresponding to the first data table, and the column encryption information corresponding to the first data table includes the third column name, the fourth column name and the second column key name; the column encryption information corresponding to the first data table also includes the name of the first data table, the type and size of the original data in the data column corresponding to the third column name, and the type and size of the encrypted data in the encrypted data column corresponding to the fourth column name, etc.
S304a,目标数据库执行第四结构化查询语句对应的建表操作。S304a, the target database executes a table creation operation corresponding to the fourth structured query statement.
S304b,目标数据库保存第一表加密元数据。S304b, the target database saves the encrypted metadata of the first table.
其中,数据交互终端通过标准结构化查询语句将第一表加密元数据发送给目标数据库进行保存。The data interaction terminal sends the encrypted metadata of the first table to the target database for storage through a standard structured query statement.
在上述图4对应的技术方案中,数据交互终端在获取到作用目标数据库的用于创建数据表的结构化查询语句后,对结构化查询语句进行重写,去除列的加密相关定义,并将重写后的结构化查询语句发送给目标数据库,使得目标数据库执行建表操作,目标数据库不需要感知加密特性,只需按照常规的方法进行建表,数据库服务端软件不需要修改。数据交互终端还将表加密元数据发送给目标数据库进行保存,能够方便后续对数据进行解密。In the technical solution corresponding to FIG. 4 above, after obtaining the structured query statement for creating a data table for the target database, the data interaction terminal rewrites the structured query statement, removes the encryption-related definition of the column, and sends the rewritten structured query statement to the target database, so that the target database performs the table creation operation. The target database does not need to perceive the encryption feature, and only needs to create the table according to the conventional method, and the database server software does not need to be modified. The data interaction terminal also sends the table encryption metadata to the target database for storage, which can facilitate the subsequent decryption of the data.
三、过程(2)的详细实施方案,即列密钥和列密钥元数据的生成和存储过程。3. Detailed implementation plan of process (2), i.e., the process of generating and storing column keys and column key metadata.
参见图5,图5为本申请实施例提供的又一种数据库操作方法的流程示意图,该方法可以应用于密态数据库系统,如图5所示,该方法包括如下步骤:Referring to FIG. 5 , FIG. 5 is a flow chart of another database operation method provided in an embodiment of the present application. The method can be applied to a secret database system. As shown in FIG. 5 , the method includes the following steps:
S401,数据交互终端获取第五结构化查询语句,第五结构化查询语句包括第二主密钥名称、第三列密钥名称以及第三列密钥名称对应的算法名称。S401: The data interaction terminal obtains a fifth structured query statement, where the fifth structured query statement includes a second master key name, a third column key name, and an algorithm name corresponding to the third column key name.
这里,第五结构化查询语句为增强数据定义语句,增强数据定义语句为支持定义加密的数据定义语句,第五结构化查询语句用于创建目标数据库对应的列密钥,第三列密钥名称为通过第五结构化查询语句需要创建的列密钥的名称,第二主密钥名称为对需要创建的列密钥进行加密的主密钥的名称。第五结构化查询语句还包括第三列密钥名称对应的算法名称,第三列密钥名称对应的算法名称为列密钥对应的加解密算法的名称。Here, the fifth structured query statement is an enhanced data definition statement, which is a data definition statement that supports definition of encryption. The fifth structured query statement is used to create a column key corresponding to the target database. The third column key name is the name of the column key to be created by the fifth structured query statement, and the second master key name is the name of the master key used to encrypt the column key to be created. The fifth structured query statement also includes an algorithm name corresponding to the third column key name, and the algorithm name corresponding to the third column key name is the name of the encryption and decryption algorithm corresponding to the column key.
第五结构化查询语句的语法示例如下:The syntax example of the fifth structured query statement is as follows:
CREATE COLUMN ENCRYPTION KEY key_nameCREATE COLUMN ENCRYPTION KEY key_name
WITH(WITH(
COLUMN_MASTER_KEY=column_master_key_name,COLUMN_MASTER_KEY=column_master_key_name,
ALGORITHM=algorithm_nameALGORITHM=algorithm_name
))
其中,key_name表示列密钥的名称,column_master_key_name表示用于加密列密钥的主密钥的名称,algorithm_name表示列密钥加密数据时使用的算法名称,可以为前述介绍的ope算法。Among them, key_name represents the name of the column key, column_master_key_name represents the name of the master key used to encrypt the column key, and algorithm_name represents the name of the algorithm used when the column key encrypts data, which can be the ope algorithm introduced above.
S402,数据交互终端根据第二主密钥名称和第三列密钥名称,确定第二加密列密钥。S402: The data interaction terminal determines a second encrypted column key according to the second master key name and the third column key name.
其中,第二加密列密钥为采用第二主密钥名称对应的第二主密钥对第三列密钥名称对应的第三列密钥加密得到。The second encrypted column key is obtained by encrypting the third column key corresponding to the third column key name using the second master key corresponding to the second master key name.
数据交互终端可以获取第二主密钥名称对应的主密钥元数据,第二主密钥名称对应的主密钥元数据包括第二主密钥名称、密钥路径、算法名称和密钥库提供者名称。The data interaction terminal can obtain the master key metadata corresponding to the second master key name, and the master key metadata corresponding to the second master key name includes the second master key name, key path, algorithm name and key library provider name.
如果第二主密钥名称对应的主密钥元数据中的密钥库提供者名称为本地密钥管理模块的名称,数据交互终端中的本地密钥管理模块可以根据第三列密钥名称,生成第三列密钥名称对应的第三列密钥,并根据第二主密钥名称对应的主密钥元数据中的密钥路径和第二主密钥名称,确定第二主密钥名称对应的主密钥;最后采用第二主密钥名称对应的主密钥元数据中的算法名称对应的加密算法和第二主密钥名称对应的主密钥,对第三列密钥名称对应的列密钥进行加密,得到第二加密列密钥。If the key library provider name in the master key metadata corresponding to the second master key name is the name of the local key management module, the local key management module in the data interaction terminal can generate a third column key corresponding to the third column key name based on the third column key name, and determine the master key corresponding to the second master key name based on the key path and the second master key name in the master key metadata corresponding to the second master key name; finally, the encryption algorithm corresponding to the algorithm name in the master key metadata corresponding to the second master key name and the master key corresponding to the second master key name are used to encrypt the column key corresponding to the third column key name to obtain the second encrypted column key.
如果第二主密钥名称对应的主密钥元数据中的密钥库提供者名称为第三方密钥管理模块的名称,数据交互终端可以将第三列密钥名称和第二主密钥名称对应的主密钥元数据发送给第三方管理模块,由第三方管理模块根据第三列密钥名称,生成第三列密钥名称对应的第三列密钥,并根据第二主密钥名称对应的主密钥元数据中的密钥路径和第二主密钥名称,确定第二主密钥名称对应的主密钥,并采用第二主密钥名称对应的主密钥元数据中的算法名称对应的加密算法和第二主密钥名称对应的主密钥,对第三列密钥名称对应的列密钥进行加密,得到第二加密列密钥,然后向数据交互终端返回第二加密列密钥。If the key library provider name in the master key metadata corresponding to the second master key name is the name of a third-party key management module, the data interaction terminal can send the third column key name and the master key metadata corresponding to the second master key name to the third-party management module, and the third-party management module generates a third column key corresponding to the third column key name based on the third column key name, and determines the master key corresponding to the second master key name based on the key path in the master key metadata corresponding to the second master key name and the second master key name, and uses the encryption algorithm corresponding to the algorithm name in the master key metadata corresponding to the second master key name and the master key corresponding to the second master key name to encrypt the column key corresponding to the third column key name to obtain a second encrypted column key, and then returns the second encrypted column key to the data interaction terminal.
S403,数据交互终端向目标数据库发送第二列密钥元数据和第二加密列密钥,第二列密钥元数据包括第二主密钥名称、第三列密钥名称以及第三列密钥名称对应的算法名称,目标数据库接收第二列密钥元数据和第二加密列密钥。S403, the data interaction terminal sends the second column key metadata and the second encrypted column key to the target database, the second column key metadata includes the second master key name, the third column key name and the algorithm name corresponding to the third column key name, and the target database receives the second column key metadata and the second encrypted column key.
S404,目标数据库保存第二列密钥元数据和第二加密列密钥。S404: The target database stores the second column key metadata and the second encrypted column key.
其中,数据交互终端通过标准结构化查询语句将第二列密钥元数据和第二加密列密钥发送给目标数据库进行保存。The data interaction terminal sends the second column key metadata and the second encrypted column key to the target database for storage through a standard structured query statement.
在上述图5对应的技术方案中,数据交互终端在获取到作用目标数据库的用于创建列密钥的结构化查询语句后,通过对列密钥进行加密,得到加密列密钥,然后将加密列密钥和指示列密钥的加密属性的列密钥元数据保存到目标数据库中,数据库中只需按照常规方法保存元数据,数据库服务端软件不需要修改。In the technical solution corresponding to FIG. 5 above, after obtaining the structured query statement for creating a column key of the target database, the data interaction terminal encrypts the column key to obtain an encrypted column key, and then saves the encrypted column key and the column key metadata indicating the encryption attribute of the column key into the target database. The database only needs to save the metadata according to the conventional method, and the database server software does not need to be modified.
四、过程(1)的详细实施方案,即主密钥和主密钥元数据的生成和保存过程。4. Detailed implementation plan of process (1), i.e., the process of generating and storing the master key and master key metadata.
参见图6,图6为本申请实施例提供的又一种数据库操作方法的流程示意图,该方法可以应用于密态数据库系统,如图6所示,该方法包括如下步骤:Referring to FIG. 6 , FIG. 6 is a flow chart of another database operation method provided in an embodiment of the present application. The method can be applied to a secret database system. As shown in FIG. 6 , the method includes the following steps:
S501,数据交互终端获取第六结构化查询语句,第六结构化查询语句包括第二主密钥元数据。S501: The data interaction terminal obtains a sixth structured query statement, where the sixth structured query statement includes second master key metadata.
这里,第六结构化查询语句为增强数据定义语句,增强数据定义语句为支持定义加密的数据定义语句,第六结构化查询语句用于创建目标数据库对应的主密钥,第六结构化查询语句包括第二主密钥元数据,第二主密钥元数据包括第三主密钥名称、第二算法名称和第二密钥路径,第二算法名称为主密钥对应的加解密算法的名称,第二密钥路径为主密钥对应的存储路径;第二主密钥元数据还包括密钥库提供者名称。Here, the sixth structured query statement is an enhanced data definition statement, which is a data definition statement that supports encryption definition. The sixth structured query statement is used to create a master key corresponding to the target database. The sixth structured query statement includes second master key metadata. The second master key metadata includes the third master key name, the second algorithm name, and the second key path. The second algorithm name is the name of the encryption and decryption algorithm corresponding to the master key, and the second key path is the storage path corresponding to the master key. The second master key metadata also includes the key library provider name.
第六结构化查询语句的示例如下:An example of the sixth structured query statement is as follows:
其中,key_name表示数据库中主密钥的名称,key_store_provider_name表示密钥库提供者名称,key_path用于表示主密钥的路径,algorithm表示算法名称。Among them, key_name indicates the name of the master key in the database, key_store_provider_name indicates the name of the key store provider, key_path is used to indicate the path of the master key, and algorithm indicates the algorithm name.
S502,生成第三主密钥名称对应的主密钥。S502: Generate a master key corresponding to the third master key name.
其中,如果第二主密钥元数据中的密钥库提供者名称为数据交互终端中的本地密钥管理模块的名称,则数据交互终端的本地密钥管理模块可以根据第二主密钥元数据生成第三主密钥名称对应的主密钥,本地密钥管理模块可以按第二密钥路径保存第三主密钥名称对应的主密钥;如果第二主密钥元数据中的密钥库提供者名称为第三方密钥管理模块的名称,则数据交互终端可以将第二主密钥元数据发送给第三方密钥管理模块,由第三方密钥管理模块根据第二主密钥元数据生成第三主密钥名称对应的主密钥并进行保存,第三方密钥管理模块可以按第二密钥路径保存第三主密钥名称对应的主密钥。Among them, if the key library provider name in the second master key metadata is the name of the local key management module in the data interaction terminal, the local key management module of the data interaction terminal can generate a master key corresponding to the third master key name based on the second master key metadata, and the local key management module can save the master key corresponding to the third master key name according to the second master key metadata; if the key library provider name in the second master key metadata is the name of a third-party key management module, the data interaction terminal can send the second master key metadata to the third-party key management module, and the third-party key management module will generate and save the master key corresponding to the third master key name based on the second master key metadata, and the third-party key management module can save the master key corresponding to the third master key name according to the second key path.
S503,数据交互终端向目标数据库发送第二主密钥元数据,目标数据库接收第二主密钥元数据。S503: The data interaction terminal sends the second master key metadata to the target database, and the target database receives the second master key metadata.
S504,目标数据库保存第二主密钥元数据。S504: The target database stores the second master key metadata.
其中,数据交互终端可以通过标准结构化查询语句,将第二主密钥元数据发送给目标数据库进行保存。The data interaction terminal may send the second master key metadata to the target database for storage through a standard structured query statement.
在上述图6对应的技术方案中,数据交互终端在获取到作用目标数据库的用于创建主密钥的结构化查询语句后,将主密钥元数据保存到目标数据库中,数据库中只需按照常规方法保存主密钥元数据,数据库服务端软件不需要修改。In the technical solution corresponding to Figure 6 above, after the data interaction terminal obtains the structured query statement for creating the master key of the target database, it saves the master key metadata to the target database. The database only needs to save the master key metadata according to the conventional method, and the database server software does not need to be modified.
上述介绍了本申请的方法,下面介绍本申请的装置。The method of the present application is introduced above, and the device of the present application is introduced below.
参见图7,图7为本申请实施例提供的一种密态数据库的加密和解密装置的结构示意图,应用于数据交互终端,如图7所示,该密态数据库的加密和解密装置60包括:Referring to FIG. 7 , FIG. 7 is a schematic diagram of the structure of an encryption and decryption device for a secret database provided in an embodiment of the present application, which is applied to a data interaction terminal. As shown in FIG. 7 , the encryption and decryption device 60 for a secret database includes:
获取模块601,用于获取作用于目标数据库的第一结构化查询语句,所述第一结构化查询语句为数据操作语句;The acquisition module 601 is used to acquire a first structured query statement acting on a target database, wherein the first structured query statement is a data operation statement;
重写模块602,用于对所述第一结构化查询语句进行重写,得到第二结构化查询语句,所述第二结构化查询语句中的数据为对所述第一结构化查询语句中的数据进行保序加密得到;A rewriting module 602 is used to rewrite the first structured query statement to obtain a second structured query statement, wherein the data in the second structured query statement is obtained by performing order-preserving encryption on the data in the first structured query statement;
发送模块603,用于向所述目标数据库发送所述第二结构化查询语句,以使所述目标数据库执行所述第二结构化查询语句对应的数据库操作;A sending module 603 is used to send the second structured query statement to the target database, so that the target database executes the database operation corresponding to the second structured query statement;
接收模块604,用于接收所述目标数据库执行所述数据库操作后返回的第一操作结果数据;A receiving module 604 is used to receive first operation result data returned by the target database after executing the database operation;
还原模块605,用于对所述第一操作结果数据进行数据还原,得到所述第一结构化查询语句对应的第二操作结果数据。The restoration module 605 is used to restore the first operation result data to obtain the second operation result data corresponding to the first structured query statement.
在一种可能的设计中,所述第一结构化查询语句包括第一列名称;上述重写模块602,具体用于:根据表加密元数据,确定所述第一列名称对应的第一列密钥名称和第二列名称,所述表加密元数据包括所述目标数据库中的数据表对应的列加密信息,所述列加密信息包括所述目标数据库中的数据表中的加密数据列加密前后的列名称以及所述加密数据列对应的列密钥名称;获取所述第一列密钥名称对应的第一列密钥元数据和第一加密列密钥,所述第一列密钥元数据包括第一主密钥名称和所述第一列密钥名称,所述第一加密列密钥为采用所述第一主密钥名称对应的主密钥对所述第一列名称对应的第一列密钥进行加密得到;获取所述第一主密钥名称对应的第一主密钥元数据,所述第一主密钥元数据包括第一算法名称和第一密钥路径,所述第一算法名称为主密钥对应的加解密算法的名称,所述第一密钥路径为主密钥对应的存储路径;根据所述第一密钥路径,确定所述第一主密钥名称对应的第一主密钥;根据所述第一主密钥和所述第一算法名称对应的加解密算法,对所述第一加密列密钥进行解密,得到所述第一列密钥;根据所述第一列密钥对所述第一数据进行保序加密,得到第二数据,所述保序加密为:将明文空间的值按照一定的顺序映射到密文空间,使得在加密后的密文中,明文之间的相对顺序仍然能够被保留,在进行映射时,明文的统计特征被隐藏,以保证算法的安全性;将所述第一结构化查询语句中的第一列名称重写为所述第二列名称,并将所述第一结构化查询语句中的所述第一数据重写为所述第二数据,得到所述第二结构化查询语句。In a possible design, the first structured query statement includes a first column name; the rewriting module 602 is specifically used to: determine a first column key name and a second column name corresponding to the first column name according to table encryption metadata, the table encryption metadata including column encryption information corresponding to the data table in the target database, the column encryption information including the column name of the encrypted data column in the data table in the target database before and after encryption and the column key name corresponding to the encrypted data column; obtain a first column key metadata and a first encrypted column key corresponding to the first column key name, the first column key metadata including a first master key name and the first column key name, the first encrypted column key being obtained by encrypting the first column key corresponding to the first column name using the master key corresponding to the first master key name; obtain a first master key metadata corresponding to the first master key name, the first master key metadata including a first algorithm name and a first key path, the first algorithm name is the name of the encryption and decryption algorithm corresponding to the master key, and the first key path is the storage path corresponding to the master key; according to the first key path, the first master key corresponding to the first master key name is determined; according to the first master key and the encryption and decryption algorithm corresponding to the first algorithm name, the first encrypted column key is decrypted to obtain the first column key; according to the first column key, the first data is encrypted in an order-preserving manner to obtain the second data, and the order-preserving encryption is: mapping the values of the plaintext space to the ciphertext space in a certain order, so that in the encrypted ciphertext, the relative order between the plaintexts can still be retained, and when mapping, the statistical characteristics of the plaintext are hidden to ensure the security of the algorithm; rewriting the first column name in the first structured query statement into the second column name, and rewriting the first data in the first structured query statement into the second data to obtain the second structured query statement.
在一种可能的设计中,上述重写模块602,具体用于:如果所述第一数据为负浮点型数据,计算所述第一数据对应的第一整数的二进制补码,得到第一补码,所述第一整数为将存储所述第一数据的字节作为整数处理所得到的整数;计算所述第一补码与最小编码的差值,得到待加密编码,所述最小编码为所述第一数据所占字节数对应的最小负整数的二进制编码;根据所述第一列密钥,将所述待加密编码作为无符号整数进行处理,对所述待加密编码进行保序加密,得到第二数据;如果所述第一数据为字符型数据,在第一数据的右侧填充预设字符,得到所述第一数据对应的标准字符,所述标准字符的字符长度为预设字符长度,其中,所述预设字符长度为所述第一列名称对应的数据列所定义的最大字符长度,如果所述第一数据为定长字符型数据,所述预设字符为空格的ASCII字符,如果所述第一数据为变长字符型数据,所述预设字符为任一小于空格的ASCII字符;根据所述第一列密钥,将所述标准字符的ACII编码作为无符号整数进行处理,对所述标准字符的ACII编码进行保序加密,得到所述第二数据;如果所述第一数据为数值型数据,将所述第一数据减去第一预设负数,得到所述第一数据对应的第一正数,所述第一预设负数为任一小于或等于第一负数的负数,所述第一负数为第一列名称对应的数据列所定义的最小负数;对所述第一正数进行小数补零处理,得到第二正数,所述第二正数的小数位数为预设位数,所述预设位数为所述第一列名称对应的数据列所定义的小数位数;从第一正整数的最低位开始,将相邻两个字节中的高位字节的低4位作为合并字节的高4位,并将低位字节的低4位作为合并字节的低4位,对所述第一正整数进行合并,得到第二正整数,所述第一正整数为忽略所述第二正数中的小数点得到的整数;根据所述第一列密钥,对所述第二正整数进行加密,得到第二数据。In a possible design, the rewrite module 602 is specifically used to: if the first data is negative floating-point data, calculate the binary complement of the first integer corresponding to the first data to obtain the first complement, where the first integer is an integer obtained by treating the bytes storing the first data as integers; calculate the difference between the first complement and the minimum code to obtain the code to be encrypted, where the minimum code is the binary code of the minimum negative integer corresponding to the number of bytes occupied by the first data; according to the first column key, treat the code to be encrypted as an unsigned integer, encrypt the code to be encrypted in an order-preserving manner, and obtain the second data; if the first data is character data, fill the right side of the first data with preset characters to obtain the standard character corresponding to the first data, where the character length of the standard character is the preset character length, wherein the preset character length is the maximum character length defined by the data column corresponding to the first column name; if the first data is fixed-length character data, the preset character is an ASCII character of a space; if the first data is variable-length character data, the preset character is any ASCII character that is less than a space. SCII character; according to the first column key, the ACII code of the standard character is processed as an unsigned integer, and the ACII code of the standard character is encrypted in order to obtain the second data; if the first data is numerical data, the first data is subtracted from a first preset negative number to obtain a first positive number corresponding to the first data, the first preset negative number is any negative number less than or equal to the first negative number, and the first negative number is the minimum negative number defined by the data column corresponding to the first column name; the first positive number is padded with zeros to obtain a second positive number, the number of decimal places of the second positive number is a preset number of places, and the preset number of places is the number of decimal places defined by the data column corresponding to the first column name; starting from the lowest bit of the first positive integer, the lower 4 bits of the high-order byte in the two adjacent bytes are used as the high 4 bits of the merged byte, and the lower 4 bits of the low-order byte are used as the lower 4 bits of the merged byte, and the first positive integer is merged to obtain a second positive integer, the first positive integer is an integer obtained by ignoring the decimal point in the second positive number; according to the first column key, the second positive integer is encrypted to obtain the second data.
在一种可能的设计中,上述重写模块602,具体用于:对所述第二数据进行基于扩展编码方式进行编码,得到第三数据,所述扩展编码方式为基于标准Base64编码的扩展编码方式;将所述第一结构化查询语句中的所述第一数据重写为所述第三数据。In a possible design, the above-mentioned rewriting module 602 is specifically used to: encode the second data based on an extended encoding method to obtain third data, and the extended encoding method is an extended encoding method based on standard Base64 encoding; rewrite the first data in the first structured query statement into the third data.
在一种可能的设计中,上述重写模块602,具体用于:按基于标准Base64编码的扩展编码表,对所述第二数据进行编码,得到所述第二数据对应的Base64扩展码,所述基于标准Base64编码的扩展编码表为将ASCII标准中的可见字符任意取出64个,并按值大小顺序排列得到;将所述Base64扩展码对应的ASCII编码,作为所述第三数据。In one possible design, the above-mentioned rewrite module 602 is specifically used to: encode the second data according to an extended coding table based on standard Base64 encoding to obtain a Base64 extended code corresponding to the second data, wherein the extended coding table based on standard Base64 encoding is obtained by randomly taking out 64 visible characters in the ASCII standard and arranging them in order of value; and use the ASCII code corresponding to the Base64 extended code as the third data.
在一种可能的设计中,上述获取模块601还用于,获取作用于目标数据库的第三结构化查询语句,所述第三结构化查询语句为增强数据定义语句,所述增强数据定义语句为支持定义加密的数据定义语句,所述第三结构化查询语句用于在所述目标数据库中创建第一数据表,所述第三结构化查询语句包括所述第一数据表的名称、第三列名称、所述第三列名称对应的第二列密钥名称和所述第三列名称对应的数据列中的原始数据的类型和大小,所述第三列名称对应的数据列为所述第一数据表中的加密数据列,所述第二列密钥名称为加密所述第三列名称对应的数据列的第二列密钥的名称;上述重写模块602还用于,对所述第三结构化查询语句进行重写,得到第四结构化查询语句,所述第四结构化查询语句中的第四列名称为对所述第三列名称进行变换得到,所述第四结构化查询语句中的第四列名称对应的加密数据列中的加密数据的类型由所述第三列名称对应的数据列中的原始数据的类型变更得到,所述第四结构化查询语句为标准数据定义语句;上述发送模块603还用于,向所述目标数据库发送所述第四结构化查询语句,以使所述目标数据库执行所述第四结构化查询语句对应的建表操作;通过标准结构化查询语句向所述目标数据库发送第一表加密元数据,以使所述目标数据库保存所述第一表加密元数据,所述第一表加密元数据包括所述第一数据表对应的列加密信息,所述第一数据表的列加密信息包括所述第一数据表的名称、所述第三列名称、所述第四列名称、所述第二列密钥名称以及所述第三列名称对应的数据列中的原始数据的类型和大小以及第四列名称对应的加密数据列中的加密数据的类型。In a possible design, the acquisition module 601 is further used to acquire a third structured query statement acting on the target database, wherein the third structured query statement is an enhanced data definition statement, wherein the enhanced data definition statement is a data definition statement that supports definition of encryption, and the third structured query statement is used to create a first data table in the target database, wherein the third structured query statement includes the name of the first data table, the name of a third column, the name of a second column key corresponding to the third column name, and the type and size of the original data in the data column corresponding to the third column name, wherein the data column corresponding to the third column name is the encrypted data column in the first data table, and the name of the second column key is the name of the second column key for encrypting the data column corresponding to the third column name; the rewriting module 602 is further used to rewrite the third structured query statement to obtain a fourth structured query statement, wherein the fourth column name in the fourth structured query statement is obtained by transforming the third column name. , the type of encrypted data in the encrypted data column corresponding to the fourth column name in the fourth structured query statement is obtained by changing the type of original data in the data column corresponding to the third column name, and the fourth structured query statement is a standard data definition statement; the sending module 603 is also used to send the fourth structured query statement to the target database, so that the target database executes the table creation operation corresponding to the fourth structured query statement; send the first table encryption metadata to the target database through the standard structured query statement, so that the target database saves the first table encryption metadata, the first table encryption metadata includes the column encryption information corresponding to the first data table, and the column encryption information of the first data table includes the name of the first data table, the third column name, the fourth column name, the second column key name, and the type and size of the original data in the data column corresponding to the third column name and the type of encrypted data in the encrypted data column corresponding to the fourth column name.
在一种可能的设计中,所述第三列名称对应的第二列密钥名称有多个,不同的第二列密钥名称对应不同的加密算法;上述重写模块602具体用于:如果针对所述第一数据表的数据操作语句为插入类型的数据操作语句,将所述插入类型的数据操作语句中的列名称替换为所述多个第四列名称,并将所述插入类型的数据操作语句中的数据使用所述第一表加密元数据中的每个第二列密钥名称对应的加密算法进行分别加密,得到多个加密数据,将所述插入类型的数据操作语句中的数据替换为所述多个加密数据;如果针对所述第一数据表的数据操作语句为查询类型的数据操作语句,对于所述查询类型的数据操作语句中的第一表达式,所述第一表达式为where子句或having子句中的表达式,如果所述第一表达式中的运算符为保序算法支持的大小比较类运算符,将所述查询类型的数据操作语句中的所述第一表达式的列名称替换为采用保序算法加密的替换列名称,并对所述查询类型的数据操作语句中的所述第一表达式中的数据使用保序算法加密,如果所述第一表达式中的运算符为除保序算法以外的其他加密算法支持的运算符,将所述查询类型的数据操作语句中的所述第一表达式中的列名称替换为采用所述其他加密算法加密的替换列名称,并对所述查询类型的数据操作语句中的所述第一表达式中的数据使用所述其他加密算法加密;如果所述查询类型的数据操作语句中的表达式仅包含列名称,根据所述查询类型的数据操作语句中的所述表达式的位置,将所述查询类型的数据操作语句中的所述表达式中的列名称替换为采用所述第一表加密元数据中的最合适的第二列密钥名称对应的替换列名称;对于数据库操作后返回的第一操作结果数据,如果其对应结果表达式中的运算符为保序算法支持的大小比较类运算符,所述结果表达式为select语句中的select和from之间的表达式,所述目标数据库返回的操作结果数据为使用保序算法加密后的运算结果,所述使用保序算法加密后的运算结果无需进一步处理,如果其对应结果表达式中的运算符为所述其他加密算法支持的运算符,所述目标数据库返回的操作结果数据为使用所述其他加密算法加密后的运算结果,所述使用所述其他加密算法加密后的运算结果需要进行解密,如果其对应结果表达式仅包含列名称,所述目标数据库返回的操作结果数据为采用所述最合适的第二列密钥名称对应的列密钥加密后的结果,所述采用所述最合适的第二列密钥名称对应的列密钥加密后的结果需要进行解密;对于需要解密的运算结果,采用对应的加密算法和密钥进行解密;如果针对所述第一数据表的数据操作语句为更新类型的数据操作语句,对于所述更新类型的数据操作语句中的where子句部分,与所述查询类型的数据操作语句中的where子句的处理相同,对于所述更新类型的数据操作语句中的其他部分,与所述插入类型的数据操作语句的处理相同;如果针对所述第一数据表的数据操作语句为删除类型的数据操作语句,对于所述删除类型中的数据操作语句中的where子句部分,与所述查询类型的数据操作语句中的where子句的处理相同。In one possible design, there are multiple second column key names corresponding to the third column name, and different second column key names correspond to different encryption algorithms; the above-mentioned rewrite module 602 is specifically used for: if the data operation statement for the first data table is an insert-type data operation statement, the column name in the insert-type data operation statement is replaced with the multiple fourth column names, and the data in the insert-type data operation statement is encrypted separately using the encryption algorithm corresponding to each second column key name in the first table encryption metadata to obtain multiple encrypted data, and the data in the insert-type data operation statement is replaced with the multiple encrypted data; if the data operation statement for the first data table is a query-type data operation statement, for the first expression in the query-type data operation statement, the first expression is an expression in a where clause or a having clause, if the The operator in the first expression is a size comparison operator supported by the order-preserving algorithm, and the column name of the first expression in the data operation statement of the query type is replaced with a replacement column name encrypted by the order-preserving algorithm, and the data in the first expression in the data operation statement of the query type is encrypted using the order-preserving algorithm. If the operator in the first expression is an operator supported by other encryption algorithms except the order-preserving algorithm, the column name in the first expression in the data operation statement of the query type is replaced with a replacement column name encrypted by the other encryption algorithm, and the data in the first expression in the data operation statement of the query type is encrypted using the other encryption algorithm; if the expression in the data operation statement of the query type only contains the column name, according to the position of the expression in the data operation statement of the query type, the column name in the expression in the data operation statement of the query type is replaced with a replacement column name encrypted by the other encryption algorithm, and the data in the first expression in the data operation statement of the query type is encrypted using the other encryption algorithm. The column name is replaced with the replacement column name corresponding to the most appropriate second column key name in the first table encryption metadata; for the first operation result data returned after the database operation, if the operator in the corresponding result expression is a size comparison operator supported by the order-preserving algorithm, the result expression is the expression between select and from in the select statement, the operation result data returned by the target database is the operation result encrypted by the order-preserving algorithm, and the operation result encrypted by the order-preserving algorithm does not need to be further processed; if the operator in the corresponding result expression is an operator supported by the other encryption algorithm, the operation result data returned by the target database is the operation result encrypted by the other encryption algorithm, and the operation result encrypted by the other encryption algorithm needs to be decrypted; if the corresponding result expression only contains the column name, the operation result data returned by the target database The data is a result of encryption using the column key corresponding to the most appropriate second column key name, and the result of encryption using the column key corresponding to the most appropriate second column key name needs to be decrypted; for the calculation result that needs to be decrypted, the corresponding encryption algorithm and key are used for decryption; if the data operation statement for the first data table is an update type data operation statement, the where clause part in the update type data operation statement is processed the same as the where clause in the query type data operation statement, and the other parts in the update type data operation statement are processed the same as the insert type data operation statement; if the data operation statement for the first data table is a delete type data operation statement, the where clause part in the delete type data operation statement is processed the same as the where clause in the query type data operation statement.
在一种可能的设计中,上述获取模块601还用于,获取第五结构化查询语句,所述第五结构化查询语句为增强数据定义语句,所述增强数据定义语句为支持定义加密的数据定义语句,所述第五结构化查询语句用于创建所述目标数据库对应的列密钥,所述第五结构化查询语句包括第二主密钥名称和第三列密钥名称以及所述第三列密钥名称对应的算法名称,所述第三列密钥名称对应的算法名称为列密钥对应的加解密算法的名称;根据所述第三列密钥名称,生成所述第三列密钥名称对应的第三列密钥;根据所述第二主密钥名称,获取所述第二主密钥名称对应的第二主密钥;采用所述第二主密钥名称对应的第二主密钥,对所述第三列密钥名称对应的第三列密钥进行加密,得到所述第二加密列密钥;上述发送模块603还用于,通过标准结构化查询语句向所述目标数据库发送第二列密钥元数据和所述第二加密列密钥,以使所述目标数据库保存所述第二列密钥元数据和所述第二加密列密钥,所述第二列密钥元数据包括所述第二主密钥名称、所述第三列密钥名称以及所述第三列密钥名称对应的算法名称。In a possible design, the acquisition module 601 is further used to acquire a fifth structured query statement, the fifth structured query statement is an enhanced data definition statement, the enhanced data definition statement is a data definition statement that supports definition of encryption, the fifth structured query statement is used to create a column key corresponding to the target database, the fifth structured query statement includes a second master key name, a third column key name, and an algorithm name corresponding to the third column key name, the algorithm name corresponding to the third column key name is the name of the encryption and decryption algorithm corresponding to the column key; according to the third column key name, a third column key corresponding to the third column key name is generated; according to the second master key name, a second master key corresponding to the second master key name is acquired; the third column key corresponding to the third column key name is encrypted using the second master key corresponding to the second master key name to obtain the second encrypted column key; the sending module 603 is further used to send the second column key metadata and the second encrypted column key to the target database through a standard structured query statement, so that the target database saves the second column key metadata and the second encrypted column key, the second column key metadata includes the second master key name, the third column key name, and the algorithm name corresponding to the third column key name.
在一种可能的设计中,上述获取模块601还用于,所述第六结构化查询语句为增强数据定义语句,所述增强数据定义语句为支持定义加密的数据定义语句,所述第六结构化查询语句用于创建所述目标数据库对应的主密钥,所述第六结构化查询语句包括第二主密钥元数据,所述第二主密钥元数据包括第三主密钥名称、第二算法名称、第二密钥路径和密钥库提供者名称,所述第二算法名称为主密钥对应的加解密算法的名称,所述第二密钥路径为主密钥对应的存储路径;生成所述第三主密钥名称对应的主密钥,按所述第二密钥路径保存所述第三主密钥名称对应的主密钥;上述发送模块603还用于,通过标准结构化查询语句向所述目标数据库发送所述第二主密钥元数据,以使所述目标数据库保存所述第二主密钥元数据。In a possible design, the acquisition module 601 is also used to: the sixth structured query statement is an enhanced data definition statement, the enhanced data definition statement is a data definition statement that supports encryption definition, the sixth structured query statement is used to create a master key corresponding to the target database, the sixth structured query statement includes a second master key metadata, the second master key metadata includes a third master key name, a second algorithm name, a second key path and a key library provider name, the second algorithm name is the name of the encryption and decryption algorithm corresponding to the master key, and the second key path is the storage path corresponding to the master key; generate a master key corresponding to the third master key name, and save the master key corresponding to the third master key name according to the second key path; the sending module 603 is also used to send the second master key metadata to the target database through a standard structured query statement, so that the target database saves the second master key metadata.
需要说明的是,图7对应的实施例中未提及的内容可参见前述方法实施例的描述,这里不再赘述。It should be noted that for the contents not mentioned in the embodiment corresponding to FIG. 7 , reference can be made to the description of the aforementioned method embodiment, which will not be repeated here.
上述装置,在获取到作用于目标数据库的第一结构化查询语句后,对第一结构化查询语句进行重写,得到第二结构化查询语句,第二结构化查询语句中的数据为对第一结构查询语句中的数据进行保序加密得到,然后将第二结构化查询语句发送给目标数据库,以使目标数据库执行第二结构化查询语句对应的数据库操作;再接收目标数据库执行第二结构化语句对应的将数据库操作后返回的第一操作结果数据;最后对第一操作结果数据进行数据还原,得到第一结构化查询语句对应的第二操作结果数据。由于是对SQL语句进行改写后发送给数据库执行,加密和数据还原均在数据交互终端侧进行,数据库服务端只需进行常规的数据库操作,无需对数据库服务端进行修改;由于改写后的SQL语句中的数据是对改写前的SQL语句中的数据进行保序加密得到,加密后的数据之间的顺序关系与加密前的数据之间的顺序关系相同,因而能够进行排序和大小比较查询等数据库操作。After obtaining the first structured query statement acting on the target database, the above-mentioned device rewrites the first structured query statement to obtain a second structured query statement, the data in the second structured query statement is obtained by encrypting the data in the first structured query statement in order-preserving manner, and then sends the second structured query statement to the target database so that the target database executes the database operation corresponding to the second structured query statement; then receives the first operation result data returned after the target database executes the database operation corresponding to the second structured query statement; finally, restores the first operation result data to obtain the second operation result data corresponding to the first structured query statement. Since the SQL statement is rewritten and then sent to the database for execution, encryption and data restoration are both performed on the data interaction terminal side, and the database server only needs to perform conventional database operations without modifying the database server; since the data in the rewritten SQL statement is obtained by encrypting the data in the SQL statement before rewriting in order-preserving manner, the order relationship between the encrypted data is the same as the order relationship between the data before encryption, so that database operations such as sorting and size comparison query can be performed.
参见图8,图8是本申请实施例提供的一种计算机设备的结构示意图,该计算机设备70包括处理器701、存储器702。存储器702连接至处理器701,例如通过总线连接至处理器701。Referring to Fig. 8, Fig. 8 is a schematic diagram of the structure of a computer device provided in an embodiment of the present application, wherein the computer device 70 includes a processor 701 and a memory 702. The memory 702 is connected to the processor 701, for example, via a bus.
处理器701被配置为支持该计算机设备70执行上述方法实施例中的方法中相应的功能。该处理器701可以是中央处理器(central processing unit,CPU),网络处理器(network processor,NP),硬件芯片或者其任意组合。上述硬件芯片可以是专用集成电路(application specific integrated circuit,ASIC),可编程逻辑器件(programmablelogic device,PLD)或其组合。上述PLD可以是复杂可编程逻辑器件(complexprogrammable logic device,CPLD),现场可编程逻辑门阵列(field-programmable gatearray,FPGA),通用阵列逻辑(generic array logic,GAL)或其任意组合。The processor 701 is configured to support the computer device 70 to perform the corresponding functions in the method in the above method embodiment. The processor 701 can be a central processing unit (CPU), a network processor (NP), a hardware chip or any combination thereof. The above hardware chip can be an application specific integrated circuit (ASIC), a programmable logic device (PLD) or a combination thereof. The above PLD can be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL) or any combination thereof.
存储器702用于存储程序代码等。存储器702可以包括易失性存储器(volatilememory,VM),例如随机存取存储器(random access memory,RAM);存储器702也可以包括非易失性存储器(non-volatile memory,NVM),例如只读存储器(read-only memory,ROM),快闪存储器(flash memory),硬盘(hard disk drive,HDD)或固态硬盘(solid-state drive,SSD);存储器702还可以包括上述种类的存储器的组合。The memory 702 is used to store program codes, etc. The memory 702 may include a volatile memory (VM), such as a random access memory (RAM); the memory 702 may also include a non-volatile memory (NVM), such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD); the memory 702 may also include a combination of the above-mentioned types of memories.
计算机设备70为授权获取终端时,处理器701可以调用所述程序代码以执行以下操作:When the computer device 70 is an authorization acquisition terminal, the processor 701 may call the program code to perform the following operations:
获取作用于目标数据库的第一结构化查询语句,所述第一结构化查询语句为数据操作语句;Acquire a first structured query statement acting on a target database, wherein the first structured query statement is a data operation statement;
对所述第一结构化查询语句进行重写,得到第二结构化查询语句,所述第二结构化查询语句中的数据为对所述第一结构化查询语句中的数据进行保序加密得到;Rewriting the first structured query statement to obtain a second structured query statement, wherein data in the second structured query statement is obtained by performing order-preserving encryption on the data in the first structured query statement;
向所述目标数据库发送所述第二结构化查询语句,以使所述目标数据库执行所述第二结构化查询语句对应的数据库操作;Sending the second structured query statement to the target database, so that the target database executes the database operation corresponding to the second structured query statement;
接收所述目标数据库执行所述数据库操作后返回的第一操作结果数据;Receiving first operation result data returned by the target database after executing the database operation;
对所述第一操作结果数据进行数据还原,得到所述第一结构化查询语句对应的第二操作结果数据。The first operation result data is restored to obtain second operation result data corresponding to the first structured query statement.
本申请实施例还提供一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序包括程序指令,所述程序指令当被计算机执行时使所述计算机执行如前述实施例所述的方法。An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a computer, the computer executes the method described in the above embodiment.
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,所述的程序可存储于计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中,所述的存储介质可为磁碟、光盘、只读存储记忆体(Read-Only memory,ROM)或随机存储记忆体(Random Accessmemory,RAM)等。A person skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
以上所揭露的仅为本申请较佳实施例而已,当然不能以此来限定本申请之权利范围,因此依本申请权利要求所作的等同变化,仍属本申请所涵盖的范围。The above disclosure is only the preferred embodiment of the present application, which certainly cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410470688.3A CN118363986B (en) | 2024-04-18 | 2024-04-18 | Encryption and decryption method and device for secret database |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410470688.3A CN118363986B (en) | 2024-04-18 | 2024-04-18 | Encryption and decryption method and device for secret database |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN118363986A true CN118363986A (en) | 2024-07-19 |
| CN118363986B CN118363986B (en) | 2025-03-04 |
Family
ID=91882654
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202410470688.3A Active CN118363986B (en) | 2024-04-18 | 2024-04-18 | Encryption and decryption method and device for secret database |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN118363986B (en) |
Citations (11)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20140380051A1 (en) * | 2013-06-21 | 2014-12-25 | International Business Machines Corporation | Secure data access using sql query rewrites |
| US20150039901A1 (en) * | 2013-07-30 | 2015-02-05 | International Business Machines Corporation | Field level database encryption using a transient key |
| EP2865127A1 (en) * | 2012-06-22 | 2015-04-29 | Commonwealth Scientific and Industrial Research Organisation | Homomorphic encryption for database querying |
| CN105787387A (en) * | 2016-03-07 | 2016-07-20 | 南京邮电大学 | Database encryption method and encryption database query method |
| CN109815719A (en) * | 2019-01-21 | 2019-05-28 | 广东电网有限责任公司信息中心 | A kind of database security encryption system that can search for |
| CN112800088A (en) * | 2021-01-19 | 2021-05-14 | 东北大学 | Database ciphertext retrieval system and method based on bidirectional security index |
| CN113111082A (en) * | 2021-03-09 | 2021-07-13 | 深圳市教育信息技术中心(深圳市教育装备中心) | Structured query statement rewriting method, device, equipment and medium |
| CN113722359A (en) * | 2021-09-03 | 2021-11-30 | 西安电子科技大学 | SQL query rewriting method for dense OLTP task |
| CN113742362A (en) * | 2021-09-03 | 2021-12-03 | 西安电子科技大学 | Ciphertext query calculation method oriented to secret database |
| CN116436682A (en) * | 2023-04-23 | 2023-07-14 | 浙江网商银行股份有限公司 | Data processing method, device and system |
| CN117763614A (en) * | 2023-12-27 | 2024-03-26 | 国网河南省电力公司电力科学研究院 | A method of intercepting and rewriting SQL statements |
-
2024
- 2024-04-18 CN CN202410470688.3A patent/CN118363986B/en active Active
Patent Citations (11)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| EP2865127A1 (en) * | 2012-06-22 | 2015-04-29 | Commonwealth Scientific and Industrial Research Organisation | Homomorphic encryption for database querying |
| US20140380051A1 (en) * | 2013-06-21 | 2014-12-25 | International Business Machines Corporation | Secure data access using sql query rewrites |
| US20150039901A1 (en) * | 2013-07-30 | 2015-02-05 | International Business Machines Corporation | Field level database encryption using a transient key |
| CN105787387A (en) * | 2016-03-07 | 2016-07-20 | 南京邮电大学 | Database encryption method and encryption database query method |
| CN109815719A (en) * | 2019-01-21 | 2019-05-28 | 广东电网有限责任公司信息中心 | A kind of database security encryption system that can search for |
| CN112800088A (en) * | 2021-01-19 | 2021-05-14 | 东北大学 | Database ciphertext retrieval system and method based on bidirectional security index |
| CN113111082A (en) * | 2021-03-09 | 2021-07-13 | 深圳市教育信息技术中心(深圳市教育装备中心) | Structured query statement rewriting method, device, equipment and medium |
| CN113722359A (en) * | 2021-09-03 | 2021-11-30 | 西安电子科技大学 | SQL query rewriting method for dense OLTP task |
| CN113742362A (en) * | 2021-09-03 | 2021-12-03 | 西安电子科技大学 | Ciphertext query calculation method oriented to secret database |
| CN116436682A (en) * | 2023-04-23 | 2023-07-14 | 浙江网商银行股份有限公司 | Data processing method, device and system |
| CN117763614A (en) * | 2023-12-27 | 2024-03-26 | 国网河南省电力公司电力科学研究院 | A method of intercepting and rewriting SQL statements |
Non-Patent Citations (2)
| Title |
|---|
| 江炳城;何倩;陈亦婷;刘鹏;: "面向云数据库的属性基加密和查询转换中间件", 计算机应用, no. 08, 7 May 2018 (2018-05-07) * |
| 王福超;牛长春;: "基于加密数据库的快速查询方法研究", 网络安全技术与应用, no. 04, 15 April 2020 (2020-04-15) * |
Also Published As
| Publication number | Publication date |
|---|---|
| CN118363986B (en) | 2025-03-04 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US11709948B1 (en) | Systems and methods for generation of secure indexes for cryptographically-secure queries | |
| US9548866B2 (en) | Deletion of content in digital storage systems | |
| Iyer et al. | A framework for efficient storage security in RDBMS | |
| US8375224B2 (en) | Data masking with an encrypted seed | |
| CN1761923B (en) | Method and device for encrypting database columns | |
| CN106934298B (en) | Transparent encryption system for universal database | |
| US10664610B2 (en) | Method and system for range search on encrypted data | |
| EP3417397A1 (en) | Searchable encryption of conjunctive sql statements | |
| US8769302B2 (en) | Encrypting data and characterization data that describes valid contents of a column | |
| Dowsley et al. | A survey on design and implementation of protected searchable data in the cloud | |
| Macedo et al. | A practical framework for privacy-preserving NoSQL databases | |
| CN110166221A (en) | A kind of ciphertext compression storing data structure RCPE and data dynamic read/write method | |
| US9178703B2 (en) | Method of protecting a control vector in an optional block of a standard key block | |
| CN106874516A (en) | Efficient cipher text retrieval method based on KCB trees and Bloom filter in a kind of cloud storage | |
| US20230315896A1 (en) | Systems and methods for end-to end-encryption with encrypted multi-maps | |
| EP3711256A1 (en) | Cryptographic key generation for logically sharded data stores | |
| CN111797425B (en) | Secure database using dictionary encoding | |
| CN117763614A (en) | A method of intercepting and rewriting SQL statements | |
| CN119089479B (en) | Space database encryption method, equipment and medium | |
| US20220318219A1 (en) | Searchable encryption | |
| US20250068775A1 (en) | Systems and methods for data security on a mobile device | |
| CN118363986B (en) | Encryption and decryption method and device for secret database | |
| CN115599872A (en) | Data processing method and system for relational database | |
| US20130058487A1 (en) | Method of building optional blocks | |
| US20130054624A1 (en) | Method of parsing optional block data |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |