A cross-platform database encryption compatibility method and apparatus

By acquiring compatibility configuration templates and numerical formatting processing, encryption and decryption interoperability between the Java application layer and the database layer is achieved, solving the problem of incompatibility between encryption and decryption results, ensuring the accessibility of data assets and business continuity, and is suitable for financial and scientific computing scenarios.

CN123122885APending Publication Date: 2026-11-17SHANSHU TECH (BEIJING) CO LTD +3
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611216601.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2025-12-22
Filing Date
2026-08-12
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

In enterprise-level information systems, encryption and decryption operations between the Java application layer and the database layer are incompatible due to differences in details such as initialization vector (IV), key encoding method, data block padding mode, and final binary data formatting, resulting in a lack of systematic solutions.

Method used

By acquiring a compatibility configuration template, including encryption algorithms, working modes, padding schemes, initialization vectors, and data encoding formats, normalized keys and data are generated. Combined with numerical formatting post-processing, seamless encryption and decryption interoperability between the Java application layer and the database layer is achieved.

Benefits of technology

It solves the problem of incompatibility between encryption and decryption results, ensuring the accessibility of enterprise historical data assets and business continuity, and avoiding business interruptions caused by data format issues. It is particularly suitable for financial and scientific computing scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123122885A_ABST
    Figure CN123122885A_ABST
Patent Text Reader

Abstract

This invention provides a cross-platform database encryption compatibility method and apparatus, relating to the technical field of database encryption compatibility technology. The method includes: obtaining a preset compatibility configuration template; performing encryption and decryption operations on an encrypted data string based on the compatibility configuration template to generate target data; and performing formatting preprocessing on the target data when the target data is a numeric string. This invention solves the problem of incompatibility between encryption / decryption results and the database, thereby improving the compatibility of encryption / decryption results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of database encryption compatibility technology, and more specifically, to a cross-platform database encryption compatibility method and apparatus. Background Technology

[0002] In enterprise-level information systems, especially in industries with extremely high data confidentiality requirements such as finance and telecommunications, database-level encryption technologies are commonly used to protect sensitive data. For example, Oracle databases provide built-in encryption function packages such as DBMS_CRYPTO, allowing developers to directly encrypt data in specific fields within the database before storing it.

[0003] With the evolution of technology architecture, many newly developed business systems are built using modern programming languages ​​such as Java. These applications need to interact with legacy databases containing historical encrypted data. In this scenario, a key technical challenge is ensuring that the encryption and decryption operations performed by the Java application layer are fully compatible with the encryption functions on the database side.

[0004] However, even when both parties use the same core encryption algorithm (such as AES), differences in implementation details such as the generation strategy of the initialization vector (IV), the encoding method of the key, the padding mode of the data block, and the formatting of the final binary data often result in Java applications being unable to decrypt encrypted databases, and vice versa. Therefore, existing technologies lack a systematic solution to address the encryption incompatibility between the application layer and the database layer. Summary of the Invention

[0005] This invention provides a cross-platform database encryption compatibility method and apparatus to at least solve the problem of incompatibility between encryption / decryption results and databases in related technologies.

[0006] According to an embodiment of the present invention, a cross-platform database encryption compatibility method is provided, comprising:

[0007] Obtain a preset compatibility configuration template, which includes an encryption algorithm, working mode, padding scheme, initialization vector, and data encoding format for matching the encryption function of the target database;

[0008] Receive encrypted data strings and initial key strings;

[0009] Based on one or more key processing rules defined in the compatibility configuration template, the initial key string is processed to generate a normalized key;

[0010] Based on the algorithm parameters defined in the compatibility configuration template and the normalized key, a decryption operation is performed on the encrypted data string to generate target data, wherein the encrypted data string is the ciphertext data to be decrypted and the target data is the decrypted plaintext data;

[0011] When the target data is a numeric string, a formatting preprocessing is performed on the target data. The formatting preprocessing includes: detecting whether the numeric string starts with a preset decimal point; if so, a preset padding zero character is placed before the beginning of the numeric string.

[0012] In one exemplary embodiment, the data encoding format in the compatibility configuration template is a hexadecimal encoding format;

[0013] Before performing encryption / decryption operations on the encrypted data string, the method further includes: converting the encrypted data string in hexadecimal encoding format into an encrypted byte array;

[0014] or,

[0015] After performing encryption and decryption operations on the encrypted data string, the method further includes: when performing encryption operations, converting the target data from a byte array into a hexadecimal encoded string.

[0016] In one exemplary embodiment, processing the initial key string to generate a normalized key includes:

[0017] Perform independent key processing on the key to generate a fixed-length key byte array.

[0018] In one exemplary embodiment, the target database is a relational database, and the target database stores data in encryption using its built-in encryption function package; the encryption parameters defined in the compatibility configuration template are consistent with the encryption parameters used by the built-in encryption function package.

[0019] In one exemplary embodiment, the method further includes:

[0020] Obtain context data associated with the encrypted data string and a pre-stored integrity token, wherein the context data is the value of one or more unencrypted fields stored in the same data record as the encrypted data string;

