Disclosure of Invention
In order to overcome the problem that the decrypted key is not safely stored in the client software or at least partially solve the problem, the invention provides a file decryption method and a file decryption device.
According to a first aspect of the present invention, there is provided a file decryption method, comprising:
receiving information of a request key sent by a client, wherein the key is positioned in a Windows service program, and the Windows service program and the client communicate through a named pipeline;
and sending the key to the client side so that the client side can decrypt the encrypted file on the client side according to the key.
Specifically, the Windows service program and the client communicate through a named pipe, including:
creating the named pipe;
waiting for the client to connect the named pipe;
reading the information of the request key sent by the client through the named pipeline;
writing the key in the named pipe.
Specifically, before receiving the information of the request key sent by the client, the method further includes:
the existence of a process of client software is monitored.
Specifically, the process of monitoring whether the client software exists includes:
a thread is created to monitor whether a process of the client software exists.
Specifically, the monitoring whether the process of the client software exists includes:
acquiring a process name list in a system;
and inquiring whether the process name of the client software exists in the process name list.
Specifically, the monitoring whether the process of the client software exists includes:
and if the process of the client software does not exist, monitoring whether the process of the client software exists again every preset time.
According to a second aspect of the present invention, there is provided a file decryption method, comprising:
sending information of a request key to a Windows service program, wherein the key is positioned in the Windows service program, and the Windows service program and a client communicate through a named pipeline;
receiving a key sent by the Windows service program;
and decrypting the encrypted file on the client according to the key.
Specifically, the communication between the Windows service program and the client through the named pipe includes:
connecting the named pipelines created by the Windows service program;
waiting for the response of the Windows service program;
writing information of a request key into the named pipeline;
and reading the key sent by the Windows service program from the named pipeline.
According to a third aspect of the present invention, there is provided a file decryption apparatus comprising:
the system comprises a first receiving unit, a second receiving unit and a third receiving unit, wherein the first receiving unit is used for receiving information of a request key sent by a client, the key is positioned in a Windows service program, and the Windows service program and the client communicate through a named pipeline;
and the first sending unit is used for sending the key to the client so that the client can decrypt the encrypted file on the client according to the key.
According to a fourth aspect of the present invention, there is provided a file decryption apparatus comprising:
the second sending unit is used for sending the information of the request key to a Windows service program, the key is positioned in the Windows service program, and the Windows service program and the client communicate through a named pipeline;
the second receiving unit is used for receiving the key sent by the Windows service program;
and the decryption unit is used for decrypting the encrypted file on the client according to the key.
The invention puts the decrypted key into the Windows service program, and the Windows service program and the software using the encrypted file are packaged and installed on the client side. And when the client software is started, starting the Windows service program. And when the software needs to use the encrypted file, decrypting the encrypted file. The decrypted key is obtained from the Windows service program in an interprocess communication mode, so that the decrypted key is hidden more secretly, and the encryption effect is enhanced.
Detailed Description
The following detailed description of embodiments of the present invention is provided in connection with the accompanying drawings and examples. The following examples are intended to illustrate the invention but are not intended to limit the scope of the invention.
Fig. 1 is a flowchart of a file decryption method according to an embodiment of the present invention. As shown in fig. 1, includes: s11, receiving the information of the request key sent by the client, wherein the key is located in the Windows service program, and the Windows service program and the client communicate through a named pipeline; and S12, sending the key to the client, so that the client can decrypt the encrypted file on the client according to the key.
In S11, the client is a program for providing local service to the client. The key is a parameter input in a decryption algorithm and is a decrypted key. The Windows service program is used for storing the decrypted key. The Windows service program and the client communicate through a named pipe. But is not limited in this manner. The named pipeline completes the communication between the processes through the network, shields the details of the underlying network protocol, and only needs to be connected through a corresponding communication port in the process, thereby realizing the direct communication between the Windows service program and the client software. In S12, the file may be a picture file, a script file, an animation file, a sound file, or the like. The file needs to be encrypted before decryption. The file process may be encrypted using a public key generated by the RSA algorithm and the file may be decrypted using a private key generated by the RSA algorithm, but is not limited to such encryption algorithms. And the Windows service program receives the information of the request key sent by the client, and the key is positioned in the Windows service program. And the Windows service program receives the information of the request key sent by the client, encrypts the key and then sends the encrypted key to the client so that the client can decrypt the encrypted file on the client according to the key.
The method comprises the steps of firstly defining a SERVICE forwarding table structure, namely SERVICE _ TAB L E _ ENTRY SERVICE table, SERVICE table [0] lpServiceName ═ T (SERVICE _ NAME), SERVICE table [0] lpServiceProc ═ L PSERVICE _ MAIN _ FUNCTION) SERVICE _ MAIN, wherein the SERVICE forwarding table structure is SERVICE _ TAB L E _ ENTRY, defined variables are SERVICE table, the SERVICE forwarding table structure has 2 attributes, namely a SERVICE NAME and a callback FUNCTION, the SERVICE NAME is the NAME of the created Windows SERVICE, the callback FUNCTION points to an ENTRY FUNCTION of the Windows SERVICE, and the SERVICE API FUNCTION StartDictcher is called, parameters in the SERVICE forwarding table are written into the created SERVICE forwarding table, and the corresponding relation between the SERVICE NAME and the ENTRY FUNCTION is created.
Firstly, reading the file to a memory, namely FI L E file (foxen, rb), wherein fopen is a system library function, xxx is a file name of the file, and rb is a read file, moving a file pointer to the tail of the file, acquiring the size of the file, namely fseek (file,0, SEEK _ END), uint file (ftell) (file), calling a read function to read the whole file to the memory, and storing the whole file in a cache buf, namely, the read (1, file), and calling an RSA algorithm to decrypt the file, namely, RSA.
In this embodiment, the decrypted key is put into a Windows service program, and the Windows service program and the client software are packaged and installed to the client. And when the client software is started, starting the Windows service. And when the client software needs to use the file, decrypting the file. The decrypted key is obtained from the Windows service program in an interprocess communication mode, so that the decrypted key is hidden more secretly, and the encryption effect is enhanced.
On the basis of the foregoing embodiments, in this embodiment, the communicating between the Windows service program and the client via a named pipe includes: creating the named pipe; waiting for the client to connect the named pipe; reading the information of the request key sent by the client through the named pipeline; writing the key in the named pipe.
Specifically, the Windows service program establishes communication connection with the client in a form of constructing a named pipe. Firstly, the Windows service program calls the Windows api function CreateNamedPipe to create a named pipe, and it should be noted that the name of the named pipe can be set at will as long as it is not renamed with the pipe of other processes of the system. And then waits for the connection of the client by calling the function ConnectNamedPipe. The Windows service program calls a function ReadFile to read the information sent by the client and writes the key into the named pipeline by calling a function WriteFile, wherein the key can be encrypted, so that the key is sent to the client so that the client can decrypt the encrypted file on the client according to the key.
In this embodiment, the data communication between the Windows service and the client is realized by constructing a named pipe, and a bottom network protocol is shielded, so that the direct communication between the Windows service program and the client is realized, but not limited to this communication manner.
On the basis of the above embodiments, before receiving the information of the request key sent by the client, a process of monitoring whether client software exists is further included.
And packaging the written Windows service program and the client software into an installation program together before decryption. The Windows service program creates a thread to monitor whether a process of the client software exists. And if the process of the client software does not exist, monitoring whether the process of the client software exists again every preset time. When the client software is started, the thread monitors the progress of the client software, and the Windows service is also started. And when the Windows service is stopped, stopping the execution of the thread and releasing the thread, thereby finishing the cleaning work of the Windows service, such as releasing resources and the like.
The method comprises the steps of writing a callback FUNCTION of the Windows SERVICE STOP in an entry FUNCTION of the Windows SERVICE, and simultaneously creating a thread to monitor whether a process of the client software exists, wherein a FUNCTION RegisterServiceCtrLHandler is used for registering a callback FUNCTION of the Windows SERVICE, the FUNCTION prototype of which is SERVICE _ STATUS _ HAND L E WINDOW API RegisterServictCtrLHandler (L PCTSTRlpServiceName, &lTtTtranslation = L "& &gggTtTtTtTtTtTtPHTtPHR L ER _ FUNCTIONlpHandProc), wherein the L PCTR laceName represents a SERVICE name, the TS L PHTRYPREJFUNCTIONlpHandProc represents a FUNCTION of the SERVICE, the callback FUNCTION pointing to the API FUNCTION of the Windows SERVICE STOP, namely pSpStuceServiceName (pSTRVItJNV _ Controll), the call is used for controlling the execution of the Windows SERVICE STOP call, and the call of the Windows SERVICE call is called by the Windows thread call entry FUNCTION of the Windows SERVICE STOP program, wherein the DWORD SERVICE call control thread TYPROD (DWORD _ NUT _ PAStWINDOW _ PASTRORD) FUNCTION is used for monitoring the call, the call when the call of the Windows SERVICE STOP FUNCTION of the Windows SERVICE exists, the Windows SERVICE call of the Windows SERVICE STOP FUNCTION of the Windows thread call of the Windows thread of the Windows SERVICE STOP type of the Windows thread of the Windows SERVICE STOP FUNCTION of the Windows thread of the Windows SERVICE STOP type.
In this embodiment, the server monitors whether the client software is started by creating a thread. When the client software is started, the services of the Windows are also started. When the Windows service is stopped, the execution of the thread is stopped and the thread is released. The Windows service is started for decryption when the client software is started, and the effect of confidentiality is enhanced. And when the Windows service is stopped, stopping the thread, releasing the resources and reducing the waste of the resources.
On the basis of the foregoing embodiments, in this embodiment, monitoring whether a process of the client software exists includes acquiring a process name list in a system; and inquiring whether the process name of the client software exists in the process name list.
The Windows service program acquires a snapshot of a process name list in a system and then acquires a first process name in the snapshot of the process name list. And acquiring other process names in the system according to the first process name, thereby acquiring a process name list of the process currently running. The process names are the process names of all threads currently running. And inquiring whether the process name of the client software exists in the process name list, namely monitoring whether the process of the client software exists in the current process. And if the process name of the client software exists, starting the Windows service. And if the process name of the client software does not exist, acquiring a process name list in the system again at intervals of preset time, and then inquiring whether the process name of the client software exists in the process name list. And if the process name list does not exist, continuing to wait for the preset time length and then acquiring the process name list in the system again. And if so, starting the Windows service.
Specifically, the Windows service program First obtains a Snapshot of a Process name list in the system by calling a system API function CreateToolhelp32 snaphot (TH32CS _ snap LL, 0), wherein TH32 _ snap represents that a Snapshot of the Process name list is obtained, and then obtains a First Process name from the Snapshot of the Process name list by calling a system API function Process32First, that is, a Process32First (hsnshot, & proctry 32), wherein a First parameter hsnshel is a handle of the obtained Snapshot, and & proctrey 32 is used for returning information of the obtained Process, and an attribute szeefile of the proctrey 32 is a Process name, that is, a Process 32. szecheny service program obtains a Process name in a Process name list, that is, a Process name of a Process name list, and then, if the Process name list is obtained by calling a procedure API function call command, the Process name list is obtained by calling a procedure server API function call, and if the Process name of the Process name list is found in the procedure server call, the procedure server call procedure name list is obtained by calling a procedure server API function netpage name, and then, the procedure call server call a procedure name of the procedure call server API function call, wherein the Process name of a procedure call is found in the procedure name list of a procedure 5932 Process name of a procedure server name of a procedure found in the Process name of a procedure found in the procedure server.
In this embodiment, a process name list in the system is obtained, and whether a process name of the client software exists is queried in the process name list, so that the client software is monitored for starting. When the software is monitored to be started, the Windows service is started, the file is decrypted, and the security effect is enhanced.
Fig. 2 is a flowchart of a file decryption method according to an embodiment of the present invention. As shown in fig. 2, includes: s21, sending the information of the request key to a Windows service program, wherein the key is located in the Windows service program, and the Windows service program and the client communicate through a named pipeline; s22, receiving the key sent by the Windows service program; and S23, decrypting the encrypted file on the client according to the key.
In S21, the Windows service program is used as a server. The key is a parameter input in a decryption algorithm and is a decrypted key. The Windows service program is used for storing the decrypted key. The Windows service program and the client communicate through a named pipe. But is not limited in this manner. The named pipeline completes the communication between the processes through the network, shields the details of the underlying network protocol, and only needs to be connected through a corresponding communication port in the process, thereby realizing the direct communication between the Windows service program and the client software. In S22, the file may be a picture file, a script file, an animation file, a sound file, or the like. In S23, the decryption may be performed by calling a corresponding function according to an encryption algorithm. The key is located in the Windows service program. When the software on the client needs to use the file, if the file is encrypted, the client sends the information of the request key to the Windows service program. And after receiving the encrypted key sent by the Windows service program, the client reads the resource file into the memory, and transmits the key as a parameter to the called decryption function, so that the resource is decrypted.
In this embodiment, the decrypted key is put into a Windows service program, and the Windows service program and the client software are packaged and installed to the client. And when the client software is started, starting the Windows service program. And when the client software needs to use the file, decrypting the file. The decrypted key is obtained from the Windows service program in an interprocess communication mode, so that the decrypted key is hidden more secretly, and the encryption effect is enhanced.
On the basis of the foregoing embodiment, in this embodiment, the communicating between the Windows service program and the client through the named pipe includes: connecting the named pipelines created by the Windows service program; waiting for the response of the Windows service program; writing information of a request key into the named pipeline; and reading the key sent by the Windows service program from the named pipeline.
Specifically, the client connects the named pipes by calling a function CreateFile. And calling a function ConnectNamedPipe to wait for the response of the Windows service program, and calling a function WriteFile to write the information of the request key into the named pipeline after the client receives the response of the Windows service program through the named pipeline. The client calls the function ReadFile to read the key sent by the Windows service program from the pipe, and the key may be encrypted. And the client decrypts the key to obtain an original value, so that the file is decrypted.
In this embodiment, the data communication between the Windows service and the client is realized by constructing a named pipe, and a bottom network protocol is shielded, so that the direct communication between the Windows service program and the client is realized, but not limited to this communication manner.
Fig. 3 is a structural diagram of a file decryption apparatus according to an embodiment of the present invention, as shown in fig. 3, including a first receiving unit 11 and a second sending unit 12, where: the first receiving unit 11 is configured to receive information of a request key sent by a client, where the key is located in a Windows service program, and the Windows service program and the client communicate through a named pipe; the first sending unit 12 is configured to send the key to the client, so that the client decrypts the encrypted file on the client according to the key.
Specifically, the client refers to a program for providing local services for the client. The key is a parameter input in a decryption algorithm and is a decrypted key. The Windows service program is used for storing the decrypted key. The file may be a picture file, a script file, an animation file, a sound file, etc. The file needs to be encrypted before decryption. The file process may be encrypted using a public key generated by the RSA algorithm and the file may be decrypted using a private key generated by the RSA algorithm, but is not limited to such encryption algorithms. And the Windows service program receives the information of the request key sent by the client, and the key is positioned in the Windows service program. The Windows service program and the client communicate through a named pipe. But is not limited in this manner. After the receiving unit 11 receives the information of the request key sent by the client, the sending unit 12 encrypts the key and sends the encrypted key to the client, so that the client can decrypt the encrypted file on the client according to the key.
In this embodiment, the decrypted key is put into a Windows service program, and the Windows service program and the client software are packaged and installed to the client. And when the client software is started, starting the Windows service. And when the client software needs to use the file, decrypting the file. The decrypted key is obtained from the Windows service program in an interprocess communication mode, so that the decrypted key is hidden more secretly, and the encryption effect is enhanced.
Fig. 4 is a structural diagram of a file decryption apparatus according to an embodiment of the present invention, as shown in fig. 4, including a second sending unit 21, a second receiving unit 22, and a decryption unit 23, where: the second sending unit 21 is configured to send information of a request key to a Windows service program, where the key is located in the Windows service program, and the Windows service program communicates with a client through a named pipe; the second receiving unit 22 is configured to receive a key sent by the Windows service program; the decryption unit 23 is configured to decrypt the encrypted file on the client according to the key.
Specifically, the Windows service program is used as a server. The key is a parameter input in a decryption algorithm and is a decrypted key. The Windows service program is used for storing the decrypted key. The file may be a picture file, a script file, an animation file, a sound file, etc. The decryption may be performed by calling a corresponding function according to an encryption algorithm. The key is located in the Windows service program. The Windows service program and the client communicate through a named pipe. But is not limited in this manner. When the software on the client needs to use the file, if the file is encrypted, the second sending unit 21 sends the information requesting the key to the Windows service program. After the second receiving unit 22 receives the encrypted key sent by the Windows service program, the decryption unit 23 reads the resource file into the memory, and transfers the key as a parameter to the called decryption function, thereby implementing decryption of the resource.
In this embodiment, the decrypted key is put into a Windows service program, and the Windows service program and the client software are packaged and installed to the client. And when the client software is started, starting the Windows service program. And when the client software needs to use the file, decrypting the file. The decrypted key is obtained from the Windows service program in an interprocess communication mode, so that the decrypted key is hidden more secretly, and the encryption effect is enhanced.
Finally, the method of the present application is only a preferred embodiment and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.