The content of the invention
To overcome the key of above-mentioned decryption to be stored in unsafe problem in client software or solving at least in part
Above mentioned problem, the invention provides a kind of file decryption method and device.
According to the first aspect of the invention, there is provided a kind of file decryption method, including:
The information for the request key that client is sent is received, the key is located in Windows service routines, described
Windows service routines and the client are by naming pipeline to be communicated;
The key is sent to the client, for the client according to the key to adding in the client
Close file is decrypted.
Specifically, the Windows service routines and the client be by naming pipeline to be communicated, including:
Create the name pipeline;
The client is waited to connect the name pipeline;
Read the information for the request key that the client is sent by the name pipeline;
The key is write in the name pipeline.
Specifically, before the information for the request key that the reception client is sent, in addition to:
Monitor whether the process that client software be present.
Specifically, the process for monitoring whether to have client software, including:
Thread is created to monitor whether the process that the client software be present.
Specifically, the process for monitoring whether to have the client software, including:
Process name list in acquisition system;
Process title of the inquiry with the presence or absence of the client software in the process name list.
Specifically, the process for monitoring whether to have the client software, including:
If judging the process in the absence of the client software, monitor whether the visitor be present again every preset duration
The process of family end software.
A kind of file decryption method is provided according to the second aspect of the invention, including:
The information for asking key is sent to Windows service routines, the key is located at the Windows service routines
In, the Windows service routines and client are by naming pipeline to be communicated;
Receive the key that the Windows service routines are sent;
The file encrypted in the client is decrypted according to the key.
Specifically, the Windows service routines and client are included by naming pipeline to carry out communication:
Connect the name pipeline that the Windows service routines create;
Wait the response of the Windows service routines;
The information of write request key into the name pipeline;
The key that the Windows service routines are sent is read from the name pipeline.
A kind of file deciphering device is provided according to the third aspect of the invention we, including:
First receiving unit, the information of the request key for receiving client transmission, the key are located at Windows clothes
In program of being engaged in, the Windows service routines and the client are by naming pipeline to be communicated;
First transmitting element, for the key to be sent into the client, so that the client is according to described close
The file encrypted in the client is decrypted key.
A kind of file deciphering device is provided according to the fourth aspect of the invention, including:
Second transmitting element, for the information for asking key to be sent into Windows service routines, the key is located at institute
State in Windows service routines, the Windows service routines and client are by naming pipeline to be communicated;
Second receiving unit, the key sent for receiving the Windows service routines;
Decryption unit, for the file encrypted in the client to be decrypted according to the key.
The key of decryption is put into Windows service routines by the present invention, described in the Windows service routines and use
The software of encryption file is packed together is installed to client.When starting the client software, start the Windows services
Program.The file of the encryption is decrypted when needing to use the file of the encryption for the software.The key of decryption leads to
The mode for crossing interprocess communication obtains from the Windows service routines, so as to more reconditely hide the key of decryption, enhancing
The effect of encryption.
Embodiment
With reference to the accompanying drawings and examples, the embodiment of the present invention is described in further detail.Implement below
Example is used to illustrate the present invention, but is not limited to the scope of the present invention.
Fig. 1 is file decryption method flow diagram provided in an embodiment of the present invention.As shown in figure 1, including:S11, receive client
The information for the request key that end is sent, the key are located in Windows service routines, the Windows service routines and institute
Client is stated by naming pipeline to be communicated;S12, the key is sent to the client, for the client root
The file encrypted in the client is decrypted according to the key.
Wherein, in S11, the client refers to the program that local service is provided for client.The key is decipherment algorithm
The parameter of middle input, for the key of decryption.The Windows service routines are used for the key for preserving decryption.The Windows clothes
Program of being engaged in and the client are by naming pipeline to be communicated.But it is not limited only to this mode.The name pipeline is to pass through net
Network completes the communication between process, shields the procotol details of bottom, it is only necessary to pass through corresponding COM1 in process
It is attached, it is achieved thereby that the direct communication between the Windows service routines and the client software.In S12, institute
It can be picture file, script file, animation file, audio files etc. to state file.Before being decrypted, it is necessary to first to described
File is encrypted.The public key that RSA Algorithm can be used to generate is encrypted to the file process, the private generated using RSA Algorithm
The file is decrypted key, but is not limited to such a AES.The Windows service routines receive the client hair
The information of the request key sent, the key are located in the Windows service routines.The Windows service routines receive
The information for the request key that the client is sent, is sent to the client, for the client after the key is encrypted
The file encrypted in the client is decrypted according to the key for end.
Specifically, Windows service routines are write before decryption.A service forward table structure is defined first, i.e.
SERVICE_TABLE_ENTRY ServiceTable;ServiceTable [0] .lpServiceName=_T (SERVICE_
NAME);ServiceTable [0] .lpServiceProc=(LPSERVICE_MAIN_FUNCTION) service_main, its
In, the service forward table structure is SERVICE_TABLE_ENTRY, and the variable of definition is ServiceTable.The service
Forward table structure has 2 attributes, i.e. service name and call back function.The service name is the name of the Windows services created
Claim.The call back function points to the entrance function of the Windows services.Calling system api function
StartServiceCtrlDispatcher, in the service forward table that parameter read-in therein is created, create the Service name
Claim the corresponding relation with the entrance function.When the Windows, which is serviced, to be started, the entrance function is called, i.e. void
WINAPI service_main(int argc,char**argv)。
After the client gets the key of decryption file, then decipherment algorithm can be used to the file that decrypt of needs
It is decrypted.First, the file is read into internal memory, i.e. FILE*file=fopen (" xxx ", " rb ").Wherein, fopen
For system library function, " xxx " is the filename of the file, and " rb " is reading file.File pointer is moved to tail of file,
Obtain file size, i.e. fseek (file, 0, SEEK_END);Uint filesize=ftell (file).Call fread letters
Whole file is read internal memory by number, and is stored in caching buf, i.e. fread (buf, filesize, 1, file).If plus
It is close to use RSA Algorithm, then call RSA Algorithm to decrypt the file, i.e. RSA.decrypt (SecretKey, buf,
filesize)。
The key of decryption is put into Windows service routines by the present embodiment, the Windows service routines and the visitor
Family end software is packed together is installed to client.When starting the client software, start the Windows services.Client
Hold software that the file is decrypted when needing to use the file.The key of decryption is by way of interprocess communication
Obtained from the Windows service routines, so as to more reconditely hide the key of decryption, strengthen the effect of encryption.
On the basis of the various embodiments described above, Windows service routines described in the present embodiment and the client pass through
Name pipeline is communicated, including:Create the name pipeline;The client is waited to connect the name pipeline;Read institute
State the information for the request key that client is sent by the name pipeline;The key is write in the name pipeline.
Specifically, the Windows service routines are named the form of pipeline to be established with the client by building and communicated
Connection.First, the Windows service routines Employ Windows API Function CreateNamedPipe creates name pipeline, needs
It is noted that the name of the name pipeline can arbitrarily be set, as long as the pipeline with system other processes is not born the same name.
The connection of client is waited by call function ConnectNamedPipe again.The Windows service routines call function
ReadFile reads the information that the client is sent, and is write by call function WriteFile toward described name in pipeline
The key, the key can be encryption, so as to which the key is sent into the client, for the client root
The file encrypted in the client is decrypted according to the key.
The present embodiment realizes that the data between the Windows services and the client are led to by building name pipeline
Letter, the procotol of bottom is shielded, it is achieved thereby that directly logical between the Windows service routines and the client
Letter, but it is not limited to such a communication mode.
On the basis of the various embodiments described above, before the information for the request key that the reception client is sent, also wrap
Include the process for monitoring whether client software be present.
Wherein, before decryption, the Windows service routines write and the client software are packed together
Into installation procedure.The Windows service routines create thread to monitor whether the process that the client software be present.If
Judge the process in the absence of the client software, then monitor whether the client software be present again every preset duration
Process.When starting the client software, the thread can monitor the process of the client software, the Windows
Service is also started up.When the Windows services are stopped, stop the execution of the thread, and discharge the thread, so as to
The cleaning work of the Windows services is completed, such as discharges resource.
Specifically, the readjustment letter of the Windows service stoppings is write in the entrance function of the service of the Windows
Number, while thread is created to monitor whether the process that the client software be present.Wherein, function
RegisterServiceCtrlHandler is used for the call back function for registering a Windows service, and its function prototype is
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandler(LPCTSTR
LpServiceName, LPHANDLER_FUNCTION lpHandlerProc), wherein, LPCTSTR lpServiceName tables
Show service name, LPHANDLER_FUNCTION lpHandlerProc represent the call back function of service, point to the Windows
The call back function of service stopping, i.e. void WINAPI ServiceHandler (DWORD fdwControl), wherein, DWORD
FdwControl represents service-control event type.When the service-control event type received is SERVICE_CONTROL_
When STOP, SERVICE_CONTROL_SHUTDOWN, the service routine of the Windows is stopped, and now calls Windows's
Function TerminateThread stops the execution of thread.Windows letters are called in the entrance function of Windows services
CreateThread is counted to create thread, i.e. HANDLE task_handle=CreateThread (NULL, NULL, game_
Thread, NULL, NULL, NULL), wherein, game_thread is that the readjustment of thread performs function, and the whole of execution thread is patrolled
Collect function.Then it whether there is the process of the client software using the thread monitor.
Server monitors whether the client software starts by creating thread in the present embodiment.When startup client
During software, the service of the Windows is also started up.When the Windows services are stopped, stop holding for the thread
OK, and thread is discharged.Realize when client software starts, start the Windows services, be decrypted, enhance guarantor
Close effect.In the Windows service stoppings, stop thread, discharge resource, reduce the waste of resource.
On the basis of the various embodiments described above, in the present embodiment, monitor whether the process of the client software be present, wrap
Include the process name list in acquisition system;Inquiry the entering with the presence or absence of the client software in the process name list
Journey title.
Wherein, the snapshot of the process name list in the Windows service routines acquisition system, then enter described in acquisition
First process title in the snapshot of journey name list.According to other processes in first process name acquiring system
Title, so as to obtain the process name list for the process being currently running.The institute that the process is entitled currently to be run is wired
The process title of journey.In the process name list inquiry monitors with the presence or absence of the process title of the client software
Whether the process of the client software is had in current process.If there is the process title of the client software, then start
The Windows services.If there is no the process title of the client software, then system is reacquired every preset duration
In process name list, then in the process name list inquiry with the presence or absence of the client software process name
Claim.If it does not exist, then the process name list in acquisition system again after continuing waiting for preset duration.If it is present open
The dynamic Windows services.
Specifically, the Windows service routines pass through calling system api function first
The snapshot of process name list in CreateToolhelp32Snapshot acquisition systems, i.e. hSnapshot=
CreateToolhelp32Snapshot(TH32CS_SNAPALL,0).Wherein, TH32CS_SNAPPROCESS represents what is obtained
It is the snapshot of process name list.Then by calling system api function Process32First from the process name list
Snapshot in obtain first process title, i.e. Process32First (hSnapshot).Wherein,
One parameter hSnapshot is the information that the handle , &procEntry32 of the snapshot obtained is used to return to the process obtained,
ProcEntry32 attribute szExeFile is process title, i.e. procEntry32.szExeFile is process title.Then,
Other process titles in acquisition system, i.e. while (bMore) bMore=Process32Next (hProcessSnap,
procEntry32);}.By while recursive call function Process32Next, next process title is obtained, until all
Process title, which all obtains, to be finished.The process name list can then be got by the above method.In the process name column
Process title of the inquiry with the presence or absence of the client software in table.If in the presence of starting Windows service.Server
One Windows of calling system Ordered Registration service routine.Registration service can use order line:sc create
Svnserve binpath=" complete trails of service routine ", then call instruction row:Sc start Service names, so as to start
State Windows services.Wherein, the service name of entitled Windows services is serviced.
The present embodiment is inquired about in the process name list and whether there is by the process name list in acquisition system
The process title of the client software, so as to realize the monitoring started to the client software.When monitoring the software
During startup, start the Windows services, file is decrypted, enhances secrecy effect.
Fig. 2 is file decryption method flow diagram provided in an embodiment of the present invention.As shown in Fig. 2 including:S21, it will ask close
The information of key is sent to Windows service routines, and the key is located in the Windows service routines, the Windows clothes
Program of being engaged in and client are by naming pipeline to be communicated;S22, receive the key that the Windows service routines are sent;S23,
The file encrypted in the client is decrypted according to the key.
Wherein, in S21, using the Windows service routines as service end.The key is what is inputted in decipherment algorithm
Parameter, for the key of decryption.The Windows service routines are used for the key for preserving decryption.The Windows service routines and
The client is by naming pipeline to be communicated.But it is not limited only to this mode.The name pipeline is completed by network
Communication between process, shield the procotol details of bottom, it is only necessary to it is attached by corresponding COM1 in process,
It is achieved thereby that the direct communication between the Windows service routines and the client software.In S22, the file can
Think picture file, script file, animation file, audio files etc..In S23, the decryption can call according to AES
Corresponding function is decrypted.The key is located in the Windows service routines.Software in the client is needing
During using the file, if the file has been encrypted, the client is close to Windows service routines transmission request
The information of key.The client is after the key for the encryption that the Windows service routines are sent is received, by resource text
Part reads internal memory, and the decryption function of calling is passed to using the key as parameter, so as to realize the solution to the resource
It is close.
The key of decryption is put into Windows service routines by the present embodiment, the Windows service routines and the visitor
Family end software is packed together is installed to client.When starting the client software, start the Windows service routines.
The file is decrypted when needing to use the file for client software.The key of decryption passes through interprocess communication
Mode obtains from the Windows service routines, so as to more reconditely hide the key of decryption, strengthens the effect of encryption.
On the basis of above-described embodiment, Windows service routines described in the present embodiment and client are managed by naming
Road, which carries out communication, to be included:Connect the name pipeline that the Windows service routines create;Wait the Windows service routines
Response;The information of write request key into the name pipeline;The Windows services are read from the name pipeline
The key that program is sent.
Specifically, the client passes through the call function CreateFile connections name pipeline.Recall function
ConnectNamedPipe waits the response of the Windows service routines, if the client passes through the name pipeline
After the response for receiving the Windows service routines, call function WriteFile write requests into the name pipeline are close
The information of key.The client call function ReadFile come read from pipeline the Windows service routines send it is close
Key, the key can be encryptions.The key is decrypted to obtain original value for the client, so as to realize to institute
State the decryption of file.
The present embodiment realizes that the data between the Windows services and the client are led to by building name pipeline
Letter, the procotol of bottom is shielded, it is achieved thereby that directly logical between the Windows service routines and the client
Letter, but it is not limited to such a communication mode.
Fig. 3 is file deciphering device structure chart provided in an embodiment of the present invention, as shown in figure 3, including the first receiving unit
11 and second transmitting element 12, wherein:First receiving unit 11 is used for the information for the request key for receiving client transmission,
The key is located in Windows service routines, and the Windows service routines and the client are by naming pipeline to carry out
Communication;First transmitting element 12 is used to the key being sent to the client, so that the client is according to
The file encrypted in the client is decrypted key.
Specifically, the client refers to the program that local service is provided for client.The key is defeated in decipherment algorithm
The parameter entered, for the key of decryption.The Windows service routines are used for the key for preserving decryption.The file can be figure
Piece file, script file, animation file, audio files etc.., it is necessary to which first the file is encrypted before being decrypted.
The public key that RSA Algorithm can be used to generate is encrypted to the file process, and the private key generated using RSA Algorithm is entered to the file
Row decryption, but it is not limited to such a AES.The Windows service routines receive the request key that the client is sent
Information, the key are located in the Windows service routines.The Windows service routines and the client pass through life
Name pipeline is communicated.But it is not limited only to this mode.The receiving unit 11 receives the request key that the client is sent
After information, the transmitting element 12 is sent to the client after the key is encrypted, so that the client is according to
The file encrypted in the client is decrypted key.
The key of decryption is put into Windows service routines by the present embodiment, the Windows service routines and the visitor
Family end software is packed together is installed to client.When starting the client software, start the Windows services.Client
Hold software that the file is decrypted when needing to use the file.The key of decryption is by way of interprocess communication
Obtained from the Windows service routines, so as to more reconditely hide the key of decryption, strengthen the effect of encryption.
Fig. 4 is file deciphering device structure chart provided in an embodiment of the present invention, as shown in figure 4, including the second transmitting element
21st, the second receiving unit 22 and decryption unit 23, wherein:Second transmitting element 21 is used to send the information for asking key
Windows service routines are given, the key is located in the Windows service routines, the Windows service routines and client
End is by naming pipeline to be communicated;Second receiving unit 22 is used to receive the close of the Windows service routines transmission
Key;The decryption unit 23 is used to the file encrypted in the client be decrypted according to the key.
Specifically, using the Windows service routines as service end.The key is the ginseng inputted in decipherment algorithm
Number, for the key of decryption.The Windows service routines are used for the key for preserving decryption.The file can be picture file,
Script file, animation file, audio files etc..The decryption can call corresponding function to be decrypted according to AES.
The key is located in the Windows service routines.The Windows service routines and the client are by naming pipeline
Communicated.But it is not limited only to this mode.Software in the client is when needing to use the file, if the file is
It is encrypted, then second transmitting element 21 sends the information of request key to the Windows service routines.Described second connects
After receiving the key that unit 22 receives the encryption that the Windows service routines are sent, the decryption unit 23 is literary by the resource
Part reads internal memory, and the decryption function of calling is passed to using the key as parameter, so as to realize the solution to the resource
It is close.
The key of decryption is put into Windows service routines by the present embodiment, the Windows service routines and the visitor
Family end software is packed together is installed to client.When starting the client software, start the Windows service routines.
The file is decrypted when needing to use the file for client software.The key of decryption passes through interprocess communication
Mode obtains from the Windows service routines, so as to more reconditely hide the key of decryption, strengthens the effect of encryption.
Finally, the present processes are only preferable embodiment, are not intended to limit the scope of the present invention.It is all
Within the spirit and principles in the present invention, any modification, equivalent substitution and improvements made etc., the protection of the present invention should be included in
Within the scope of.