[0021] Based on the target data and the context data, a verification hash is generated;

[0022] The verification hash is compared with the integrity token to determine the integrity of the target data.

[0023] In one exemplary embodiment, generating the verification hash includes:

[0024] According to preset concatenation rules, each piece of data in the target data and the context data is concatenated into a standardized verification string;

[0025] Using a preset hash algorithm and verification key, a hash message authentication code is calculated on the normalized verification string to generate the verification hash.

[0026] In one exemplary embodiment, the method further includes:

[0027] Monitor the execution process of the encryption and decryption operations to capture encryption and decryption anomalies;

[0028] If a predefined encryption / decryption exception is captured, the source identifier and timestamp associated with that exception are recorded.

[0029] Based on the records, the frequency of encryption / decryption anomalies of the preset type from the same source identifier within a unit time window is statistically analyzed.

[0030] When the frequency of occurrence exceeds a preset safety threshold, a safety response is triggered.

[0031] According to another embodiment of the present invention, a cross-platform database encryption compatible device is provided, comprising:

[0032] The configuration acquisition module is used to acquire a preset compatibility configuration template, which includes an encryption algorithm, working mode, padding scheme, initialization vector and data encoding format for matching the encryption function of a target database.

[0033] The string acquisition module is used to receive encrypted data strings and initial key strings;

[0034] The standardization module is used to process the initial key string based on one or more key processing rules defined in the compatibility configuration template to generate a standardized key;

[0035] The decryption module is used to perform encryption and decryption operations on the encrypted data string based on the algorithm parameters defined in the compatibility configuration template and the normalized key to generate target data, wherein the encrypted data string is ciphertext data to be decrypted or plaintext data to be encrypted, and the target data is decrypted plaintext data or encrypted ciphertext data.

[0036] The format preprocessing module is used to perform format preprocessing on the target data when the encryption / decryption operation is a decryption operation and the target data is a numeric string. The format preprocessing includes: detecting whether the numeric string starts with a preset decimal point; if so, placing a preset padding zero character before the beginning of the numeric string.

[0037] According to yet another embodiment of the present invention, a computer-readable storage medium is also provided, wherein a computer program is stored therein, wherein the computer program is configured to perform the steps in any of the above method embodiments when executed.

[0038] According to yet another embodiment of the present invention, an electronic device is also provided, including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in any of the above method embodiments.

[0039] This invention completely solves the data interoperability problem between new Java applications and legacy database encryption systems by standardizing parameters, ensuring the accessibility of enterprise historical data assets and business continuity. Therefore, it can solve the problem of incompatibility between encryption / decryption results and databases, thereby improving the compatibility of encryption / decryption results. Attached Figure Description

[0040] Figure 1 This is a flowchart of a cross-platform database encryption compatibility method according to an embodiment of the present invention;

[0041] Figure 2 This is a structural block diagram of a cross-platform database encryption compatibility device according to an embodiment of the present invention. Detailed Implementation

[0042] The technical solutions of the embodiments of this application will be described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.

[0043] In the following description, the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined with "first," "second," etc., may explicitly or implicitly include one or more of that feature. In the description of this application, unless otherwise stated, "a plurality of" means two or more.

[0044] Furthermore, in this application, directional terms such as "upper," "lower," "left," and "right" may be defined relative to the orientation of the components shown in the accompanying drawings. It should be understood that these directional terms can be relative concepts, used for relative description and clarification, and may change accordingly depending on the orientation of the components in the accompanying drawings.

[0045] In this application, unless otherwise expressly specified and limited, the term "connection" should be interpreted broadly. For example, "connection" can be a fixed connection, a detachable connection, or an integral part; it can be a direct connection or an indirect connection through an intermediate medium. Furthermore, the term "coupled" can refer to an electrical connection that enables signal transmission.

[0046] As used herein, “about,” “approximately,” or “approximately” includes the stated value and the average value within an acceptable range of deviation from the given value, wherein the acceptable range of deviation is determined by a person skilled in the art taking into account the measurement under discussion and the error associated with the measurement of the given quantity (i.e., the limitations of the measurement system).

[0047] Example 1

[0048] This embodiment provides a cross-platform database encryption compatibility method. In a specific implementation, this method employs a strictly defined set of parameterized configurations fully aligned with the target database encryption implementation, combined with a targeted numerical formatting post-processing mechanism. This enables seamless and reliable data encryption and decryption interoperability between the application layer program and the underlying database encryption function. This method solves the technical problem in existing technologies where subtle differences in encryption parameters (such as initialization vectors, padding modes, key encoding, etc.) lead to cross-platform compatibility failures. It also proactively avoids runtime anomalies caused by non-standard formats after decrypting numerical data, achieving the beneficial effects of ensuring business continuity and data security.

[0049] like Figure 1 As shown, the method includes the following steps:

[0050] S100: Obtain a preset compatibility configuration template, which includes an encryption algorithm, working mode, padding scheme, initialization vector, and data encoding format for matching the encryption function of the target database.

