Secure caching and automatic erasing method for sensitive data
By building an access timing chain and encryption key mechanism, the problems of abnormal access identification and automatic erasure of sensitive data in the cache system are solved, achieving high security and practicality against malicious attacks.
Patent Information
- Application Number
- CN202511011195.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-22
- Publication Date
- 2025-09-16
AI Technical Summary
When the existing caching mechanism faces bypass attacks or forged access paths in the middle layer, it is difficult to effectively identify abnormal access, resulting in the risk of sensitive data leakage. It is also unable to automatically erase based on behavioral consistency, reducing the cached data's ability to resist malicious attacks.
By building an access timing chain, the cache operation sequence and time interval in the user session are recorded in real time, encryption keys are generated, and cache data is automatically erased in the event of abnormal access, ensuring that only requests with a complete access chain and consistent access sequence can decrypt and access sensitive data.
It effectively blocks forged access paths or abnormal access behaviors, improves the security and responsiveness of the cache system, prevents the reuse and brute force cracking of sensitive data under abnormal access, and improves the security and practicality of data in the cache stage.
Smart Images

Figure CN120654255A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of information security, and in particular relates to a method for securely caching and automatically erasing sensitive data. Background Art
[0002] With the continuous development of internet technology and the increasing integration of business systems, the frequent access to sensitive data within application systems has placed higher performance and security demands on caching mechanisms. To reduce database access pressure and improve response speed, a common practice is to store frequently accessed business data in an intermediate cache layer, such as high-performance cache systems like Redis and Memcached. However, traditional caching mechanisms primarily use a key-value approach for data storage and access. While access control and encryption algorithms can improve data security, they still pose the risk of sensitive data leakage when the intermediate layer is attacked by bypass attacks, replay attacks, or forged access paths.
[0003] Common methods for protecting sensitive data in existing caches include user-identity-based data encryption, access whitelisting, cache lifecycle restrictions, and access auditing through interface gateways. While these methods can control access behavior to a certain extent, they rely on static authentication and fixed policies, making it difficult to effectively identify anomalous access in dynamic contexts. For example, if an attacker obtains user credentials or forges legitimate interface parameters, they can simulate normal requests through the interface, thereby hitting the cache and obtaining sensitive data. Traditional methods make it difficult for the system to detect such disguised behavior.
[0004] The aforementioned existing technologies lack dynamic modeling and verification of cache access behavior sequences, making it impossible to determine the legitimacy of requests based on the contextual integrity of the access chain, leading to potential leakage of sensitive data. Furthermore, once data is cached, its lifespan is typically driven by time rather than access path, making it impossible to automatically erase data based on behavioral consistency, reducing the cache's ability to defend against malicious attacks. Summary of the Invention
[0005] In order to solve the problems in the prior art, the present invention provides a method for securely caching and automatically erasing sensitive data, comprising the following steps:
[0006] After a user service session begins, the system records the order and time intervals of cached data operations during the user session in real time, and constructs an access sequence chain based on the actual access sequence. Each node in the access sequence chain corresponds to an access to cached data, and the nodes are connected by time intervals.
[0007] When the user session accesses the first sensitive data for the first time and triggers a cache write operation, the system reads the current user ID and the currently formed first access timing chain, and appends this access behavior to the chain to obtain an updated second access timing chain;
[0008] The system generates a first encryption key based on the user identifier and the second access timing chain;
[0009] The system symmetrically encrypts the first sensitive data using the first encryption key, and writes the encryption result into the first cache;
[0010] When a user service session triggers an access request to the first cache, the system obtains the current user identifier and the third access timing chain actually formed in the current session;
[0011] The system generates a second encryption key based on the user identifier and the third access timing chain;
[0012] The system attempts to decrypt the encrypted data in the first cache using the second encryption key. If the decryption is successful, the first sensitive data is returned for access. If the decryption fails, the system identifies the access as abnormal behavior, records relevant log information and immediately performs a cache erase operation, including destroying the encrypted data copy and related indexes in the first cache.
[0013] Furthermore, the nodes in the access timing chain include a cache key name, an operation timestamp, an operation type, a user session identifier, and a time interval field with adjacent nodes.
[0014] Furthermore, the time intervals in the access timing chain are normalized and converted into discrete level identifiers to participate in the generation of encryption keys.
[0015] Furthermore, the first encryption key and the second encryption key are jointly generated by a key derivation algorithm based on the user identifier and the access timing chain, and the key derivation algorithm is a deterministic function.
[0016] Furthermore, the symmetric encryption algorithm is an AES encryption algorithm or a national secret SM4 encryption algorithm.
[0017] Furthermore, the first sensitive data is stored in the cache only in ciphertext form, without plaintext data or decryption keys being written.
[0018] Furthermore, when the system identifies abnormal access behavior, the recorded log information includes access time, access cache key, decryption failure reason, current user ID and access path summary.
[0019] Furthermore, the cache erasure operation includes calling a cache system interface to delete ciphertext data and cancel related index records.
[0020] Furthermore, after the sensitive data is successfully decrypted, the system limits the read-only access rights and maximum usage time of the data.
[0021] Furthermore, if a key node in the access path is missing or the time interval exceeds the maximum tolerance offset range set by the system, the generated second encryption key is inconsistent with the first encryption key, resulting in decryption failure and triggering an erase operation.
[0022] By constructing an access timing chain, this invention implements a mechanism for dynamically generating encryption keys based on user behavior paths. This mechanism tightly binds cached data access permissions to the actual access sequence and time characteristics, fundamentally blocking security threats posed by forged access paths or abnormal access behavior. Only legitimate requests with a complete access chain and consistent access timing can correctly derive the key used to decrypt cached data, ensuring access security for sensitive data during the caching phase.
[0023] The present invention introduces an automatic erasure mechanism triggered by decryption failure. When an abnormal access path or inconsistent key generation is identified, the system will immediately destroy the sensitive data copies and indexes in the cache to prevent data from being reused and brute-force cracked under abnormal access, thereby improving the cache system's response capability to illegal access and the timeliness of data destruction.
[0024] By normalizing access order and time interval information and incorporating them into encryption key derivation, this invention ensures key uniqueness while also providing a degree of behavioral fault tolerance. Even with minor fluctuations in operation times, the system can still ensure access tolerance for legitimate users through discrete time-level mapping, thereby enhancing the solution's practicality and robustness in real-world business scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0026] Figure 1 It is an overall flow chart of the method of the present invention;
[0027] Figure 2 This is a schematic diagram of the access timing chain construction structure. DETAILED DESCRIPTION
[0028] Below, the invention is preferably described with reference to the accompanying drawings and specific embodiments.
[0029] The secure caching and automatic erasure method for sensitive data of the present invention performs encrypted cache management on sensitive data based on the temporal characteristics of user access behavior, and triggers an automatic erasure operation when abnormal access behavior is detected, thereby improving the security and anti-attack capability of sensitive information in the caching stage.
[0030] like Figure 1 As shown, this embodiment implements secure caching and automatic erasure of sensitive data through the following steps.
[0031] After the user service session begins, the system records the operation sequence and operation time interval of the cached data during the user session in real time, and constructs an access timing chain according to the actual access order. Each node in the access timing chain corresponds to an access behavior to the cached data, and the nodes are connected by time intervals.
[0032] In traditional data caching mechanisms, sensitive data is usually stored uniformly and called through key-value methods after being written to the cache. Although encryption protection can be combined with user identity, once the cache layer encounters the risk of bypass or leakage, it may still cause the data to be illegally accessed or reconstructed. In order to improve the access security of sensitive data in the cache, the present invention introduces an "access timing chain" to make the accessibility of sensitive data dependent on the complete and correct user access path and time behavior, thereby limiting the data decryption conditions through the behavioral context, so that only legitimate session access paths can restore the key and access the data, and illegal access will cause decryption failure and automatic erasure of the cache due to inconsistent timing chains, thereby effectively avoiding the leakage of sensitive data caused by cache interception or replay attacks.
[0033] An access timing chain refers to an ordered access structure constructed by the system within a user's business session based on the order in which the user accesses cached data and the time intervals between adjacent operations. This chain represents each user access to the cache as a node in chronological order. The connections between nodes are formed based on the access order. The system can view this structure as a chain context that includes access paths and temporal features. The time interval between nodes can be defined as the time difference between two adjacent accesses, and the operations are numbered according to the logical order in which they occurred.
[0034] In most enterprise-level application systems, business logic is defined by front-end and back-end services through clearly orchestrated processes. For example, steps such as user login, query, order placement, payment, and confirmation are typically executed in a fixed order. Because this business logic undergoes extensive product design and functional testing, once deployed in production, its code logic is relatively stable, and its interface call paths are relatively fixed. This means that users will exhibit highly consistent behavior when accessing cached data during normal system usage.
[0035] Specifically, the user access pattern of the cache in a normal session usually includes the following characteristics:
[0036] Stable access order: Users usually access the cache in the order of business processes, for example, first accessing the user information cache, then the order cache, and finally the payment information cache;
[0037] Time interval regularity: The time interval between operations fluctuates within a certain range, but generally remains within a stable time window;
[0038] Complete access chain: Normal requests will trigger a complete business process from entry to exit, thus covering access to all key cache points.
[0039] However, in real-world environments, certain attacks or unusual calling behaviors attempt to circumvent these business processes. For example, some malicious requests directly forge parameters to call core APIs, skipping permission checks, payment confirmation, or order verification, and directly attempting to access sensitive data. A key characteristic of this behavior is that it does not go through the entire business process, and therefore does not form the expected complete access chain at the cache layer. For example, if an attacker directly requests the payment data API without first triggering the order confirmation API, some key nodes in the access timing chain will be missing.
[0040] In a specific implementation, the steps of constructing the access timing chain include:
[0041] 1. Initialize the session access record structure
[0042] After a user service session begins, the system assigns a unique session identifier to the current user and allocates an access record container for the session in system memory. This container stores all access events to cached data during the user's session. The container structure can be a linked list, stack array, or hash map, and must support sequential append and index access.
[0043] Assume that user A starts a new service session. The system assigns a session identifier, SID_A, to the session. The system then initializes an empty linked list structure named "Access_Chain_SID_A" in memory to record subsequent cache access behavior.
[0044] 2. Capture access events and generate access nodes
[0045] Whenever a user accesses cached data (reading or writing), the system monitors the operation and extracts the following information: access timestamp, cached data key, operation type, and access status. This information is then constructed into an access node object, along with the current session identifier, and inserted at the end of the access chain.
[0046] After user A's session begins, at 10:01:05, he accesses cached data with the key "userinfo." The system generates access node N1, which contains the following fields: key = "userinfo," timestamp = 10:01:05, operation type = "read," and session ID = SID_A. Node N1 is appended to the end of Access_Chain_SID_A.
[0047] 3. Calculate the time interval and connect the previous and next nodes
[0048] For each newly accessed node, the system reads the timestamp of the previous node and calculates the time interval between the previous and current timestamps. This interval is stored as a connection attribute between the two nodes in the previous node or chain connection structure.
[0049] Subsequently, user A accesses the cache with the key "orderlist" at 10:01:09, generating node N2 with a timestamp of 10:01:09. The system calculates the time difference between N1 and N2 as 4 seconds and attaches this interval as a connection attribute to the edge between N1 and N2. The access chain structure is:
[0050] N1("userinfo", 10:01:05) ——4s→ N2("orderlist", 10:01:09)
[0051] 4. Build a complete access timing chain structure
[0052] The system continuously monitors all cache access behaviors in the session, appends nodes and updates time intervals in sequence until the current data access process ends. The access chain will serve as the complete historical structure of the current session cache behavior for subsequent key derivation and access verification. The overall timing chain structure is as follows: Figure 2 shown.
[0053] User A continues to access the "paymentdata" cache at 10:01:13, generating node N3 with a timestamp of 10:01:13. The interval between it and N2 is calculated to be 4 seconds, and the chain structure is updated as follows:
[0054] N1("userinfo", 10:01:05) ——4s→ N2("orderlist", 10:01:09) ——4s→N3("paymentdata", 10:01:13)
[0055] Through the above technical path, the system can stably and real-time build a cache access timing chain during the user session, and use the behavior sequence and time interval in the chain as a trusted basis for subsequent key derivation and access control.
[0056] When the user session accesses the first sensitive data for the first time and triggers a cache write operation, the system reads the current user ID and the currently formed first access timing chain, and appends this access behavior to the chain to obtain an updated second access timing chain.
[0057] In a typical business system, when a user session first accesses business data, the data is often not yet stored in the cache system, resulting in a cache miss. To fulfill the user's request, the system must read the target data from a backend database or other persistent storage. For example, when requesting order details for the first time, the system must retrieve the complete order information from the database using the order number. To improve subsequent access efficiency and reduce repeated query pressure on the database, the system typically writes the data content to the cache after successfully reading it and stores it indexed by the business identifier. Subsequently, when the same order information is accessed again in the same or other sessions, the system can prioritize directly retrieving the required data from the cache, significantly reducing response time and database load, optimizing system resource utilization and significantly improving responsiveness. This mechanism is a common read optimization technique in modern high-concurrency systems, particularly suitable for business data scenarios with high access frequency and low update frequency. Therefore, the first access to sensitive data that needs to be cached triggers a cache write operation, which determines the access chain through the following steps:
[0058] 1. When an operation in a user session triggers a request to write sensitive data to the cache for the first time, the system detects the cache write and immediately initiates the access context capture process. At this point, the system first obtains the current user's identity information, which may include the user ID, session ID, device fingerprint information, login token, etc., to uniquely identify the service session. Subsequently, the system attempts to read the access time chain established in the current user session. The access time chain is used to record all access behaviors related to cached data by the current user since the session was initiated, arranged in chronological order, and may include information about the time intervals between nodes.
[0059] In some scenarios, the current sensitive data may be the target data that triggers cache writes for the first time in a user session. At this time, the access timing chain has not yet been built and is in the initialization state or is empty. In this case, the system will automatically initialize a new access chain structure and treat it as the initial state of the current chain.
[0060] 2. The system encapsulates the behavior corresponding to this cache write operation into a new access node. An access node is a structured object that represents a specific cache access behavior and contains the following fields: cache key name, operation timestamp, access type (read or write), current user identifier, session identifier, and the time interval since the previous node. If this is the first access node in a session, the time interval field can be set to a default initial value (such as 0) or to the "no previous node" state. The node can optionally attach a hash digest or digital signature field for tamper-proof verification.
[0061] 3. The system appends the access node to the end of the current access timing chain, forming an updated access path. This path, known as the "second access timing chain," reflects the user's complete cache access history from the start of the session to the current write operation. When appending nodes, the system ensures the immutability of the node order in the chain and automatically calculates and updates the time interval field to ensure the chain's temporal integrity.
[0062] This process allows the system to structurally integrate current access behavior with existing access history before sensitive data is cached, thereby constructing a cryptographic key derivation basis that maintains user identity and behavioral continuity. Even if sensitive data is the first cached operation in a session, the system can gradually build access context from an empty chain, completing the access path node by node.
[0063] In a specific example:
[0064] User A logs into the business system for the first time at 10:00:05 AM and immediately accesses the order details screen, requesting data for order number OD202406001. The system detects that this order information is not cached and instead reads the order details from the database and prepares to write them to the cache. At this point, because no other cache accesses have occurred in this session, the access sequence chain is empty.
[0065] Based on this access behavior, the system generates access node N1. Its fields include: cache key name "order_OD202406001", access timestamp 10:00:05, operation type write, user ID A1, and session ID SID_A. Because N1 is the first node, the time interval between it and the previous node is initialized to 0.
[0066] The system initializes the access chain structure "AccessChain_SID_A" and adds node N1 as the first node to form the initial access chain:
[0067] N1("order_OD202406001", 10:00:05, Δt = 0).
[0068] The system generates a first encryption key based on the user identifier and the second access timing chain.
[0069] In a cache-based data security mechanism, access rights to sensitive data should be restricted not only based on static identity authentication but also in combination with dynamic behavior characteristics, thereby effectively preventing data leaks caused by abnormal operations such as forged requests and bypassing business processes. To this end, the present invention proposes to dynamically generate a unique encryption key based on the user identifier and access behavior path before writing cached sensitive data, and use this key for encryption operations on sensitive data, thereby ensuring that only subsequent visitors with consistent behavior can successfully decrypt and access cached contents. In this mechanism, the access order and access interval in the access timing chain will directly affect the key generation result, thereby forming a strong coupling relationship between the access rights of cached data and the access path behavior, thereby enhancing the security of the system.
[0070] In a specific implementation, the step of generating the first encryption key includes:
[0071] The system obtains the unique identification information of the current user, including but not limited to user ID, session ID, device ID or authentication token, for identity dimension binding in subsequent key generation.
[0072] The system reads the currently updated access sequence chain, which consists of multiple access nodes. The nodes are arranged in sequence according to the operation order and record the access key name and access time.
[0073] The system traverses the chain node sequence, calculates the actual time interval between each pair of adjacent nodes, and normalizes the interval value. Normalization can include mapping the interval to a predefined discrete time interval, such as rounding the interval to 500 milliseconds, or setting a maximum and minimum tolerance range and mapping it to a level identifier. Optional implementation schemes include mapping intervals less than 1 second to level A, 1 to 3 seconds to level B, 3 to 10 seconds to level C, and greater than 10 seconds to level D.
[0074] The system combines the normalized access sequence with the user identifier to form a structured key input, such as a key derivation vector or string digest. The system then calls a key derivation function to generate the first encryption key. This key derivation function can use a KDF-like algorithm, a hash-based MAC function, or a repeatable entropy encoding mechanism based on the access sequence to ensure that the same key is generated by the same user under the same behavior path.
[0075] The system uses the first encryption key to perform symmetric encryption operations on sensitive data that is about to be written into the cache, and stores the ciphertext data into the cache structure, replacing the plaintext writing process.
[0076] Through this approach, the system ensures that sensitive cached data is bound to a specific access path upon write. Subsequent accesses can only correctly decrypt the cache if they reproduce the same path and follow a consistent timeline. This creates dynamic contextual constraints on sensitive data access, mitigating security risks associated with identity leaks or interface replay. Furthermore, a time normalization mechanism effectively mitigates time errors caused by fluctuations in human operations or system response delays, making the key generation mechanism more fault-tolerant and practical.
[0077] In the preceding example, user A accessed "userinfo," "orderlist," and "paymentdata" in the access chain, at 10:00:05, 10:00:08, and 10:00:14, respectively. The system calculates these time intervals as 3 seconds and 6 seconds, and normalizes them to levels B and C. The system combines user ID A1 and the access sequence ["userinfo-B," "orderlist-C," "paymentdata"] as key input and uses this structure to derive the first encryption key, Key_123.
[0078] The system symmetrically encrypts the first sensitive data using the first encryption key and writes the encryption result into the first cache.
[0079] In traditional caching mechanisms, once sensitive data is written to the cache, its access control usually relies on a static permission system. Once a cache hit occurs, the system defaults to a legitimate access request. Although this mechanism improves performance in high-concurrency scenarios, it also amplifies security risks. Once an attacker bypasses authentication or replays an old request, it may access sensitive cached data that has not yet expired. Therefore, the present invention proposes to perform symmetrical encryption on the sensitive data based on the encryption key generated above before writing it to the cache, ensuring that even if the attacker directly hits the cache, the attacker cannot decrypt the data because he does not have the key, thereby effectively achieving security enhancement of the cache layer.
[0080] In a specific implementation, the process of encrypting data using the key generated in the above steps includes:
[0081] The system invokes a symmetric encryption module to perform encryption on the first sensitive data. This module uses the previously generated first encryption key as input to perform a one-time encoding process on the original data. Optional implementations include using the AES encryption algorithm with a key length of 128, 192, or 256 bits, or using the SM4 national commercial encryption algorithm to meet domestic deployment requirements.
[0082] After the encryption operation is complete, the system writes the generated ciphertext data to a pre-set first cache area. This area can be a key-value pair structure in a local cache system (such as Redis or Memcached). The cache key can contain a data type identifier, a user identity fragment, and an encryption tag to support subsequent access identification and decryption matching.
[0083] To prevent cache leaks from causing brute force cracking of ciphertext, the system can optionally append an integrity check code or message digest value to the encryption result for subsequent verification of whether the ciphertext has been tampered with or forged.
[0084] The system records the cache write behavior and updates the cache lifecycle parameters, such as setting the cache validity period, maximum number of accesses, behavior context drift tolerance, etc., to provide a reference for subsequent abnormal behavior detection.
[0085] Through these steps, the system ensures that sensitive data is key-bound and encrypted before being written to the cache. Even if an attacker gains physical access to the cache or hits the cache through an API call, they cannot restore the original data without the key context, thus ensuring the storage security of sensitive data at the cache level. Furthermore, this mechanism is compatible with existing cache architectures, making it easy to deploy and integrate.
[0086] Continuing with the previous example, when user A accesses the order details screen, the system reads the complete order information for order number OD202406001 from the database, generating the first sensitive data. The system has previously generated the first encryption key, Key_123, based on the user's behavior path N1 → N2. The system then invokes the AES-128 encryption module and encrypts the order data using Key_123, generating the ciphertext Cipher_OD202406001. The system then writes this ciphertext as the value to the cache key "order_OD202406001" and sets an expiration time of 30 minutes.
[0087] When a user service session triggers an access request to the first cache, the system obtains the current user identifier and the third access timing chain actually formed in the current session.
[0088] In the traditional cache access mechanism, the system usually returns the result directly after detecting a cache hit, without re-verifying whether the current request has the consistency of the access context. This processing method has advantages in performance, but there are major security risks, especially in sensitive data processing scenarios. Once an attacker bypasses the front-end authentication or uses replayed requests to hit the cache, he can bypass the business process and directly obtain sensitive information, causing the risk of data leakage. In order to prevent such attacks, the present invention proposes that when a cache access request arrives, the system not only needs to confirm the identity information of the requester, but also needs to obtain the access behavior chain actually formed in the current session, and use it as an important basis for access authorization judgment.
[0089] In a specific implementation, determining the access timing chain of services accessing the cache is achieved through the following steps:
[0090] When the system detects a request to access the cache interface, it determines that the request is targeting the encrypted first cache data. It immediately triggers the access context resolution process and extracts user identification information from the current request. This extraction method includes reading the user ID field in the current request header, calling the identity management module to obtain the login session identifier, or reading the corresponding session token from the server-side record.
[0091] The system locates the user's currently active service session based on the user's identification information and further extracts the access operation records completed in that session. The system constructs an access time sequence chain based on the access sequence and operation timestamps, which serves as the "third access time sequence chain." This construction process involves traversing access logs or cache hit records and calculating the time interval between adjacent operations based on timestamp differences.
[0092] In a specific example, user A first accesses the user information node "userinfo" at 10:00:05, and accesses the order node "order_OD202406001" at 10:00:08, forming an access chain N1 → N2, generating the key Key_123, and encrypting the order data and writing it to the cache.
[0093] Later, at 10:00:14, the user attempts to access the order information again. The system detects that the access target is the first cached data, triggering the access context resolution process. The system obtains user ID A1 and extracts the operation records of the current business session. It recognizes that the user has accessed "userinfo" and "order_OD202406001" in sequence, forming the third access sequence chain.
[0094] The system generates a second encryption key according to the user identifier and the third access timing chain.
[0095] The second encryption key is generated similarly to the first encryption key. The current user ID and the third access sequence chain are extracted, the time intervals are normalized, and the access sequence and time interval are combined as inputs to the key derivation function. The second encryption key is then generated using the key derivation function. The system uses the same key derivation method as the write phase to ensure that the same key is generated when access behavior is consistent.
[0096] For example, user A first accesses the "userinfo" data at 10:00:05, and then accesses "order_OD202406001" at 10:00:08 and writes it to the cache. The system calculates the time interval between the two operations as 3 seconds, normalizes it to level B, and generates the first encryption key Key_123.
[0097] When user A accesses "order_OD202406001" again at 10:00:14, the system extracts the current access behavior path as "userinfo" → "order_OD202406001" and calculates the same 3-second interval, normalizing it to level B. Based on this, the system generates a second encryption key, Key_123′. Because the behavior path and the normalized time level are consistent, Key_123′ equals Key_123, and the system successfully decrypts the cache and returns the data. If the access path or time rhythm changes, the generated key will be different, and decryption will fail.
[0098] The system attempts to decrypt the encrypted data in the first cache using the second encryption key. If the decryption is successful, the first sensitive data is returned for access. If the decryption fails, the system identifies the access as abnormal behavior, records relevant log information and immediately performs a cache erase operation, including destroying the encrypted data copy and related indexes in the first cache.
[0099] The system calls the encryption and decryption module and attempts to decrypt the encrypted data in the first cache using the second encryption key. The decryption module can use a symmetric encryption algorithm such as AES or SM4. The decryption process must use the same algorithm, padding method, and key length as the initial encryption.
[0100] If the decryption is successful, that is, the key is correct and the data has not been tampered with, the system will decode the original sensitive data into plain text and return it to the caller. Furthermore, the read permission can be set to read-only and the usage time can be limited. Repeated cache writing is not allowed.
[0101] If decryption fails, it indicates that the current access path is inconsistent with the original behavior chain. The system will immediately mark this access as abnormal access behavior and record a log, including access time, user ID, access path summary, decryption failure reason, etc., for subsequent auditing and risk analysis.
[0102] The system simultaneously triggers the cache wipe mechanism, deleting the corresponding data item from the primary cache and destroying the ciphertext content and its index record. Optional implementation options include invalidating the cache key, invoking the cache delete command, and marking the data as obsolete, ensuring that the sensitive data cannot be accessed again after this session.
[0103] Through this mechanism, the system implements a secure cache decryption process based on behavioral consistency verification. Instead of relying on traditional identity verification, it embeds behavioral traces into the decryption key generation path. Even if an attacker possesses a user's identity, they cannot bypass the business behavior chain to decrypt the data. This ensures that sensitive data in the cache layer is "context-bound," significantly enhancing the system's resistance to replay attacks and unauthorized access.
[0104] For example, in the scenario where user A accesses order information, the system writes the encrypted order data to the cache key "order_OD202406001" at 10:00:08, using the key Key_123. Subsequently, the user requests access to the order data again at 10:05:15, and the system regenerates Key_123 based on the current behavior path.
[0105] If the access path and timing are consistent, and Key_123′ matches the original key, the system successfully decrypts the ciphertext, returns the order details, and displays them in the user interface. If the access path is abnormal, such as a user skipping the "userinfo" node and directly requesting "order_OD202406001," or if the access time interval deviates abnormally, the system generates Key_456′ and the decryption attempt fails.
[0106] The system identifies this as an abnormal access and records a log: "User A, 10:05:15, behavior path missing, decryption failed", and immediately erases the ciphertext data and index key of "order_OD202406001" from the cache to prevent the data from being illegally accessed or reused, ensuring the irreversible elimination of sensitive information in abnormal access scenarios.
[0107] The prior art mentioned in the above background technology section and specific embodiments section of the present invention can be regarded as part of the present invention and used to understand the meaning of some technical features or parameters.
Claims
1. A method for secure caching and automatic erasure of sensitive data, characterized in that: The steps include: After a user service session begins, the system records the order and time intervals of cached data operations during the user session in real time, and constructs an access sequence chain based on the actual access sequence. Each node in the access sequence chain corresponds to an access to cached data, and the nodes are connected by time intervals. When the user session accesses the first sensitive data for the first time and triggers a cache write operation, the system reads the current user ID and the currently formed first access timing chain, and appends this access behavior to the chain to obtain an updated second access timing chain; The system generates a first encryption key based on the user identifier and the second access timing chain; The system symmetrically encrypts the first sensitive data using the first encryption key, and writes the encryption result into the first cache; When a user service session triggers an access request to the first cache, the system obtains the current user identifier and the third access timing chain actually formed in the current session; The system generates a second encryption key based on the user identifier and the third access timing chain; The system attempts to decrypt the encrypted data in the first cache using the second encryption key. If the decryption is successful, the first sensitive data is returned for access. If the decryption fails, the system identifies the access as abnormal behavior, records relevant log information and immediately performs a cache erase operation, including destroying the encrypted data copy and related indexes in the first cache.
2. The method for secure caching and automatic erasure of sensitive data according to claim 1, characterized in that: The nodes in the access timing chain include a cache key name, an operation timestamp, an operation type, a user session identifier, and a time interval field with adjacent nodes.
3. The method for secure caching and automatic erasure of sensitive data according to claim 1, characterized in that: The time intervals in the access timing chain are normalized and converted into discrete level identifiers before participating in the encryption key generation.
4. The method for secure caching and automatic erasure of sensitive data according to claim 1, wherein: The first encryption key and the second encryption key are jointly generated based on the user identifier and the access timing chain through a key derivation algorithm, and the key derivation algorithm is a deterministic function.
5. The method for secure caching and automatic erasure of sensitive data according to claim 4, characterized in that: The symmetric encryption algorithm is the AES encryption algorithm or the national secret SM4 encryption algorithm.
6. The method for secure caching and automatic erasure of sensitive data according to claim 1, wherein: The first sensitive data is stored in the cache only in ciphertext form, and no plaintext data or decryption key is written.
7. The method for secure caching and automatic erasure of sensitive data according to claim 1, wherein: When the system identifies abnormal access behavior, the recorded log information includes access time, access cache key, decryption failure reason, current user ID and access path summary.
8. The method for secure caching and automatic erasure of sensitive data according to claim 1, wherein: The cache erasure operation includes calling the cache system interface to delete the ciphertext data and cancel the related index records.
9. The method for secure caching and automatic erasure of sensitive data according to claim 1, wherein: After the sensitive data is successfully decrypted, the system limits the read-only access rights and maximum usage time of the data.
10. The method for secure caching and automatic erasure of sensitive data according to claim 1, wherein: If a key node in the access path is missing or the time interval exceeds the maximum tolerance offset range set by the system, the generated second encryption key will be inconsistent with the first encryption key, resulting in decryption failure and triggering an erase operation.