MyBatis-based method, system and equipment for automatically signing data and preventing tampering

By integrating the signature verification module with annotations and the national cryptographic SM2 algorithm into the MyBatis framework with the interceptor, the problems of insufficient complexity and security in data anti-tampering in existing technologies are solved, realizing efficient and flexible data signature anti-tampering, and adapting to various MyBatis use cases.

CN118916853APending Publication Date: 2024-11-08ZHUHAI MAIYUE INFORMATION TECH
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411151660.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-20
Publication Date
2024-11-08

AI Technical Summary

Technical Problem

Existing data anti-tampering solutions based on the MyBatis framework are complex, impact system performance, and lack sufficient security. They also lack flexibility and scalability, and the anti-tampering logic is mixed with business logic, making them unable to effectively resist advanced attacks.

Method used

By dynamically configuring fields through annotations and combining them with the MyBatis framework, the signature verification module using the national cryptographic SM2 algorithm is seamlessly integrated with the MyBatis interceptor to achieve automatic data signing and anti-tampering, supporting dynamic data protection and multiple encryption algorithms, and separating the anti-tampering logic from the business logic.

Benefits of technology

It achieves efficient, secure, and flexible data signature anti-tampering that integrates seamlessly with the MyBatis framework, supports dynamic data protection, improves data security and scalability, and simplifies the development process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916853A_ABST
    Figure CN118916853A_ABST
Patent Text Reader

Abstract

The invention provides a method, a system and equipment for automatically signing data and preventing tampering based on MyBatis. The method comprises the following steps: step S1, configuring a use annotation; s2, configuring a signature algorithm and an interceptor, and loading a configuration class, an automatic scanning configuration and a MyBatis interceptor configuration; s3, starting the application program; s4, the annotation is scanned, a MyBatis interceptor is loaded, and a signature algorithm is loaded; step S5, data operation: when a query or persistence operation exists, the MyBatis interceptor intercepts the operation; if yes, automatic signature verification is carried out according to a verification result, the verification result is returned, and different processing is carried out according to the verification result and specific business conditions; by annotating a dynamic configuration field and seamlessly integrating the dynamic configuration field with a MyBatis framework, a data automatic signature verification tamper-proof function is realized.
Need to check novelty before this filing date? Find Prior Art

Description

[Technical field]

[0001] The present invention relates to the field of enterprise-level application technology, and in particular to a method, system and device for automatically signing and tamper-proofing data based on MyBatis. [Background technology]

[0002] With the rapid development of Internet technology, data security issues have received increasing attention. In various systems, preventing data from being maliciously tampered with is the key to ensuring the normal operation of the system and data integrity. Especially for some systems involving sensitive information, such as government agencies, finance, medical and other important fields, the need for data confidentiality and anti-tampering is more urgent.

[0003] Traditional data integrity protection methods usually use cryptographic methods such as digital signatures and message authentication codes, but these technical solutions have certain defects, such as low performance, complex implementation, and poor scalability. MyBatis, as a widely used persistence layer framework, is a common framework for Spring to implement data addition, deletion, modification, and query. It supports customized SQL, stored procedures, and advanced mappings; MyBatis avoids almost all JDBC codes and manual parameter settings and result sets; MyBatis can use simple XML or annotations to configure and map native information, and map interfaces and Java POJOs (Plain Ordinary Java Objects) into records in the database; therefore, MyBatis plays an important role in Java enterprise application development.

[0004] In addition, Spring Boot is a new framework based on Spring 4.0, which is designed to simplify the initial construction and development process of new Spring applications. The Spring Boot framework uses a specific way to configure, so that developers no longer need to define boilerplate configurations. In this way, Spring Boot is committed to becoming a leader in the booming field of rapid application development. Therefore, it is a common practice for Spring Boot projects to implement data addition, deletion, modification and query based on the MyBatis framework, but there is currently no more common or flexible way to automatically prevent tampering of data based on the MyBatis framework. At present, when implementing tamper-proofing at the application level, the tamper-proofing logic is usually mixed with the business logic, resulting in poor code maintainability and scalability; some simple tamper-proofing solutions based on hash functions (such as MD5, SHA-1, etc.) have low security and cannot resist advanced attack methods, and signatures may be bypassed or forged; some existing annotation-based tamper-proofing solutions lack support for dynamically generated data objects, and the scope of protection is limited. In addition, the signature algorithm selection and performance optimization space of existing solutions also need to be improved.

[0005] Moreover, in the interceptor, MyBatis provides an interceptor mechanism that allows custom interception operations to be implemented during the execution of mapped statements. Through the interceptor, some special processing can be performed before or after the execution of SQL statements, such as data encryption and decryption, performance monitoring, etc.