[0051] In this embodiment, a foundational environment is constructed to ensure consistency in encryption and decryption operations. This compatibility encryption parameter set (i.e., the compatibility configuration template) is not dynamically generated or negotiated at runtime, but exists as a priori, fixed configuration template. Its core purpose is to accurately reproduce the behavior of the target database's (e.g., Oracle database) internal encryption functions. This parameter set, as a whole, defines all deterministic elements in the conversion process from plaintext to ciphertext and from ciphertext to plaintext. The parameter acquisition process typically occurs during the system or service initialization phase, where a configuration acquisition module loads the parameters from an external configuration file (such as application.properties or config.xml). This design, which separates volatile configurations from program logic, improves the system's maintainability and adaptability. When needing to interface with databases with different configurations, only the configuration file needs to be modified without recompiling the code.

[0052] The compatibility configuration template is composed of several key technical elements, including encryption algorithm, working mode, padding scheme, initialization vector, data encoding format, and encryption key. The selection of each element directly affects the final generated ciphertext structure. If any element does not match the implementation of the target database, decryption will fail.

[0053] To achieve compatibility with specific databases (such as Oracle's DBMS_CRYPTO package), the encryption algorithm was determined to be the Advanced Encryption Standard (AES), the operating mode was determined to be Cipher Block Chaining (CBC), and the padding scheme was determined to be PKCS5Padding. The combination of these three, namely "AES / CBC / PKCS5Padding", constitutes a complete encryption transformation identifier, which is used to instantiate a Cipher object in the Java Encryption and Decryption Architecture (JCE).

[0054] For example, the string identifier "AES / CBC / PKCS5Padding" is parsed into three independent instructions within the encryption / decryption module. First, the "AES" instruction specifies the core algorithm for symmetric encryption. AES is a block cipher that divides plaintext data into fixed-length blocks (128 bits, or 16 bytes for AES) and performs independent encryption transformations on each block. Internally, it achieves high levels of obfuscation and diffusion through multiple rounds of byte substitution (SubBytes), row shifting (ShiftRows), column mixing (MixColumns), and round key addition (AddRoundKey), thereby ensuring encryption security. Second, the "CBC" instruction specifies the working mode of the block cipher. In CBC mode, each plaintext block is XORed with the previous ciphertext block before encryption. For the first plaintext block, since there is no previous ciphertext block, it is XORed with an initialization vector (IV). The data blocks are XORed; this chained dependency ensures that even if two plaintext blocks contain identical content, the resulting ciphertext blocks will differ depending on their position in the chain, effectively resisting pattern analysis attacks against Electronic Codebook (ECB) mode. This mode enhances cryptographic security but also introduces strict requirements for the Initialization Vector (IV), the correctness of which is crucial for successful decryption in CBC mode. Finally, the "PKCS5Padding" instruction specifies the padding scheme. Since AES processes data in 16-byte blocks, if the last plaintext data block is less than 16 bytes long, padding is required to complete a full block. PKCS5Padding is a deterministic padding scheme that calculates the number of bytes needed for padding. Then fill in the end of the data. Each byte has a value of 1. For example, if 4 bytes of padding are needed, 0x04,0x04, 0x04, 0x04 will be added to the end. During decryption, the program reads the value of the last byte and removes the corresponding number of padding bytes, thus recovering the original plaintext.

[0055] Another core element of the compatibility configuration template is the initialization vector (IV). Unlike conventional security practices that generate a random, unpredictable IV for each encryption operation, this method uses a fixed, non-randomly generated initialization vector to achieve deterministic compatibility with legacy database systems. This fixed IV value must be exactly the same as the IV value used by the encryption function on the target database side; in many legacy system implementations, for ease of management, an all-zero or other fixed-value IV may be hardcoded. Therefore, the configuration acquisition module of this method reads a preset IV string from the configuration file.

[0056] For example, let's take a closer look at the processing of the initialization vector (IV). Suppose the configuration file specifies data-sync.iv = "00000000000000000000000000000000", which is a hexadecimal string of length 32. Inside the encryption / decryption module, this string cannot be used directly because it needs to be converted into a 16-byte byte array to meet the AES block length (128 bits) requirement. This conversion process includes: first, parsing the 32-byte hexadecimal string into 16 bytes. For example, the first two characters "00" in the string are parsed as byte value 0x00, the next "00" is also parsed as 0x00, and so on; finally, a byte array byte[] ivBytes = new byte

[16] containing 16 0x00 bytes is generated; then, this ivBytes array will be used to construct the IvParameterSpec object:

[0057] IvParameterSpec ivSpec = new IvParameterSpec(ivBytes)

[0058] This ivSpec object will eventually be passed to the Cipher.init() method along with the key to initialize the encryption and decryption operations.

[0059] Next, the compatibility configuration template also includes specifications for handling encryption keys. Since the key string length provided by the user in the configuration file may be variable, and the AES algorithm requires a key length of 16 bytes (128 bits), 24 bytes (192 bits), or 32 bytes (256 bits), this method includes a key-independent key processing step to handle this mismatch. This step first converts the user-provided key string (e.g., "my-secret-key") into a raw byte array according to a specified character set (e.g., UTF-8). Then, the system creates a target key byte array of a preset length (e.g., 32 bytes for AES-256 compatibility) and fills it with zeros or other default values. Finally, a method such as System.arraycopy is used to copy the contents of the raw byte array into the target key byte array. If the original byte array is longer than the target array, only the beginning of it is copied (truncation); if it is shorter than the target array, its contents are copied, and the remainder of the target array is kept with the initial padding value (padding). This process ensures that the key used for encryption has a valid fixed length regardless of the length of the key string provided by the user.

[0060] For example, suppose the default key length is 32 bytes (256 bits), and the key provided by the user in the configuration file is data-sync.decrypt_key = "secret". First, the string "secret" is converted into a byte array originalKeyBytes using UTF-8 encoding, with the content [0x73, 0x65, 0x63, 0x72, 0x65, 0x74] and a length of 6 bytes. Next, a byte array keyBytes = new byte

[32] with a length of 32 is created. Then, an array copy operation is performed: System.arraycopy(originalKeyBytes, 0, keyBytes, 0, Math.min(originalKeyBytes.length, keyBytes.length)). Since originalKeyBytes.length(6) is less than keyBytes.length(32), this operation will copy all 6 bytes of originalKeyBytes to the first 6 positions of keyBytes. After copying, the content of keyBytes will be [0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x00, 0x00, ..., 0x00], which is the UTF-8 encoding of secret followed by 26 zero bytes. Finally, use this 32-byte keyBytes array to construct the SecretKeySpec object:

[0061] new SecretKeySpec(keyBytes, "AES")

[0062] This SecretKeySpec object is the key that ultimately participates in the encryption and decryption calculations.

[0063] Finally, the compatibility configuration template defines the data encoding format. To ensure lossless interaction with database field types used for storing binary data (such as Oracle's RAW type), this method uniformly adopts a hexadecimal encoding format. This means that after encryption, the generated binary ciphertext (byte array) is converted into a readable hexadecimal string (e.g., "1A2B3C4D...") before storage or transmission. Conversely, before decryption, the hexadecimal string ciphertext obtained from the database must first be converted back to its original binary byte array form before decryption. This unified encoding format acts as a "common language" between the application layer and the database layer, avoiding garbled characters and data corruption problems that may result from character set misunderstandings or direct transmission of binary data.

[0064] S200: Based on the compatibility configuration template, perform a decryption operation on the encrypted data string to generate target data, wherein the encrypted data string is the ciphertext data to be decrypted or the plaintext data to be encrypted, and the target data is the decrypted plaintext data or the encrypted ciphertext data.

[0065] In this embodiment, the operation process for both encryption and decryption is strictly defined by the obtained compatibility configuration template. The encryption and decryption operation module encapsulates all the details of interaction with the JCE (Java Cryptography Extension) API, providing a unified and simplified interface for upper-layer applications.

[0066] Specifically, during the decryption operation, the encrypted data string received by this module is a hexadecimal encoded string. Before entering the core decryption process, a preprocessing step must be performed first: converting the hexadecimal string into a byte array. This conversion process reads hexadecimal characters (e.g., "1A") one pair at a time and parses them into their corresponding 8-bit byte values ​​(0x1A). After the conversion is complete, the ciphertext is obtained as a byte array representation.

[0067] Next, the encryption / decryption module initializes a Cipher instance using the defined parameters; the specific process is as follows:

[0068] Instantiate a Cipher object: Create an encryption / decryption processor that follows a preset algorithm, pattern, and padding scheme by calling Cipher.getInstance("AES / CBC / PKCS5Padding").

[0069] Prepare the key and IV: Wrap the key byte array, which has been processed by the independent key, into a SecretKeySpec object, and wrap the fixed IV string into a 16-byte array into an IvParameterSpec object.

[0070] Initialize Cipher: Call the cipher.init(Cipher.DECRYPT_MODE, secretKey, ivSpec) method to set the Cipher instance to decryption mode and configure it with the correct key and initialization vector.

[0071] After the Cipher instance is initialized, its `cipher.doFinal(encryptedBytes)` method is called, taking the preprocessed ciphertext byte array as input. The `doFinal` method performs the complete decryption process, including reverse CBC chaining decryption and removal of PKCS5 padding. Upon successful execution, the method returns a byte array, which is the binary representation of the original plaintext data. Finally, for easier processing by upper-layer applications, this plaintext byte array is typically decoded into a string using a predefined character set (such as UTF-8). This string is the final target data, i.e., the decrypted plaintext.

[0072] For example, assuming the target database is Oracle, its DBMS_CRYPTO packet is encrypted using the following parameters: AES-256, CBC mode, PKCS5Padding, key "secret" (UTF-8 encoded and padded with zeros to 32 bytes), and IV is 16 zero bytes; assuming the plaintext "15.50" is encrypted and stored in the database RAW field as the hexadecimal string "A1B2C3D4E5F6A1B2C3D4E5F6A1B2C3D4" (this is just an example value).

[0073] Retrieve encrypted data string: The application reads the encrypted data string from the database, which is the hexadecimal string encryptedHex = "A1B2C3D4E5F6A1B2C3D4E5F6A1B2C3D4".

[0074] Hexadecimal to byte conversion: The encryption / decryption module calls an internal function to convert encryptedHex into a byte array encryptedBytes, the contents of which are [0xA1, 0xB2, 0xC3, 0xD4, 0xE5, 0xF6, 0xA1, 0xB2, 0xC3, 0xD4, 0xE5, 0xF6, 0xA1, 0xB2, 0xC3, 0xD4].

[0075] Parameter preparation:

[0076] Key: Following the independent key process, generate a 32-byte keyBytes from "secret" and create SecretKeySpec key = new SecretKeySpec(keyBytes, "AES").

[0077] IV: Generates 16 bytes of IVivBytes from the fixed IV string "000000000000000000000000000000" and creates IvParameterSpec ivSpec = new IvParameterSpec(ivBytes).

[0078] Cipher initialization:

[0079] Cipher cipher = Cipher.getInstance("AES / CBC / PKCS5Padding").

[0080] cipher.init(Cipher.DECRYPT_MODE, key, ivSpec).

[0081] Decryption execution:

[0082] byte[] decryptedBytes = cipher.doFinal(encryptedBytes); Assuming the decryption process is correct, the content of decryptedBytes will be the UTF-8 encoding of the string "15.50", that is, [0x31, 0x35, 0x2E, 0x35, 0x30].

[0083] Byte to string conversion:

[0084] String decryptedString = new String(decryptedBytes,StandardCharsets.UTF_8).

[0085] The final value of the target data, decryptedString, is "15.50".

[0086] The encryption process is similar to the decryption process, but in the reverse direction. The input is a plaintext string, which is first encoded into a byte array, and Cipher is initialized to Cipher.ENCRYPT_MODE. The doFinal method returns the encrypted ciphertext binary byte array. Finally, this byte array is encoded into a hexadecimal string, which serves as the final target data for writing to a RAW type field in the database.

[0087] S300: When the encryption / decryption operation is a decryption operation and the target data is a numeric string, perform a formatting preprocessing on the target data. The formatting preprocessing includes: detecting whether the numeric string starts with a preset decimal point; and if so, prepending a preset zero-padding character at the beginning of the numeric string.

[0088] In this embodiment, numerical formatting is performed to adapt to scenarios such as finance and metrology where strict requirements for numerical accuracy and format are placed. In some cases, a numerical value representing a decimal less than 1, such as 0.15, may be simplified to .15 in its encrypted plaintext after being processed by certain systems (possibly at the database end or other processing stages). After successfully decrypting such data, the target data obtained is a string .15 that begins with a decimal point symbol (.).

[0089] If such a string is not processed and is directly passed to subsequent business logic—for example, attempting to create a high-precision numeric object using `new BigDecimal(".15")`—Java's `BigDecimal` constructor will throw a `NumberFormatException`. This is because `.15` is not considered a valid, complete numeric representation. This exception can cause the current business process to be interrupted, potentially leading to serious problems such as data inconsistency or transaction failure.

[0090] To systematically address this issue, this method introduces a format preprocessing module, which is automatically invoked after successful decryption and before the data is passed to the business logic.

[0091] Conditional trigger: This module is activated only when the encryption / decryption operation is decryption and the decrypted target data (plaintext string) is identified as or expected to be a numeric string.

[0092] Formatting check: The core operation of this module is to check the first character of the received string. It uses String.startsWith(".") or similar logic to determine if the string starts with a decimal point.

[0093] Perform a fix: If the detection result is true (i.e., the string starts with a dot), the module will perform a string concatenation operation, adding a pre-defined zero-padding character "0" to the beginning of the original string. For example, if the input is .15, the output will be corrected to 0.15.

[0094] Passing results: If the string does not start with a dot (e.g., 1.15 or 15), the module does not perform any operation and simply returns the original string.

[0095] Through this simple yet effective step, this method ensures that all numeric strings decrypted from encrypted fields conform to a standard numeric representation format before entering the business layer. This fundamentally eliminates NumberFormatException caused by missing leading zeros, guaranteeing the smooth execution of business processes.

[0096] For example, the numerical formatting preprocessing flow is described. Assume that the target data decryptedString after S200 decryption is ".25".

[0097] Call the formatting module: formattedString = formatNumericString(decryptedString).

[0098] Internal check: The formatNumericString method internally executes decryptedString.startsWith("."), which returns true.

[0099] Execute the fix: The method returns "0" + decryptedString, which is "0" + ".25", resulting in "0.25".

[0100] Subsequent processing: The business logic receives the formatted string "0.25". When `new BigDecimal("0.25")` is executed, the constructor executes successfully without throwing any exceptions, and the business logic continues.

[0101] Let's assume another scenario where the decrypted target data, decryptedString, is "100.00".

[0102] Call the formatting module: formattedString = formatNumericString(decryptedString).

[0103] Internal check: The formatNumericString method internally executes decryptedString.startsWith("."), which returns false.

[0104] No repair performed: The method directly returns the original decryptedString, i.e., "100.00".

[0105] Subsequent processing: The business logic received the string "100.00", and subsequent processing proceeded normally.

[0106] By adopting the above steps and standardizing parameters, the data interoperability problem between new Java applications and legacy database encryption systems is completely solved, ensuring the accessibility of enterprise historical data assets and business continuity. Intelligent numerical formatting post-processing fundamentally avoids business process interruptions or calculation errors caused by data format issues, making it particularly suitable for financial and scientific computing scenarios with extremely high data accuracy requirements. A highly encapsulated solution is provided, eliminating the need for developers to concern themselves with underlying compatibility details; they only need to call a unified interface, greatly improving development efficiency and reducing technical barriers and maintenance costs. For the industry in scenarios where "compatibility with specific legacy systems is mandatory," a clear, reliable, and feasible technical implementation solution is provided, reducing the uncertainty of technology selection and trial and error.

[0107] Example 2

[0108] The difference from Example 1 is that, in order to defend against potential decryption attacks, this example performs decryption anomaly detection, specifically including the following steps:

[0109] S400: Perform context-aware plaintext integrity verification.

[0110] In this embodiment, after the formatting preprocessing is completed, it is necessary to verify whether the format of the decrypted target data is correct and whether its content has been tampered with. This verification process does not examine the plaintext itself in isolation, but rather places it in the data environment in which it was generated for correlation verification, hence the name "context-aware". This verification process relies on a premise: in the target database's data tables, in addition to the field storing encrypted data, there are one or more unencrypted fields that are strongly related to the encrypted data in business logic (context data), and a field specifically used to store integrity verification values ​​(integrity token).

[0111] S410: Obtain a set of context data associated with the encrypted data string and a pre-stored integrity token.

[0112] For example, a financial transaction table TRANSACTIONS might contain the following structures: TRANSACTION_ID (primary key, unencrypted), USER_ID (user ID, unencrypted), TRANSACTION_TIME (transaction time, unencrypted), ENCRYPTED_AMOUNT (encrypted transaction amount, i.e., encrypted data string), and AMOUNT_HMAC (amount integrity token, unencrypted). When an application needs to read and process the amount of a transaction, it will not only retrieve the value of the ENCRYPTED_AMOUNT field, but also the TRANSACTION_ID, USER_ID, and TRANSACTION_TIME from the same row as context data, and the value of the AMOUNT_HMAC field as a pre-stored integrity token.

[0113] For example, assuming the application is processing a transaction record with ID TXN_987654321, the database query returns the following data:

[0114] Encrypted data string (ENCRYPTED_AMOUNT): Hexadecimal string, such as "F1E2D3C4B5A6...".

[0115] Context data:

[0116] USER_ID: "USR_ABCDE" (string)

[0117] TRANSACTION_TIME: "2024-05-20T14:30:00Z" (ISO 8601 format string)

[0118] Integrity Token (AMOUNT_HMAC): A hexadecimal encoded hash value, such as "e8a4c1b0...".

[0119] S420: Generate a verification hash based on the target data and context data.

[0120] After obtaining all the necessary data, the system will execute a deterministic process to recalculate a verification hash for comparison, specifically:

[0121] S421: According to the preset concatenation rules, the target data and each data in the set of context data are concatenated into a normalized verification string (i.e., normalized key).

[0122] The concatenation rules must ensure that the results of each calculation are reproducible. In this embodiment, the rules define the order of fields, delimiters, and data formats. For example, the rules can be defined as: , where | is the separator.

[0123] For example, based on the rules above and the data obtained in the preceding steps, the system will construct the following canonical validation string: canonicalString = "USR_ABCDE|2024-05-20T14:30:00Z|150.75"

[0124] S422: Using a preset hash algorithm and verification key, calculate the Hash Message Authentication Code (HMAC) on the normalized verification string to generate the verification hash.

[0125] To prevent attackers from forging integrity tokens without knowing the key, HMAC is used instead of a simple hash function; the default hash algorithm is usually SHA-256 or a stronger algorithm; the verification key is a secure key that is independent of the data encryption key and stored on the application server.

[0126] For example, assuming the system is configured with HMAC algorithm HmacSHA256 and the verification key is verification_secret, the verification module will perform the following calculation:

[0127] computedHash=HMAC_SHA256("verification_secret","USR_ABCDE|2024-05-20T14:30:00Z|150.75")

[0128] The result of the calculation is a byte array, which is then encoded into a hexadecimal string to obtain the final verification hash.

[0129] S430: Compare the verification hash with the integrity token to determine the integrity of the target data.

[0130] The system compares the calculated verification hash (hexadecimal string) byte-by-byte with the pre-stored integrity token retrieved from the database. If they are completely equal, it proves that the decrypted plaintext data "150.75" is correct and has not been tampered with during storage, and its business context (user, time) also matches. In this case, the verification passes, and the data can safely enter the subsequent business process. If they are not equal, it indicates a serious problem. Possible reasons include: an incorrect decryption key leading to the decryption of incorrect data; the ciphertext being tampered with in the database; the context data being tampered with; or the integrity token itself being tampered with. Regardless of the reason, the system will determine that the data integrity verification has failed, immediately suspend the current operation, record a high-priority security event log, and throw an exception indicating that data integrity has been compromised to the upper-layer application.

[0131] S500: Performs security monitoring operations.

[0132] This operation is executed in parallel or sequentially with the aforementioned verification operations, serving as a continuous security monitoring layer to detect and respond to actions that may indicate a probing attack on the encryption system, particularly Padding Oracle attacks against CBC mode. These attacks are characterized by attackers sending a large number of carefully crafted, slightly different ciphertexts and gradually deducing the plaintext information by observing whether the system returns "decryption successful" or "padding error." Therefore, a large number of padding error anomalies appearing in a short period is a strong warning sign.

[0133] S510: Monitor the execution of cryptographic operations to capture cryptographic anomalies.

[0134] In a Java-based implementation, this means that in the try-catch block that executes cipher.doFinal(), javax.crypto.BadPaddingException needs to be specifically caught. When this specific type of exception is caught, it is not treated as a normal decryption failure, but as a "security signal" that requires further analysis.

[0135] S520: If a BadPaddingException is caught, the source identifier and timestamp associated with the exception are recorded, and a stateful exception frequency monitor is maintained.

[0136] The system extracts the source identifier from the context of the current request. This could be the IP address of the client that made the request or the account ID of an authenticated user. Then, it records this source identifier and the current timestamp into a stateful monitor. This monitor can be implemented as an in-memory data structure, such as a hash table, where the key is the source identifier and the value is a queue or list storing the timestamps of the most recent exceptions. The monitor operates in a sliding time window mode.

[0137] For example, the monitor's configuration parameters are as follows:

[0138] Time window: 60 seconds

[0139] Safety threshold: 10 times

[0140] When a request from IP address 203.0.113.55 causes a BadPaddingException at time T1, the monitor's data structure is updated as follows: monitorCache = { "203.0.113.55": [T1]} After handling the exception, the system checks the number of exceptions from that IP address in the past 60 seconds; at this time, it is 1, less than the threshold of 10, so no response is triggered. Subsequently, at time T2 (T2 > T1 and T2 - T1 < 60s), another request from that IP address causes the same exception. At this time, the monitor is updated to: monitorCache = { "203.0.113.55": [T1, T2]} The number of exceptions is 2, still less than the threshold, and this process continues.

[0141] S530: When the frequency of anomalies originating from the same source identifier exceeds a preset security threshold, a security response is triggered.

[0142] After each new anomaly is recorded, the monitor recalculates the total number of anomalies in the current window. If this total reaches or exceeds the security threshold, the system determines that it is likely an attack and immediately triggers the preset security response.

[0143] For example, at time T11 (T11 - T1 < 60s), a request from IP 203.0.113.55 causes the 10th BadPaddingException; at this point, the monitor detects that the exception count has reached the threshold of 10, and a security response is triggered, which may include one or more of the following actions:

[0144] High-risk alert: Sends a high-risk alert to the Security Information and Event Management (SIEM) system containing the attack source IP, target user (if any), and timestamp.

[0145] Source IP blocking: Dynamically add a rule in the application layer firewall or API gateway to temporarily (e.g., for 15 minutes) or permanently block all traffic from IP address 203.0.113.55.

[0146] Account Lockdown: If an anomaly is associated with a specific user account, the system can temporarily lock the account and notify the user that their account may be at risk.

[0147] Delayed response: In order to confuse attackers, the system may choose not to immediately return an error for subsequent requests from that IP, but instead introduce a long random delay, which greatly reduces the timeliness of the attack.

[0148] And so on, without limitation here.

[0149] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.

[0150] This embodiment also provides a cross-platform database encryption compatible device for implementing the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.

[0151] Figure 2 This is a structural block diagram of a cross-platform database encryption compatibility device according to an embodiment of the present invention, such as... Figure 2 As shown, the device includes:

[0152] The configuration acquisition module 21 is used to acquire a preset compatibility configuration template, which includes an encryption algorithm, working mode, padding scheme, initialization vector and data encoding format for matching the encryption function of a target database.

[0153] String acquisition module 22 is used to receive encrypted data strings and initial key strings;

[0154] The standardization module 23 is used to process the initial key string based on one or more key processing rules defined in the compatibility configuration template to generate a standardized key;

[0155] The decryption module 24 is used to perform a decryption operation on the encrypted data string based on the compatibility configuration template to generate target data, wherein the encrypted data string is ciphertext data to be decrypted or plaintext data to be encrypted, and the target data is decrypted plaintext data or encrypted ciphertext data.

[0156] The format preprocessing module 25 is used to perform format preprocessing on the target data when the encryption / decryption operation is a decryption operation and the target data is a numeric string. The format preprocessing includes: detecting whether the numeric string starts with a preset decimal point; if so, placing a preset padding zero character before the beginning of the numeric string.

[0157] It should be noted that the above modules can be implemented by software or hardware. For the latter, they can be implemented in the following ways, but are not limited to: all the above modules are located in the same processor; or, the above modules are located in different processors in any combination.

[0158] Embodiments of the present invention also provide a computer-readable storage medium storing a computer program, wherein the computer program is configured to perform the steps in any of the above method embodiments when executed.

[0159] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.

[0160] Embodiments of the present invention also provide an electronic device including a memory and a processor, the memory storing a computer program and the processor being configured to run the computer program to perform the steps in any of the above method embodiments.

[0161] In one exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.

[0162] Through the above description of the embodiments, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0163] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another apparatus, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0164] The units described as separate components may or may not be physically separate. A component shown as a unit can be one or more physical units; that is, it can be located in one place or distributed in multiple different locations. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0165] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0166] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, in essence, or the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0167] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A cross-platform database encryption compatibility method, characterized in that, include: Obtain a preset compatibility configuration template, which includes an encryption algorithm, working mode, padding scheme, initialization vector, and data encoding format for matching the encryption function of the target database; Receive encrypted data strings and initial key strings; Based on one or more key processing rules defined in the compatibility configuration template, the initial key string is processed to generate a normalized key; Based on the algorithm parameters defined in the compatibility configuration template and the normalization key, the encrypted data string is decrypted to generate target data, wherein the encrypted data string is the ciphertext data to be decrypted and the target data is the decrypted plaintext data; When the target data is a numeric string, a formatting preprocessing is performed on the target data. The formatting preprocessing includes: detecting whether the numeric string starts with a preset decimal point; if so, a preset padding zero character is placed before the beginning of the numeric string.

