A method and apparatus for locating an error in an encryption
By generating an exception during the encryption process and creating a reverse decryption process, the problem of difficulty in locating encryption errors in existing technologies is solved, achieving the effect of quickly locating encryption errors and improving troubleshooting efficiency.
Patent Information
- Application Number
- CN202110014800.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-06
- Publication Date
- 2026-01-09
- Estimated Expiration
- 2041-01-06
AI Technical Summary
In existing technologies, when data cannot be decrypted after encryption or when the final encryption/decryption result is incorrect, it is difficult to quickly locate the cause of the error.
An exception is generated during the encryption process to create a reverse decryption process. The ciphertext data is then decrypted in the reverse decryption process, and the decrypted data is compared with the data to be encrypted. If they do not match, it is determined that there is an error in the encryption process of the current layer.
It can quickly locate the error level during the encryption process, avoiding the need for error investigation after the entire encryption process is completed, thus improving the investigation efficiency of developers.
Smart Images

Figure CN114722406B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the computer technical field, and in particular to an encryption method and device for locating errors. BACKGROUND
[0002] For a security program developer, various encryption algorithms are often used to encrypt and decrypt data, however, the encryption algorithm internally is a series of multi-layered loop iteration calculations. For example, some data security algorithms use a variety of encryption and decryption algorithms to be stacked to increase the complexity of the algorithm. Similar to the process of peeling an onion, one encryption or decryption algorithm is stacked at a time, and thus the plaintext data is ultimately obtained.
[0003] At present, if the encrypted data cannot be decrypted or the final encryption and decryption result is incorrect, it is difficult to locate the error cause. Therefore, there is an urgent need for an encryption method capable of quickly locating encryption errors. SUMMARY
[0004] In view of the above problems, the present application provides an encryption method and device for locating errors, which can locate the encryption level during the encryption process, avoiding error troubleshooting after completing the entire encryption process, thereby shortening the troubleshooting time for the developer and improving the efficiency.
[0005] In a first aspect, the present application provides the following technical solutions through an embodiment:
[0006] An encryption method for locating errors, comprising:
[0007] Based on preset encryption information, encrypting the data to be encrypted in a pre-created forward encryption process to obtain ciphertext data and generate an exception; creating a reverse decryption process based on the encryption information and the exception, and decrypting the ciphertext data in the reverse decryption process to obtain decrypted data; determining whether the decrypted data matches the data to be encrypted; if yes, performing a next layer of encryption operation on the ciphertext data; and if no, determining that the current layer of encryption process has an error based on the exception.
[0008] Optionally, the generating an exception comprises:
[0009] Based on a preset EncryptException class inherited system exception class, obtaining a constructor; wherein the constructor is used to expand the exception; and generating an exception based on the encryption information and the constructor.
[0010] Optionally, the parameters of the constructor include: error type, encryption key, data size of the data to be encrypted, and encryption level.
[0011] Optionally, the reverse decryption process is created based on the encryption information and the exception, and the ciphertext data is decrypted in the reverse decryption process to obtain decrypted data, including:
[0012] The memory mapping file is obtained based on the ciphertext data and the encryption information, wherein the reverse decryption process and the forward encryption process perform data communication based on the memory mapping file, the reverse decryption process is created based on the exception, and the ciphertext data is decrypted in the reverse decryption process based on the memory mapping file to obtain decrypted data.
[0013] Optionally, the reverse decryption process is created based on the exception, including:
[0014] The Void Notify() interface is called based on the exception, and the system function CreateProcess is called based on the Void Notify() interface to create the reverse decryption process, wherein the reverse decryption process and the forward encryption process perform data communication based on the memory mapping file, and the ciphertext data is decrypted in the reverse decryption process based on the memory mapping file to obtain decrypted data.
[0015] Optionally, the error of the encryption process of the current layer is determined based on the exception, including:
[0016] The key length is obtained based on the exception captured by the catch function, and when the key length does not match the first preset length, the error type is determined to be a key length error.
[0017] Optionally, the error of the encryption process of the current layer is determined based on the exception, including:
[0018] The data packet length of the data to be encrypted is obtained based on the exception captured by the catch function, and when the data packet length does not match the second preset length, the error type is determined to be a data length error.
[0019] In a second aspect, based on the same inventive concept, an embodiment of the present application provides the following technical scheme:
[0020] An encryption device for locating errors, comprising:
[0021] The forward operation module is configured to encrypt the data to be encrypted in a pre-created forward encryption process based on preset encryption information, obtain ciphertext data and generate an exception; the reverse operation module is configured to create a reverse decryption process based on the encryption information and the exception, and decrypt the ciphertext data in the reverse decryption process to obtain decrypted data; the first judging module is configured to judge whether the decrypted data matches the data to be encrypted; the second judging module is configured to perform a next layer of encryption operation on the ciphertext data when the decrypted data matches the data to be encrypted; and the third judging module is configured to determine that an error exists in the encryption process of the current layer based on the exception when the decrypted data does not match the data to be encrypted.
[0022] Optionally, the forward operation module is specifically configured to:
[0023] An exception class of an EncryptException class inheritance system is obtained based on preset encryption information, and a constructor is obtained; the constructor is configured to extend to an exception; and an exception is generated based on the encryption information and the constructor.
[0024] In a third aspect, based on the same inventive concept, an embodiment of the present application provides the following technical solutions:
[0025] A positioning error encryption device includes a processor and a memory coupled to the processor, and the memory stores instructions that, when executed by the processor, cause the positioning error encryption device to perform the steps of any of the methods of the first aspect.
[0026] The positioning error encryption method and device provided in the embodiments of the present application include the following steps: encrypting data to be encrypted in a pre-created forward encryption process based on preset encryption information, obtaining ciphertext data and generating an exception; then, creating a reverse decryption process based on the encryption information and the exception, and decrypting the ciphertext data in the reverse decryption process to obtain decrypted data; then, judging whether the decrypted data matches the data to be encrypted; if yes, performing a next layer of encryption operation on the ciphertext data; and if no, determining that an error exists in the encryption process of the current layer based on the exception. In the embodiments of the present application, reverse operation is performed on the ciphertext data obtained by encryption of the layer after the encryption operation is completed, and the encryption process and the decryption process of the reverse operation are respectively performed in two different processes and do not affect each other, so that even if a serious error occurs, the program will not crash; at the same time, the layer of encryption can be located, and error troubleshooting is avoided after the entire encryption process is completed, thereby shortening the troubleshooting time of the developer and improving the efficiency.
[0027] The above description is only a summary of the technical solutions of the present application. In order to enable a more thorough understanding of the technical means of the present application, the contents of the description can be implemented, and in order to enable the above and other purposes, features and advantages of the present application to be more apparent and easy to understand, the specific embodiments of the present application are described below. BRIEF DESCRIPTION OF DRAWINGS
[0028] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are some embodiments of the present application, and those skilled in the art can also obtain other drawings according to these drawings without creative labor. In the drawings:
[0029] Figure 1 A flow chart of an encryption method for locating errors provided by the first embodiment of the present application is shown;
[0030] Figure 2 A structural schematic diagram of an encryption device for locating errors provided by the second embodiment of the present application is shown. DETAILED DESCRIPTION
[0031] The exemplary embodiments of the present disclosure will be described in detail with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided so that the present disclosure can be more thoroughly understood and the scope of the present disclosure can be accurately conveyed to those skilled in the art.
[0032] First embodiment
[0033] Please refer to Figure 1 , Figure 1 A flow chart of an encryption method for locating errors provided by the first embodiment of the present application is shown, which includes:
[0034] Step S10: Based on the preset encryption information, the encryption of the to-be-encrypted data is performed in the pre-created forward encryption process, and ciphertext data is obtained and an exception is generated.
[0035] In step S10, the to-be-encrypted data can be data that has not been encrypted, or data that has been encrypted one or more times. The preset encryption information can include: the algorithm name of the encryption algorithm used, the algorithm key of the encryption, the encryption level of the current encryption, the size of the data to be encrypted, etc. When the to-be-encrypted data is encrypted, the corresponding encryption algorithm will be used in the forward encryption process to encrypt the to-be-encrypted data.
[0036] For example, in an encryption process, TEA (Tiy Ecrytio Algorithm) and AES (Advanced Encryption Standard) encryption operations are required for the original data. The encryption process has two levels, the first level is TEA encryption, and the second level is AES encryption. The data to be encrypted can be the data after TEA encryption, in which case step S10 is performed to encrypt the data to be encrypted at the second level; or the data before TEA encryption, in which case step S10 is performed to encrypt the data to be encrypted at the second level.
[0037] In step S10, the next encryption process is paused after the execution is completed, and the operation of the reverse decryption process is performed to ensure that each level of error encryption operation can be located. The general exception is to tell the caller that a problem has occurred and the desired result cannot be obtained, and the program does not crash. However, in the present embodiment, the advantage of generating an exception is that the exception can be captured and the next operation can be selected based on the error condition. In the present embodiment, when an error occurs in the encryption and decryption task, it is convenient to locate the cause.
[0038] Specifically, the process of generating an exception is as follows: based on the preset EncryptException class inheritance system exception class, a constructor is obtained; the constructor is used to extend the exception; based on the encryption information and the constructor, an exception is generated. The parameters of the constructor include at least: error type, encryption key, data size of data to be encrypted, and encryption level.
[0039] Step S20: creating a reverse decryption process based on the encryption information and the exception, and decrypting the ciphertext data in the reverse decryption process to obtain decrypted data.
[0040] In step S20, the ciphertext data is operated in reverse to verify whether the ciphertext data corresponds to the data to be encrypted. In the present embodiment, a shared file data of process communication is designed to ensure that the forward encryption process and the reverse decryption process can share data. Specifically, in the forward encryption process, the encryption and decryption direction of the data and the number of iteration loops, the name of the encryption and decryption algorithm used in each layer, and the encryption and decryption key are known. The header of the memory shared file of the forward encryption process stores the layer data of the entire data to be encrypted or decrypted, the name of the encryption and decryption algorithm of each layer, the encryption and decryption key of each layer, and the data to be encrypted / original data. The subsequent created process can query the data from the memory shared file. Specifically, the sub-steps of step S20 are as follows:
[0041] Step S21: obtaining a memory mapping file based on the ciphertext data and the encryption information; wherein the reverse decryption process and the forward encryption process communicate data based on the memory mapping file;
[0042] Step S22: creating the reverse decryption process based on the exception;
[0043] In step S22, the process is implemented as follows: based on the exception, a Void Notify() interface is called; then, based on the Void Notify() interface, a system function CreateProcess is called to create the reverse decryption process; wherein the reverse decryption process and the forward encryption process communicate data based on the memory mapping file; finally, in the reverse decryption process, the ciphertext data is decrypted based on the memory mapping file to obtain the decrypted data.
[0044] Step S23: decrypting the ciphertext data in the reverse decryption process based on the memory mapping file to obtain the decrypted data.
[0045] For the various exceptions in the present embodiment, the functions of data communication based on encryption and decryption, data calculation and verification are required. Therefore, in the present embodiment, these common functions are abstractly designed into the basic framework of the exception, based on which various types of exceptions can be conveniently extended, so that more encryption algorithms and more scenarios can be met. That is, the constructor is designed into the constructor, the reverse decryption process is created by calling the Void Notify() interface through inheritance of the exception, and the decrypted data is obtained based on the memory mapping file.
[0046] The code implementation of the reverse decryption process through the constructor is as follows:
[0047] First, a class EncryptException is written and inherited from the exception class std::exception of the system, specifically: class EncryptException: public std::exception{.
[0048] Then, the parameters required by the exception class must be designed, and the corresponding construction parameters must be provided in the constructor of the class.
[0049] explicit EncryptException(std::string const&msg, std::string const&sharename, std::string const&name, char*data, int size, std::string const&key, int level); wherein the mandatory construction parameters include: msg, an error type used to describe the error; sharename, a channel used to pass data for encryption or decryption communication with the other party; name, a name used to represent the encryption or decryption algorithm; data, the current data to be encrypted or the ciphertext data; size, the corresponding data size; key, the secret key used for data encryption or decryption; level, the number of rounds identifying the current algorithm loop iteration, the level of encryption or decryption. It should be noted that the embodiment described herein is for error positioning in the encryption process.
[0050] Next, a function needs to be written to notify another program in an exception to synchronize the corresponding data encryption or decryption operation. In the embodiment, a Void Notify() interface is used to create a process to complete the corresponding operation, which is used to notify the other process to complete the corresponding encryption or decryption operation. If there is no reverse decryption process at this time, a reverse decryption process is immediately created. For example, a system function CreateProcess can be called to create a process, and a memory file mapping is created to complete the data communication operation between the forward encryption process and the reverse decryption process, and a semaphore is used to synchronize the two processes. In this process, the ciphertext data and / or encryption information is sent to the other process through the memory mapping file for operation. When creating the process, the relevant parameters are packaged together through the lpCommandLine parameter of the CreateProcess function to pass the data to the corresponding reverse decryption process and parse it to obtain all the parameters of the reverse process. The data passed includes at least: sharename, name, data, size, key, and level.
[0051] Through step S20, the forward operation and the reverse operation can be respectively performed in two processes, and real-time verification is performed on each level of the encryption process, so that the error of the encryption and decryption algorithm at which level can be located. Based on this, the encryption secret key and the decryption secret key can also be adjusted at the same time to verify whether the loop of each level is correct. Instead of using a log to print the error reason, some problems can be avoided which cause the program to crash and make the log unusable; the log cannot also feedback the current error situation in time, and the developer cannot adjust the function code in real time based on the log error.
[0052] In the present application, the multi-process is realized through step S20 to solve the error problem. The throwing of each error will first collect the current data, and create a process to complete the corresponding reverse operation, and return the result, so as to continue to verify the correctness of the current data. The multi-process mode can not interfere with the program, and will not cause performance consumption to the current process. If other processes have problems, it will not cause errors to the current process, avoiding program crash.
[0053] Step S30: determining whether the decrypted data matches the data to be encrypted.
[0054] In step S30, by performing the reverse decryption operation on the ciphertext data, it can be determined whether the corresponding data to be encrypted can be obtained again, that is, whether the decrypted data matches the data to be encrypted. For example, the original data to be encrypted needs to be encrypted by TEA and AES encryption of two levels. Then the reverse operation is to decrypt from AES, and then TEA decryption, and compare whether the original data is consistent at each decryption level to realize detection of each round, so the earliest level at which the decrypted data and the data to be encrypted cannot match can be determined, so that it can be queried which level and which algorithm have errors, and then the error type is determined to determine the error type causing the encryption and decryption error.
[0055] Step S40: if yes, performing next level encryption operation on the ciphertext data.
[0056] In step S40, if the decrypted data and the data to be encrypted are matched, it means that the encryption of this layer is correct. Otherwise, step S50 is executed.
[0057] Step S50: if no, determining that the encryption process of the current layer has an error based on the exception.
[0058] In step S50, if the decrypted data and the data to be encrypted are not matched, it means that the encryption of this layer has an error. Specifically, the key length of the encryption can be obtained based on the catch function to capture the exception; when the key length does not match the first preset length, the error type is determined to be key length error. In addition, the data packet length of the data to be encrypted can also be obtained based on the catch function to capture the exception; when the data packet length does not match the second preset length, the error type is determined to be data length error.
[0059] In addition, in the embodiment, the key length error is the most frequently occurred problem in the encryption process. The judgment of the key length error is performed first, so that the error determination time can be saved and the efficiency is improved. Therefore, the judgment of the key length error type can be performed first. Specifically, the key length of the encryption is acquired first. The key length is stored in the memory mapping file and can be read at any time. Then, it is judged whether the key length is the first preset length. If the key length is not the first preset length, it is determined that the error type is the key length error.
[0060] For example, the key length of some encryption and decryption algorithms must be 32 bytes, the key length of some encryption and decryption algorithms must be 4 bytes, the key length of some encryption and decryption algorithms must be 128 bytes, and the like. That is, the first preset length can be set to 4 bytes, 32 bytes, 128 bytes according to the actually used encryption algorithm. Therefore, a specific error type can be designed for the error type of the unmatched key length. In the embodiment, the following code implementation process is provided. First, the ClassKeyErrorException: public EncryptException is inherited from the EncryptException exception inheritance framework, so that the functions provided by the EncryptException are possessed. Then, the core parameters filled in the constructor of the ClassKeyErrorException include the name of the current encryption and decryption algorithm, the current encryption and decryption level, the current key data and key length data, and the actually required key length data. This error type is used to mark all the error types of the unmatched key length. Next, after the current data is acquired, the interface Notify() provided by the base class is called immediately to create an opposite decryption process. The decryption process performs the reverse operation and the exception judgment to restore the error reason. Meanwhile, the current key length exception is thrown to the current program.
[0061] If the key length exception does not exist, the judgment of the error type of the data length error of the data to be encrypted is continued. Specifically, it is judged whether the data packet length of the data to be encrypted is the second preset length. When the data packet length is not the second preset length, it is determined that the error type is the data length error. Specifically, the encryption and decryption data type of the data is not matched, which usually occurs when the data needs to be encrypted or decrypted. The data to be encrypted is usually grouped and the length of each group of data is fixed.
[0062] For example, when using TEA encryption algorithm, the data length is at least 4 bytes or its integer multiple; if it is less than 4 bytes or not a multiple of 4 bytes, it will cause encryption error. Therefore, the second preset length can be 4 bytes or an integer multiple of 4 bytes. Further, the same as the previously written exception framework is inherited, thereby having the function of creating reverse operation process, and specifically a class Class DataErrorException: public EncryptException can be written, which mainly includes the name of encryption algorithm, the current level, the current encryption key, the data length of the data to be encrypted, and the actual data length required by the current encryption algorithm and other parameter information. After encryption, the interface Notify() provided by the base class is also called to create an opposite reverse decryption process, which will perform reverse operation to determine whether there is data length error to restore the error cause. At the same time, the reverse decryption process will throw the current exception to the current program.
[0063] In the embodiment, the key length error is the most frequent problem in the encryption process. First, the key length error is judged, which can save the error determination time and improve the efficiency. Therefore, preferably, the key error can be judged first, and then the data length error is judged. Alternatively, two or more kinds of judgments can be performed at the same time, which is not limited.
[0064] Through the construction of constructor and inheritance, the customized exception of special case can be realized, and the corresponding error type can be realized to clearly inform the error type for each error, so that the error type and error cause can be known when error occurs, and the corresponding solution is generated based on the error type.
[0065] In addition, in the present embodiment, the advantage based on the exception is that the exception can be captured and how to proceed to the next step can be selected based on the error condition. Generally, the exception is to tell the caller that a problem has occurred and the desired result cannot be obtained when an error occurs, without crashing the program. In the present embodiment, in order to facilitate positioning of the cause when an error occurs in the encryption and decryption task, the encryption level is positioned in the following manner: a correct exception is thrown in each round of encryption and decryption operation, the purpose of the exception is to inform the program that the encryption and decryption has reached that level, and then the step of creating a reverse decryption process based on the previously designed component function is performed to verify the correctness of the current round of data. Thus, it is determined in advance whether the encryption operation of the current round is correct, and if it is correct, the next round can be performed, and if it is not correct, it is positioned that the program encryption error exists in the current round. Then, based on the recorded last round data, secret key and other data, only the error reason of the current round can be excluded, thereby narrowing the error checking range. The code implementation of throwing a correct exception through inheritance is as follows: Class NoErrorException: public EncryptException, the main purpose of the exception is to inform the program that it has reached that round, and a process is created to perform reverse operation to verify whether the current executed data is correct.
[0066] Through the programming of the above three types of exceptions, other types of exceptions can be easily extended and customized, so that a type of error can be programmed for each specific encryption error, to ensure that the level of the exception and the type of the exception can be accurately positioned.
[0067] In the present embodiment, the exception thrown needs to be captured when implemented, so as to obtain the type of the exception after judgment; based on the exception condition, the error type can be captured, and based on the length of the encryption and decryption data in the execution process or the length of the secret key, the corresponding customized exception type is thrown, and the corresponding function is executed in the exception type to locate the error cause. At the same time, based on the design idea of the present embodiment, the error condition can be fed back in time when the program has an error, and the program will not crash and can continue to execute. Specifically, the code principle of the entire implementation process of the present embodiment and the implementation manner of the exception capture are as follows:
[0068] The main program performs operations at the beginning of data encryption and decryption, first writes the related encryption algorithm, encryption key and encryption level of the specific encryption data to be encrypted in the memory mapping file, which can be executed based on the function Try{}. Then, the specific data encryption and decryption operation of the specific data to be encrypted is started, and the specific interface is EncryptOrDecrptData(). Through this interface, the specific multi-round iteration data decryption task execution operation can also be completed; then, the system provides an exception capture catch function for abnormal conditions, for example, a most initial exception code can be represented as: catch(const std::exception&e){}. In addition, different exception types are also provided in this embodiment, so a set of exception handling needs to be written based on different exception types. Based on the setting of this embodiment, when the encryption and decryption task is wrong, the exception to be handled is relatively fixed processing steps, so a scheme is needed to write an exception handling that can solve every different customized exception situation. Therefore, the following skills are used in this embodiment:
[0069] The information of the specific exception type is obtained by const std::type_info & type = typeid(e), and the name of the exception type, such as NoErrorException, DataErrorException, etc., can be obtained. Since all the customized exception types are based on std::exception and come through multi-layer inheritance, the RTTI (Run-Time Type Identification) technology can be used to obtain the name of each specific exception type. The std::exception type can be captured through the unified system layer exception, and the specific exception type, including NoErrorException, DataErrorException, and other customized exception types, can be obtained through the type conversion from the base class to the subclass. Then, the exception type captured can know which layer the error in the iteration encryption and decryption process occurs and the reason for the error, and based on the created reverse decryption process, the error reason can be located. In each round of data encryption and decryption operation, the legality of the current data is checked, and for each error condition, the defined exception type is created and the corresponding exception type is thrown. When the exception type is created, the current environment data is created, and the environment data is all the parameters required by the previously defined base class EncryptException. The corresponding exception parameters are filled in by throw NoErrorException. In this embodiment, a correct exception is thrown for each round of encryption and decryption operation. Of course, the encryption process is mainly described in this embodiment, and based on the same understanding, it can also be applied to the decryption process. Finally, the error positioning of the entire encryption process is realized.
[0070] In summary, the encryption method for positioning errors provided in this embodiment includes: based on the preset encryption information, encrypting the data to be encrypted in the pre-created forward encryption process to obtain ciphertext data; then, based on the encryption information, decrypting the ciphertext data in the pre-created reverse decryption process to obtain decrypted data; then, judging whether the decrypted data matches the data to be encrypted; if yes, performing the next layer of encryption operation on the ciphertext data; if no, determining that there is an error in the current layer of encryption process. In this embodiment, the ciphertext data obtained by the encryption operation of this layer is subjected to reverse operation after the encryption operation is completed, and the encryption process and the decryption process of the reverse operation are respectively performed in two different processes and do not affect each other, so that even if a serious error occurs, the program will not crash; at the same time, the encryption level can be located, and the error troubleshooting is avoided after the entire encryption process is completed, thereby shortening the troubleshooting time of the developer and improving the efficiency.
[0071] Second embodiment
[0072] Referring to Figure 2 Based on the same inventive concept, the second embodiment of the present application provides a positioning error encryption device 300. Figure 2 The structural diagram of the positioning error encryption device 300 is shown. The positioning error encryption device 300 comprises:
[0073] A forward operation module 301 is configured to encrypt the data to be encrypted in a pre-created forward encryption process based on preset encryption information, obtain ciphertext data and generate an exception; an inverse operation module 302 is configured to create an inverse decryption process based on the encryption information and the exception, and decrypt the ciphertext data in the inverse decryption process to obtain decrypted data; a first judgment module 303 is configured to judge whether the decrypted data matches the data to be encrypted; a second judgment module 304 is configured to perform a next layer of encryption operation on the ciphertext data when the decrypted data matches the data to be encrypted; and a third judgment module 305 is configured to determine that there is an error in the encryption process of the current layer based on the exception when the decrypted data does not match the data to be encrypted.
[0074] As an optional implementation, the forward operation module 301 is specifically configured to:
[0075] obtain a constructor based on a preset exception class of an EncryptException class inheritance system; wherein the constructor is used to extend the exception; and generate an exception based on the encryption information and the constructor.
[0076] As an optional implementation, the parameters of the constructor include an error type, an encryption key, a data size of the data to be encrypted, and an encryption level.
[0077] As an optional implementation, the inverse operation module 302 is specifically configured to:
[0078] obtain a memory mapping file based on the ciphertext data and the encryption information; wherein the inverse decryption process and the forward encryption process perform data communication based on the memory mapping file; create the inverse decryption process based on the exception; and decrypt the ciphertext data in the inverse decryption process based on the memory mapping file to obtain decrypted data.
[0079] As an optional implementation, the inverse operation module 302 is specifically configured to:
[0080] Based on the exception, a Void Notify() interface is called; based on the Void Notify() interface, a system function CreateProcess is called to create the reverse decryption process; wherein the reverse decryption process and the forward encryption process communicate data based on the memory mapping file; in the reverse decryption process, the ciphertext data is decrypted based on the memory mapping file to obtain decrypted data.
[0081] As an optional implementation, the third determining module 305 is specifically configured to:
[0082] Based on the exception captured by the catch function, the encrypted key length is obtained; when the key length does not match the first preset length, it is determined that the error type is a key length error.
[0083] As an optional implementation, the third determining module 305 is specifically configured to:
[0084] Based on the exception captured by the catch function, the data packet length of the data to be encrypted is obtained; when the data packet length does not match the second preset length, it is determined that the error type is a data length error.
[0085] It should be noted that the encryption device for locating errors provided by the embodiment of the application has the same specific implementation and technical effects as the foregoing method embodiments, and for brief description, the part not mentioned in the device embodiment can refer to the corresponding content in the foregoing method embodiments.
[0086] Third embodiment
[0087] Based on the same inventive concept, the third embodiment of the application further provides an encryption device for locating errors, comprising a processor and a memory, the memory is coupled to the processor, the memory stores instructions, when the instructions are executed by the processor, the encryption device for locating errors executes the steps of any one method in the foregoing first embodiment.
[0088] It should be noted that in the encryption device for locating errors provided by the embodiment of the application, the specific implementation of each step in the encryption device for locating errors and the technical effects generated are the same as those of the foregoing method embodiments, and for brief description, the part not mentioned in the embodiment can refer to the corresponding content in the foregoing method embodiments.
[0089] The term "and / or", occurring in this text, is merely used to describe associated objects, and means that three cases can exist, for example, A and / or B can mean that A exists alone, A and B exist together, and B exists alone. In addition, the character " / " in this text generally means that the associated objects before and after are in an "or" relationship; the word "comprising" does not exclude the existence of elements or steps not listed in the claims. The word "one" or "an" before an element does not exclude the existence of multiple such elements. The present application can be implemented by means of hardware including a plurality of different elements and by means of a suitably programmed computer. In a unit claim enumerating several means, several of these means can be embodied by one and the same item of hardware. The use of the words "first", "second", and "third", etc. does not indicate any order. These words can be interpreted as names.
[0090] Those skilled in the art should understand that embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage, etc.) containing computer usable program code.
[0091] The present application is described with reference to the flowcharts and / or block diagrams of the methods, apparatus (systems), and computer program products according to embodiments of the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, as well as combinations of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing apparatus to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing apparatus produce an apparatus that implements the functions specified in the flowcharts and / or block diagrams. Figure 1 The functions specified in a flow or multiple flows and / or blocks Figure 1 The functions specified in a flow or multiple flows and / or blocks
[0092] These computer program instructions can also be stored in a computer-readable memory that can direct the computer or other programmable data processing apparatus to work in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including instruction means that implement the functions specified in the flowcharts and / or block diagrams. Figure 1 The functions specified in a flow or multiple flows and / or blocks Figure 1 The functions specified in a flow or multiple flows and / or blocks
[0093] These computer program instructions can also be loaded into a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks. Figure 1 one or more flowcharts and / or blocks Figure 1 one or more flowcharts and / or blocks
[0094] Although preferred embodiments of the application have been described herein, it will be apparent to those skilled in the art that various modifications can be made within the scope of the application without departing from the spirit of the application. Accordingly, it is intended that all such possible modifications be included within the scope of the application as described in the following claims. In compliance with the statute, the application has been described in language more or less specific to structural
[0095] Obviously, numerous modifications and variations of the present application are possible in light of the above teachings. It is therefore to be understood that within the scope of the appended claims and their equivalents, the application can be practiced otherwise than as specifically described.
Claims
1. A method of locating an error in an encryption, characterized by, The application comprises the following steps: encrypting the data to be encrypted in a pre-created forward encryption process based on preset encryption information, obtaining ciphertext data and generating an exception; creating a reverse decryption process based on the encryption information and the exception, and decrypting the ciphertext data in the reverse decryption process to obtain decrypted data; judging whether the decrypted data matches the data to be encrypted; if yes, performing a next layer of encryption operation on the ciphertext data; if no, determining that the encryption process of the current layer has an error based on the exception; wherein the data to be encrypted is data that has not been encrypted or data that has been encrypted for one or more layers; the preset encryption information comprises an algorithm name of an encryption algorithm to be used, an encryption algorithm key, a current encryption layer, and a size of data to be encrypted, and when the data to be encrypted is encrypted, a corresponding encryption algorithm is used to encrypt the data to be encrypted in the forward encryption process.
2. The method of claim 1, wherein, The step of generating an exception comprises the following steps: obtaining a constructor based on an exception class of an EncryptException class inheritance system, wherein the constructor is used for expansion to an exception; generating an exception based on the encryption information and the constructor.
3. The method of claim 2, wherein, The parameters of the constructor comprise an error type, an encryption key, a data size of data to be encrypted, and an encryption layer.
4. The method of claim 2, wherein, The step of creating a reverse decryption process based on the encryption information and the exception, and decrypting the ciphertext data in the reverse decryption process to obtain decrypted data comprises the following steps: obtaining a memory mapping file based on the ciphertext data and the encryption information, wherein data communication is performed between the reverse decryption process and the forward encryption process based on the memory mapping file; creating the reverse decryption process based on the exception; decrypting the ciphertext data in the reverse decryption process based on the memory mapping file to obtain decrypted data.
5. The method of claim 4, wherein, The step of creating the reverse decryption process based on the exception comprises the following steps: calling a Void Notify() interface based on the exception; creating the reverse decryption process by calling a system function CreateProcess based on the Void Notify() interface, wherein data communication is performed between the reverse decryption process and the forward encryption process based on the memory mapping file; decrypting the ciphertext data in the reverse decryption process based on the memory mapping file to obtain decrypted data.
6. The method of claim 1, wherein, The step of determining that the encryption process of the current layer has an error based on the exception comprises the following steps: obtaining a key length of encryption based on the exception captured by a catch function; when the key length does not match a first preset length, determining that an error type is a key length error.
7. The method of claim 1, wherein, The step of determining that the encryption process of the current layer has an error based on the exception comprises the following steps: obtaining a data packet length of the data to be encrypted based on the exception captured by a catch function; when the data packet length does not match a second preset length, determining that an error type is a data length error.
8. A positioning error encryption device, characterized by, The application comprises the following steps: A forward operation module is configured to encrypt the data to be encrypted in a pre-created forward encryption process based on preset encryption information, to obtain ciphertext data and generate an exception; A reverse operation module is configured to create a reverse decryption process based on the encryption information and the exception, and to decrypt the ciphertext data in the reverse decryption process to obtain decrypted data; A first judgment module is configured to judge whether the decrypted data matches the data to be encrypted; A second judgment module is configured to perform a next layer of encryption operation on the ciphertext data when the decrypted data matches the data to be encrypted; A third judgment module is configured to determine that an error exists in the encryption process of a current layer based on the exception when the decrypted data does not match the data to be encrypted. The data to be encrypted is data that has not been encrypted or data that has been encrypted for one or more layers. The preset encryption information includes an algorithm name of an encryption algorithm used, an algorithm key of encryption, an encryption layer of current encryption, and a size of data to be encrypted. When the data to be encrypted is encrypted, a corresponding encryption algorithm is used to encrypt the data to be encrypted in the forward encryption process.
9. The apparatus of claim 8, wherein, The forward operation module is specifically configured to: obtain a constructor based on an exception class of an EncryptException class inheritance system, wherein the constructor is used to expand an exception; and generate an exception based on the encryption information and the constructor.
10. A positioning error encryption device, characterized by A positioning error encryption device includes a processor and a memory coupled to the processor. The memory stores instructions that, when executed by the processor, cause the positioning error encryption device to perform the steps of the method of any one of claims 1-7.
Citation Information
Patent Citations
Application program testing method and device, computer equipment and storage medium
CN108347361A
Android App reinforcing method based on file self-modification
CN110502874A