[0006] At the same time, National Cryptography refers to the general term for commercial cryptographic algorithms and cryptographic standards formulated and issued by the national cryptography administration agency. National cryptography algorithms mainly include SM2 elliptic curve cryptography algorithm, SM3 cryptographic hash algorithm, SM4 block cipher algorithm, etc. Among them, SM4 block cipher algorithm is a symmetric key encryption algorithm in the national cryptography algorithm. It is a block cipher algorithm with independent intellectual property rights in my country, also known as the national block data encryption standard. The SM4 algorithm has high security and key flexibility, and can be used for data encryption in the fields of e-government, e-commerce, etc., as well as encryption in the fields of wireless communications.

[0007] In summary, although traditional cryptographic schemes can be used to protect data integrity, due to the particularity of the MyBatis framework, the implementation and integration of traditional cryptographic schemes are often complex and may affect system performance. Therefore, there is an urgent need to explore a simpler and more efficient data integrity protection solution to adapt to the usage scenarios of MyBatis. [Summary of the invention]

[0008] The present invention provides a method, system and device for automatically signing and tamper-proofing data based on MyBatis. The method realizes the function of automatically verifying and tamper-proofing data by annotating dynamic configuration fields and seamlessly integrating with the MyBatis framework, provides a more flexible, secure and scalable data signature, and is seamlessly integrated with the MyBatis framework to adapt to various MyBatis usage scenarios.

[0009] In order to achieve the above-mentioned purpose, in the first aspect, the technical solution adopted by the present invention to solve the technical problem is as follows:

[0010] A method for automatically signing and tamper-proofing data based on MyBatis, comprising the following steps:

[0011] Step S1, configure the usage annotation

[0012] Developers use the @RowSignature annotation to mark the entity class, and use the properties signFields and ignoreFields to set multiple fields that need to be signed or multiple fields that do not need to be signed;

[0013] Step S2: Configure signature algorithm and interceptor

[0014] Load configuration class, automatic scanning configuration and MyBatis interceptor configuration;

[0015] Step S3, start the application, and the above configurations will be loaded in sequence;

[0016] Step S4, scan annotations, load MyBatis interceptor and load signature algorithm;

[0017] Step S5: Data operation

[0018] Step S5.1, for persistence operations, the MyBatis interceptor will pre-process, encrypt the fields that need to be signed through the signature verification module, generate a signature, and store it in the database;

[0019] Step S5.2, when there is a query or persistence operation, the MyBatis interceptor will intercept the operation;

[0020] Step S5.3, for the query operation, the MyBatis interceptor will pre-process and first check whether the signature matches;

[0021] Step S5.4, if there is no match, directly return the verification result and end;

[0022] Step S6, if it matches, the signature is automatically verified according to the verification result, and the national secret SM2 algorithm is used by default, and the interface containing multiple encryption algorithms is flexibly implemented. The MyBatis interceptor processes the data result set, updates or queries whether the verification data has been tampered with, and performs different processing according to the specific business situation;

[0023] Step S7, return the verification result and end.

[0024] In the second aspect, another technical solution adopted by the present invention to solve the technical problem is as follows:

[0025] A system for automatically signing and tamper-proofing data based on MyBatis, the system comprising:

[0026] Annotation definition module, which allows developers to use @RowSignature to mark custom annotations for fields that need to be tamper-proof, and supports dynamic setting of protection for multiple database fields;

[0027] MyBatis interceptor module is integrated with the MyBatis framework, customizing the implementation of Interceptor to intercept the execution process of MyBatis, and then persisting the operation to automatically sign and save the unsigned data in the database. Subsequent updates or queries verify whether the data has been tampered with;

[0028] The signature verification module uses the national encryption SM2 algorithm as the signature algorithm and flexibly implements interfaces containing multiple encryption algorithms;

[0029] The configuration module provides configuration signature algorithm, loads interceptors, parses configuration and provides configuration information to the encryption and decryption modules, and starts interceptor monitoring.

[0030] Furthermore, the multiple encryption algorithms include the national encryption SM2 algorithm, ECC algorithm, MD5 algorithm or a custom encryption module.

[0031] In the third aspect, another technical solution adopted by the present invention to solve the technical problem is as follows:

[0032] A computer device comprising:

[0033] At least one processor, at least one memory and computer program instructions stored in the memory, the computer program instructions include the above-mentioned system for automatically signing and preventing tampering of data based on MyBatis, and the processor is configured to be suitable for executing the above-mentioned method for automatically signing and preventing tampering of data based on MyBatis according to the system for automatically signing and preventing tampering of data based on MyBatis stored in the memory.