2. The method according to claim 1, characterized in that, In the compatibility configuration template, the data encoding format is hexadecimal encoding format; Before performing the decryption operation on the encrypted data string, the method further includes: converting the encrypted data string in hexadecimal encoding format into an encrypted byte array; or, After performing encryption and decryption operations on the encrypted data string, the method further includes: when performing encryption operations, converting the target data from a byte array into a hexadecimal encoded string.

3. The method according to claim 1, characterized in that, The process of processing the initial key string to generate a normalized key includes: Perform independent key processing on the key to generate a fixed-length key byte array.

4. The method according to claim 1, characterized in that, The target database is a relational database, and the target database uses its built-in encryption function package to encrypt and store data; the encryption parameters defined in the compatibility configuration template are consistent with the encryption parameters used by the built-in encryption function package.

5. The method according to claim 1, characterized in that, The method further includes: Obtain context data associated with the encrypted data string and a pre-stored integrity token, wherein the context data is the value of one or more unencrypted fields stored in the same data record as the encrypted data string; Based on the decrypted target data and the context data, a verification hash is generated; The verification hash is compared with the integrity token to determine the integrity of the target data.

6. The method according to claim 1, characterized in that, The generated verification hash includes: According to preset concatenation rules, each piece of data in the target data and the context data is concatenated into a standardized verification string; Using a preset hash algorithm and verification key, a hash message authentication code is calculated on the normalized verification string to generate the verification hash.

