Disclosure of Invention
In order to solve the problems, the invention provides a transparent encryption and decryption method, which comprises the following steps:
A configuration management layer;
Setting a transparent encryption and decryption layer;
obtaining a secret file;
And carrying out transparent encryption and decryption on the secret file by using the transparent encryption and decryption layer.
Preferably, the configuration management layer includes the steps of:
installing configuration management software;
Using the configuration management software to open a secret file;
Acquiring a current process in a VFS layer;
Judging whether the current process is a configuration management process or not;
if yes, judging whether the confidential file needs to be subjected to confidential treatment or not;
if not, returning to the step of installing configuration management software;
if yes, carrying out confidentiality treatment on the confidentiality file;
if not, continuing to open the secret file.
Preferably, the security processing of the security document includes the steps of:
Initializing a hash chain table node;
acquiring a file structure body of the secret file;
Calculating a key value of the hash chain table node according to the structural body;
inserting node information of the structural body and the hash chain table nodes into a hash chain table;
filling security level information in the hash chain table;
and writing the hash chain table into the head part of the security file.
Preferably, the setting the transparent encryption and decryption layer includes the steps of:
Opening any file;
Reading a header secret field of the open file;
judging whether the header security field has a security level field or not;
if yes, encrypting the opened file;
if not, continuing to open the opened file.
Preferably, the encrypting the open file includes the steps of:
Initializing a hash chain table node;
acquiring a structure body of the opening file;
Calculating a key value of the hash chain table node according to the structural body;
inserting the file structure body and the hash chain table node into a hash chain table;
and generating key values required by encryption and decryption through the file structure body.
Preferably, the transparent encrypting and decrypting the secret document by using the transparent encrypting and decrypting layer includes the steps of:
Performing a write security operation on the security file;
performing a read security operation on the security document;
And executing closing operation on the secret file.
The transparent encryption and decryption method provided by the application solves the problem that the transparent encryption and decryption can be carried out only by relying on a specific file system, and the kernel object file generated in the scheme flow has reusability and supports secondary development under a Linux platform.
Detailed Description
The objects, technical solutions and advantages of the present invention will become more apparent by the following detailed description of the present invention with reference to the accompanying drawings. It should be understood that the description is only illustrative and is not intended to limit the scope of the invention. In addition, in the following description, descriptions of well-known structures and techniques are omitted so as not to unnecessarily obscure the present invention.
In the embodiment of the present application, as shown in fig. 1, the present application provides a transparent encryption and decryption method, which includes the steps of:
s1, configuring a management layer;
In an embodiment of the present application, the configuration management layer includes the steps of:
installing configuration management software;
Using the configuration management software to open a secret file;
Acquiring a current process in a VFS layer;
Judging whether the current process is a configuration management process or not;
if yes, judging whether the confidential file needs to be subjected to confidential treatment or not;
if not, returning to the step of installing configuration management software;
if yes, carrying out confidentiality treatment on the confidentiality file;
if not, continuing to open the secret file.
In the embodiment of the present application, as shown in fig. 2 and 3, the configuration and creation of the security file under the Linux platform includes a plurality of detailed steps, and the specific flow is as follows:
When a new security document is created:
(1) Opening user configuration management software;
(2) The user configuration management software open a new secret file, select whether to create the secret file;
(3) Step (2) entering into the VFS layer through system call, judging whether the current process is a user configuration management process in the do_sys_open function of the VFS layer, if so, judging whether to carry out security treatment on the file, if so, entering into step (4), otherwise, entering into step (5);
(4) Performing security treatment:
(5) Executing an open follow-up action;
And (5) ending.
In an embodiment of the present application, the performing security processing on the security document includes the steps of:
Initializing a hash chain table node;
acquiring a file structure body of the secret file;
Calculating a key value of the hash chain table node according to the structural body;
inserting node information of the structural body and the hash chain table nodes into a hash chain table;
filling security level information in the hash chain table;
and writing the hash chain table into the head part of the security file.
In the embodiment of the application, the specific steps of carrying out the security treatment on the security document are as follows:
a. Initializing a hash chain table node;
b. calculating a hash key value through an address of a file structure body of the opened file;
c. inserting the file structure body and initialized node information into a hash chain table;
d. Filling corresponding security level information, and writing the information into the file header.
S2, setting a transparent encryption and decryption layer;
In the embodiment of the application, the setting of the transparent encryption and decryption layer comprises the following steps:
Opening any file;
Reading a header secret field of the open file;
judging whether the header security field has a security level field or not;
if yes, encrypting the opened file;
if not, continuing to open the opened file.
In the embodiment of the application, the specific steps of setting the transparent encryption and decryption layer are as follows:
When an existing file is opened:
(1) The user reads an existing file through any file reading software open;
(2) Step (1), entering a VFS layer through system call, reading a file header secret field in a do_sys_open function of the VFS layer, judging whether the field has a secret level field, and entering step (3) when the field is a secret file, and entering step (4) when the field is a non-secret file;
(3) When the file is judged to be a secret file, encrypting the opened file;
(4) An open follow-up action is performed.
In an embodiment of the present application, the encrypting the open file includes the steps of:
Initializing a hash chain table node;
acquiring a structure body of the opening file;
Calculating a key value of the hash chain table node according to the structural body;
inserting the file structure body and the hash chain table node into a hash chain table;
and generating key values required by encryption and decryption through the file structure body.
In the embodiment of the application, the encryption processing of the open file specifically comprises the following steps:
a. Initializing a hash chain table node;
b. calculating a hash key value through an address of a file structure body of the opened file;
c. Inserting the file structure body and the initialized buffer area into a hash chain table;
d. and generating key values required by encryption and decryption.
S3, acquiring a secret file;
s4, carrying out transparent encryption and decryption on the secret file by utilizing the transparent encryption and decryption layer.
In the embodiment of the present application, the transparent encrypting and decrypting the secret document by using the transparent encrypting and decrypting layer includes the steps of:
Performing a write security operation on the security file;
performing a read security operation on the security document;
And executing closing operation on the secret file.
In the embodiment of the present application, as shown in fig. 4, the specific steps of performing the write security operation on the security document are as follows:
(1) The user performs write operation on an open file;
(2) Step (1) entering a VFS layer through system call, calculating a hash value through a file structure address in a vfs_write function of the VFS layer, searching whether corresponding secret node information is stored in a hash chain table through the hash value, entering step (3) when the node exists, and entering step (4) when the secret node information is not found;
(3) And (3) encrypting the secret file:
a, judging whether the length of the written data is smaller than the length of the buffer zone, if so, entering the step (b), and if so, entering the step (c);
b, putting the data into a buffer area, and entering a step c when a user executes a closing action or when the buffer area is full;
c, encrypting the data;
(4) Executing a write follow-up action;
And (5) ending.
In the embodiment of the present application, as shown in fig. 5, the specific steps of performing the read security operation on the security document are as follows:
(1) The user performs read reading operation on an open file;
(2) Step (1) entering a VFS layer through system call, calculating a hash value through a file structure address in a vfs_read function of the VFS layer, searching whether corresponding secret node information is stored in a hash chain table through the hash value, entering step (3) when the node exists, and entering step (4) when the secret node information is not found;
(3) And (3) performing read reading operation on the confidential file:
a, checking whether data exists in the buffer area, and entering the step (d) when the buffer area has no data, and entering the step (b) when the buffer area has data;
b, checking whether the data in the buffer area meets the length of the data to be read, and entering the step (c) when the length to be read is met, and entering the step (d) when the length to be read is not met;
c, acquiring data of a buffer area, and entering a step f;
Reading out the data of the buffer area;
reading data from a specific file system, putting the data into a buffer area, calling a decryption unit, and decrypting the data in the buffer area;
f, returning the decrypted data to the user;
(4) Executing read follow-up actions;
(5) And (5) ending.
In fig. 6, in the embodiment of the present application, the specific steps of executing the closing operation on the security document are as follows:
(1) The user performs close closing operation on an open file;
(2) Step (1) entering a VFS layer through system call, calculating a hash value through a file structure body address in a filp _close function of the VFS layer, searching whether corresponding secret node information is stored in a hash chain table through the hash value, and entering step (3) when the node exists;
(3) Closing the confidential file:
a, judging whether data exists in a buffer area in a node, and calling an encryption unit to encrypt the data when the data exists;
b, writing the encrypted data into a file system;
(4) And executing a close follow-up action.
(5) And (5) ending.
The transparent encryption and decryption method provided by the application solves the problem that the transparent encryption and decryption can be carried out only by relying on a specific file system, and the kernel object file generated in the scheme flow has reusability and supports secondary development under a Linux platform.
It is to be understood that the above-described embodiments of the present invention are merely illustrative of or explanation of the principles of the present invention and are in no way limiting of the invention. Accordingly, any modification, equivalent replacement, improvement, etc. made without departing from the spirit and scope of the present invention should be included in the scope of the present invention. Furthermore, the appended claims are intended to cover all such changes and modifications that fall within the scope and boundary of the appended claims, or equivalents of such scope and boundary.