[0034] Advantages of the present invention:

[0035] 1. Completely separate the anti-tampering logic from the business logic, implement the function directly through annotations, seamlessly integrate with the MyBatis framework, and encapsulate it inside the framework. Developers only need to focus on the business logic without repeated implementation;

[0036] 2. Higher security. It adopts the national secret SM2 digital signature algorithm based on elliptic curve cryptography, which is more secure and reliable, can effectively defend against various known cryptographic attacks, and greatly improves the security of data tampering;

[0037] 3. Support dynamic data protection, support automatic signature protection for dynamically generated data objects, expand the protection scope, and enable more data to be protected against tampering;

[0038] 4. It is easy to use, highly scalable and flexible. Developers only need to add corresponding annotations to the data objects that need to be protected, without having to write complex signature codes, which greatly simplifies the development process. Parameters such as signature algorithms and signature data ranges can be customized according to actual needs, which enhances the scalability and applicability of the solution.

[0039] [Instruction manual with attached drawings]

[0040] Figure 1 This is a flow chart of automatic signature tamper-proofing in the present invention;

[0041] Figure 2 This is a system diagram for automatic signature tamper-proofing in the present invention. [Specific implementation method]

[0042] The present invention will be further described below with reference to specific embodiments.

[0043] The features and exemplary embodiments of various aspects of the present invention will be described in detail below. In order to make the purpose, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings and Examples. It should be understood that the specific embodiments described herein are only configured to explain the present invention and are not configured to limit the present invention. For those skilled in the art, the present invention can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present invention by illustrating examples of the present invention.

[0044] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "includes..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0045] In the first embodiment of the present invention, a method for automatically signing and tamper-proofing data based on MyBatis is provided. Figure 1 As shown, the following steps are included:

[0046] Step S1, configure the usage annotation

[0047] Developers use the @RowSignature annotation to mark the entity class, and use the properties signFields and ignoreFields to set multiple fields that need to be signed or multiple fields that do not need to be signed;

[0048] Step S2: Configure signature algorithm and interceptor

[0049] Load configuration class, automatic scanning configuration and MyBatis interceptor configuration;

[0050] Step S3, start the application, and the above configurations will be loaded in sequence;

[0051] Step S4, scan annotations, load MyBatis interceptor and load signature algorithm;

[0052] Step S5: Data operation

[0053] Step S5.1, for persistence operations, the MyBatis interceptor will pre-process, encrypt the fields that need to be signed through the signature verification module, generate a signature, and store it in the database;

[0054] Step S5.2, when there is a query or persistence operation, the MyBatis interceptor will intercept the operation;

[0055] Step S5.3, for the query operation, the MyBatis interceptor will pre-process and first check whether the signature matches;

[0056] Step S5.4, if there is no match, directly return the verification result and end;

[0057] Step S6, if it matches, the signature is automatically verified according to the verification result, and the national secret SM2 algorithm is used by default, and the interface containing multiple encryption algorithms is flexibly implemented. The MyBatis interceptor processes the data result set, updates or queries whether the verification data has been tampered with, and performs different processing according to the specific business situation;

[0058] Step S7, return the verification result and end.

[0059] In the second embodiment of the present invention, a system for automatically signing and tamper-proofing data based on MyBatis is provided. Figure 2 As shown, the system includes:

[0060] Annotation definition module 1 is used by developers to use @RowSignature to mark custom annotations for fields that need to be tamper-proof. It supports dynamic setting of protection for multiple database fields. Developers only need to use the annotation on the corresponding entity class.

[0061] MyBatis interceptor module 2 is integrated with the MyBatis framework, customizing the implementation of Interceptor to intercept the execution process of MyBatis, and then persisting the operation to automatically sign and save the unsigned data in the database. Subsequent updates or queries verify whether the data has been tampered with to ensure the correctness and security of the data;

[0062] Signature verification module 3 adopts the national secret SM2 algorithm as the signature algorithm, and flexibly implements interfaces containing multiple encryption algorithms; multiple encryption algorithms include the national secret SM2 algorithm, ECC algorithm, MD5 algorithm or custom encryption module, etc.; using the national secret SM2 algorithm as the signature algorithm has higher cryptographic security strength, stronger resistance to quantum computer attacks, better anti-collision performance, and complies with national password management regulations, etc., making the signature safer and more reliable.

[0063] Configuration module 4 provides configuration signature algorithm, loads interceptor, parses configuration and provides configuration information to encryption and decryption module, and starts interceptor monitoring.

