Domestic password encryption storage method and device
By defining interceptors and annotations in the MyBatis application system, combined with the Guoxin SM2 algorithm, the encryption and decryption processing of sensitive information is realized, solving the problem of sensitive information storage security and improving data storage security.
Patent Information
- Application Number
- CN202411075127.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-07
- Publication Date
- 2024-12-06
AI Technical Summary
In the MyBatis application system, it is difficult for the existing technology to realize domestic password encrypted storage of sensitive information without increasing the development workload to improve data security.
By defining the ParameterHandler and ResultHandler interceptor of MyBatis, using the encryption annotation @Encrypt and decrypt annotation @Decrypt, interfaces and abstract classes are defined to realize encryption and decryption processing based on national secret SM2, and combining MybatisInterceptorHolder and abstract processor classes to realize data encryption and Decryption to improve the security of the data storage stage.
Without increasing the development workload, domestic cryptographic algorithm encrypted storage of sensitive information is realized, improving the security of the data storage stage.
Smart Images

Figure CN119089515A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the Mybatis field, and specifically provides a domestic password encryption storage method and device. Background Art
[0002] MyBatis is an excellent persistence layer framework. It is widely used due to its high flexibility, lightweight, rich mapping configuration, and good performance. Interceptor is an extension mechanism provided by MyBatis. MyBatis provides four types of interceptors: Executor, StatementHandler, ParameterHandler, and ResultHandler.
[0003] Without modifying the core code, you can implement custom function extensions by intercepting specific method calls, such as adding logging, performance monitoring, data processing, etc. Under the premise of increasing emphasis on data privacy and security, the ciphertext storage of some sensitive information (mobile phone numbers, etc.) is becoming more and more important. Therefore, in the development of Mybatis-based application systems, it is urgent to implement ciphertext storage of sensitive information and improve data security without increasing the development workload. Summary of the invention
[0004] The present invention aims at solving the above-mentioned deficiencies of the prior art and provides a domestically produced password encryption storage method with strong practicality.
[0005] A further technical task of the present invention is to provide a domestically produced password encryption storage device that is reasonably designed, safe and applicable.
[0006] The technical solution adopted by the present invention to solve its technical problem is:
[0007] A domestic password encryption storage method has the following steps:
[0008] S1, ParameterHandler and ResultHandler interceptors based on Mybatsis;
[0009] S2. Define the encryption annotation @Encrypt and the decryption annotation @Decrypt;
[0010] S3. Define the interface MybatisProcessor and process method;
[0011] S4. Define MybatisInterceptorHolder to collect and store data;
[0012] S5. Define two abstract classes: AbstractResultProcessor and AbstractParamProcessor;
[0013] S6. Customize the encryption class DecryptProcessor to inherit AbstractParamProcessor.
[0014] Furthermore, in step S1, two types of interceptors, ParamInterceptor and ResultInterceptor, are defined, wherein ParamInterceptor is responsible for data encryption in the data storage phase, and ResultInterceptor is responsible for data decryption in the data query phase.
[0015] Furthermore, the encryption annotation @Encrypt and the decryption annotation @Decrypt are defined to act on the properties of Java Bean and are used to define situations where properties need to be encrypted and decrypted. Both the encryption and decryption annotations have a type attribute for developers to customize domestic password types.
[0016] Furthermore, in step S3, the interface MybatisProcessor, the process processing method, the custom attribute annotation type and the corresponding processing implementation and priority are defined.
[0017] Furthermore, in step S4, MybatisInterceptorHolder is defined to collect and store information. When the Java Bean is loaded, the information on whether there are encryption and decryption attributes and attribute details is stored in the memory. Subsequent Java Bean processing does not need to use the emission scanning attribute information.
[0018] Furthermore, in step S5, two abstract classes AbstractResultProcessor and AbstractParamProcessor are defined, both of which inherit MybatisProcessor and implement the getType() method, where AbstractResultProcessor corresponds to ResultInterceptor and AbstractParamProcessor corresponds to ParamInterceptor.
[0019] Furthermore, in step S6, the encryption class DecryptProcessor is customized to inherit AbstractParamProcessor to implement data encryption based on the national encryption SM2;
[0020] Define the decryption class EncryptProcessor to inherit AbstractResultProcessor to implement data decryption based on SM2.
[0021] A domestic password encryption storage device, comprising: at least one memory and at least one processor;
[0022] The at least one memory is used to store a machine-readable program;
[0023] The at least one processor is used to call the machine-readable program to execute a domestic password encryption storage method.
[0024] Compared with the prior art, the domestic password encryption storage method and device of the present invention has the following outstanding beneficial effects:
[0025] The present invention realizes encrypted storage of sensitive information using a domestic cryptographic algorithm without increasing the development workload, thereby improving the security of the data storage stage. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0027] Attached Figure 1 It is a flow chart of a domestic password encryption storage method. DETAILED DESCRIPTION
[0028] In order to enable those skilled in the art to better understand the solution of the present invention, the present invention is further described in detail below in conjunction with specific implementation methods. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0029] A best embodiment is given below:
[0030] like Figure 1 The domestic password encryption storage method in this embodiment has the following steps:
[0031] S1, ParameterHandler and ResultHandler interceptors based on Mybatsis;
[0032] Define two types of interceptors: ParamInterceptor and ResultInterceptor. ParamInterceptor is responsible for data encryption during the data storage phase, while ResultInterceptor is responsible for data decryption during the data query phase.
[0033] S2. Define the encryption annotation @Encrypt and the decryption annotation @Decrypt;
[0034] Acts on the properties of Java Bean, used to define which properties need to be encrypted and decrypted. Encryption and decryption annotations all have a type attribute, which can be used by developers to customize domestic password types.
[0035] S3. Define the interface MybatisProcessor and process method;
[0036] Define the interface MybatisProcessor, process processing method, custom attribute annotation type and corresponding processing implementation and priority, etc.
[0037] S4. Define MybatisInterceptorHolder to collect and store data;
[0038] Which specific implementation classes of interceptors are in the system, and which Java Beans have custom annotations added. When the JavaBean is processed and loaded, information such as whether there are encryption and decryption attributes and attribute details is stored in the memory. Subsequent processing of the Java Bean does not need to use emission scanning attribute information, thereby improving processing efficiency.
[0039] S5. Define two abstract classes: AbstractResultProcessor and AbstractParamProcessor;
[0040] Both inherit MybatisProcessor and implement the getType() method, where AbstractResultProcessor corresponds to ResultInterceptor and AbstractParamProcessor corresponds to ParamInterceptor.
[0041] S6. Customize the encryption class DecryptProcessor to inherit AbstractParamProcessor;
[0042] The custom encryption class DecryptProcessor inherits AbstractParamProcessor to implement data encryption based on the national secret SM2. The decryption class EncryptProcessor is defined to inherit AbstractResultProcessor to implement data decryption based on SM2.
[0043] Based on the above method, a domestic password encryption storage device in this embodiment includes: at least one memory and at least one processor;
[0044] The at least one memory is used to store a machine-readable program;
[0045] The at least one processor is used to call the machine-readable program to execute a domestic password encryption storage method.
[0046] The above-mentioned specific implementations are only specific cases of the present invention. The patent protection scope of the present invention includes but is not limited to the above-mentioned specific implementations. Any technical solutions that comply with the claims of the present invention and any appropriate changes or substitutions made by ordinary technicians in the relevant technical field shall fall within the patent protection scope of the present invention.
[0047] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A domestic password encryption storage method, characterized in that: The steps are as follows: S1, ParameterHandler and ResultHandler interceptors based on Mybatsis; S2. Define the encryption annotation @Encrypt and the decryption annotation @Decrypt; S3. Define the interface MybatisProcessor and process method; S4. Define MybatisInterceptorHolder to collect and store data; S5. Define two abstract classes: AbstractResultProcessor and AbstractParamProcessor; S6. Customize the encryption class DecryptProcessor to inherit AbstractParamProcessor.
2. A domestic password encryption storage method according to claim 1, characterized in that: In step S1, two types of interceptors, ParamInterceptor and ResultInterceptor, are defined, wherein ParamInterceptor is responsible for data encryption in the data storage phase, and ResultInterceptor is responsible for data decryption in the data query phase.
3. A domestic password encryption storage method according to claim 2, characterized in that: In step S2, the encryption annotation @Encrypt and the decryption annotation @Decrypt are defined to act on the properties of the Java Bean and are used to define situations where properties need to be encrypted and decrypted. Both the encryption and decryption annotations have a type attribute for developers to customize domestic password types.
4. A domestic password encryption storage method according to claim 3, characterized in that: In step S3, define the interface MybatisProcessor, the process processing method, the custom attribute annotation type and the corresponding processing implementation and priority.
5. A domestic password encryption storage method according to claim 4, characterized in that: In step S4, MybatisInterceptorHolder is defined to collect and store information. When the Java Bean is loaded, the information about whether there are encryption and decryption attributes and attribute details is stored in the memory. Subsequent Java Bean processing does not need to use the emission scanning attribute information.
6. A domestic password encryption storage method according to claim 5, characterized in that: In step S5, two abstract classes AbstractResultProcessor and AbstractParamProcessor are defined, both of which inherit MybatisProcessor and implement the getType() method, where AbstractResultProcessor corresponds to ResultInterceptor and AbstractParamProcessor corresponds to ParamInterceptor.
7. A domestic password encryption storage method according to claim 6, characterized in that: In step S6, the encryption class DecryptProcessor is customized to inherit AbstractParamProcessor to implement data encryption based on the national encryption SM2; Define the decryption class EncryptProcessor to inherit AbstractResultProcessor to implement data decryption based on SM2.
8. A domestic password encryption storage device, characterized in that: include: at least one memory and at least one processor; The at least one memory is used to store a machine-readable program; The at least one processor is configured to call the machine-readable program to execute the method according to any one of claims 1 to 7.