7. The method according to claim 1, characterized in that, The method further includes: Monitor the execution process of the encryption and decryption operations to capture encryption and decryption anomalies; If a predefined encryption / decryption exception is captured, the source identifier and timestamp associated with that exception are recorded. Based on the records, the frequency of encryption / decryption anomalies of the preset type from the same source identifier within a unit time window is statistically analyzed. When the frequency of occurrence exceeds a preset safety threshold, a safety response is triggered.

8. A cross-platform database encryption compatibility device, characterized in that, include: The configuration acquisition module is used to acquire a preset compatibility configuration template, which includes an encryption algorithm, working mode, padding scheme, initialization vector and data encoding format for matching the encryption function of the target database. The string acquisition module is used to receive encrypted data strings and initial key strings; The standardization module is used to process the initial key string based on one or more key processing rules defined in the compatibility configuration template to generate a standardized key; The decryption module is used to perform a decryption operation on the encrypted data string based on the algorithm parameters defined in the compatibility configuration template and the normalization key to generate target data, wherein the encrypted data string is ciphertext data to be decrypted or plaintext data to be encrypted, and the target data is decrypted plaintext data or encrypted ciphertext data. The format preprocessing module is used to perform format preprocessing on the target data when the encryption / decryption operation is a decryption operation and the target data is a numeric string. The format preprocessing includes: detecting whether the numeric string starts with a preset decimal point; if so, placing a preset padding zero character before the beginning of the numeric string.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the computer program is configured to perform the method described in any one of claims 1 to 7 when executed.

10. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the method as described in any one of claims 1 to 7.