[0064] In a third embodiment of the present invention, a computer device is provided, comprising: at least one processor, at least one memory, and computer program instructions stored in the memory, the computer program instructions including the above-mentioned system for automatic signature and tamper-proofing of data based on MyBatis, and the processor is configured to be suitable for executing the above-mentioned method for automatic signature and tamper-proofing of data based on MyBatis according to the system for automatic signature and tamper-proofing of data based on MyBatis stored in the memory.

[0065] In the above embodiments, through the MyBatis framework, data tamper-proofing is combined with the framework, which can realize functions more flexibly and reduce business logic coupling; by annotating dynamic configuration fields and seamlessly integrating with the MyBatis framework, data automatic signature verification and tamper-proofing functions are realized, providing a more flexible, secure and scalable data signature.

[0066] In this embodiment, an annotation-driven method and seamless integration with MyBatis are adopted to combine data tamper-proofing with the MyBatis framework, and the tamper-proofing logic is completely separated from the business logic, which completely solves the problem of coupling between data signature and business logic, and implements functions directly through annotations; more signature fields can be dynamically expanded, with higher security, support for dynamic data protection, and provide a more flexible, secure and scalable data signature algorithm, which has highly scalable and flexible implementation functions, reduces business logic coupling, and can adapt to various usage scenarios of MyBatis.

[0067] It should also be noted that the exemplary embodiments mentioned in the present invention describe some methods or systems based on a series of steps or devices. However, the present invention is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiments, or in a different order from the embodiments, or several steps can be performed simultaneously.

[0068] The above-described embodiments are only preferred embodiments of the present invention and are not intended to limit the scope of implementation of the present invention. Except for the cases listed in the specific embodiments, all equivalent changes made according to the methods and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for automatically signing and tamper-proofing data based on MyBatis, characterized in that: The following steps are involved: Step S1, configure the usage annotation Developers use the @RowSignature annotation to mark the entity class, and use the properties signFields and ignoreFields to set multiple fields that need to be signed or multiple fields that do not need to be signed; Step S2: Configure signature algorithm and interceptor Load configuration class, automatic scanning configuration and MyBatis interceptor configuration; Step S3, start the application, and the above configurations will be loaded in sequence; Step S4, scan annotations, load MyBatis interceptor and load signature algorithm; Step S5: Data Operation Step S5.1, for persistence operations, the MyBatis interceptor will pre-process, encrypt the fields that need to be signed through the signature verification module, generate a signature, and store it in the database; Step S5.2, when there is a query or persistence operation, the MyBatis interceptor will intercept the operation; Step S5.3, for the query operation, the MyBatis interceptor will pre-process and first check whether the signature matches; Step S5.4, if there is no match, directly return the verification result and end; Step S6, if it matches, the signature is automatically verified according to the verification result, and the national secret SM2 algorithm is used by default, and the interface containing multiple encryption algorithms is flexibly implemented. The MyBatis interceptor processes the data result set, updates or queries whether the verification data has been tampered with, and performs different processing according to the specific business situation; Step S7, return the verification result and end.

2. A system for automatically signing and tamper-proofing data based on MyBatis, characterized in that: The system includes: Annotation definition module, which allows developers to use @RowSignature to mark custom annotations for fields that need to be tamper-proof, and supports dynamic setting of protection for multiple database fields; MyBatis interceptor module is integrated with the MyBatis framework, customizing the implementation of Interceptor to intercept the execution process of MyBatis, and then persisting the operation to automatically sign and save the unsigned data in the database. Subsequent updates or queries verify whether the data has been tampered with; The signature verification module uses the national encryption SM2 algorithm as the signature algorithm and flexibly implements interfaces containing multiple encryption algorithms; The configuration module provides configuration signature algorithm, loads interceptors, parses configuration and provides configuration information to the encryption and decryption modules, and starts interceptor monitoring.

3. According to a MyBatis-based system for automatically signing and tamper-proofing data according to claim 2, it is characterized in that: The multiple encryption algorithms include the national encryption SM2 algorithm, ECC algorithm, MD5 algorithm or a custom encryption module.

4. A computer device, characterized in that: include: At least one processor, at least one memory and computer program instructions stored in the memory, the computer program instructions including a system for automatically signing and tampering-proofing data based on MyBatis as described in claim 2, the processor being configured to be suitable for executing a method for automatically signing and tampering-proofing data based on MyBatis as described in claim 1 according to a system for automatically signing and tampering-proofing data based on MyBatis stored in the memory.

Citation Information

Cited By

  • Parameter tamper-proofing method and system, electronic equipment and storage medium

    CN120354461A

  • Parameter tamper-proofing method, system, electronic device and storage medium

    CN120354461B