Character encryption method, electronic device and computer-readable medium

Through the dynamic key encryption mechanism and preset data structure, the data leakage and tampering risks of traditional natural language processing systems are solved, data security and processing efficiency are improved, and the human-computer interaction experience is improved.

CN120358014BActive Publication Date: 2025-09-09CLP (TIANJIN) NETWORK INFORMATION SECURITY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510855009.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-25
Publication Date
2025-09-09
Estimated Expiration
2045-06-25

AI Technical Summary

Technical Problem

Traditional natural language processing systems have problems such as high risk of data leakage, high risk of tampering, and low processing efficiency.

Method used

A dynamic key encryption mechanism is adopted to encapsulate encrypted characters through a preset data structure, convert plaintext prompt words into ciphertext prompt words based on character mapping relationships, and decrypt them into plaintext responses after processing in the natural language processing system.

Benefits of technology

Significantly reduce the risk of data leakage and tampering, improve data security, avoid occupying the computing resources of the natural language processing system, improve processing efficiency, and enhance the human-computer interaction experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120358014B_ABST
    Figure CN120358014B_ABST
Patent Text Reader

Abstract

This application discloses a character encryption method, electronic device, and computer-readable medium. When a key switching condition is met, a target key group and target key after switching are determined from a pre-built key library; encrypted characters that conform to a preset data structure are obtained based on the target key group, target key, and original character encapsulation; a locally stored character mapping table is updated based on a character mapping relationship, so that a gateway converts a plaintext prompt word sent by a user device into a ciphertext prompt word based on the updated character mapping table; the ciphertext prompt word is input into a natural language processing system encrypted based on the character mapping relationship, and an output ciphertext response is obtained, so that the gateway decrypts the ciphertext response to obtain a plaintext response and sends it to the user device. This method can improve data security, save computing resources, reduce inference latency, and enhance natural language processing efficiency and user experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular, to a character encryption method, an electronic device, and a computer-readable medium. Background Art

[0002] Natural language processing (NLP) is a key branch of artificial intelligence (AI) models. One important form of human-computer interaction involves generating natural language responses based on user-entered prompts. Traditional NLP systems face numerous security challenges, including high risks of data leakage and tampering, low processing efficiency, and limited data security. Summary of the Invention

[0003] The present application aims to solve one of the technical problems in the related art to a certain extent. To this end, the present application provides a character encryption method, an electronic device and a computer-readable medium.

[0004] As a first aspect of the present application, a character encryption method is provided, wherein the method comprises:

[0005] When a key switching condition is met, determining a target key group after switching and a target key in the target key group from a pre-built key library; wherein the key library includes a first preset number of key groups, and the key group includes a second preset number of keys;

[0006] Encapsulating, according to the target key group, the target key and the original character, an encrypted character conforming to a preset data structure;

[0007] updating a locally stored character mapping table according to a character mapping relationship between the original character and the encrypted character, so that a gateway associated with the device converts a plaintext prompt word sent by the user device into a ciphertext prompt word based on the updated character mapping table;

[0008] The ciphertext prompt word is input into the natural language processing system encrypted based on the character mapping relationship to obtain the ciphertext response output by the natural language processing system, so that the gateway decrypts the ciphertext response to obtain a plaintext response and sends the plaintext response to the user device.

[0009] Optionally, encapsulating the target key group, the target key, and the original character to obtain an encrypted character conforming to a preset data structure includes:

[0010] Generate encrypted data bytes according to the target key and the original characters;

[0011] According to the byte length of the encrypted data bytes, the currently used encryption algorithm, the identifier of the target key group and the identifier of the target key, the encrypted data byte length field, the encryption algorithm field, the key group identification field and the key identification field are generated in sequence to form control data; wherein the encrypted characters include the encrypted data bytes and the control data.

[0012] Optionally, each field in the control data includes a corresponding preset number of bits, and the byte length of the encrypted data byte does not exceed the maximum value that can be represented by the encrypted data byte length field; the byte length of the encrypted data byte includes:

[0013] (1);

[0014] In formula (1), Indicates the byte length of the encrypted data bytes, Related to the encryption algorithm currently in use, Indicates the original byte length of the encrypted data, Indicates the extended byte length, The value of is greater than or equal to 1.

[0015] Optionally, updating a locally stored character mapping table according to a character mapping relationship between the original character and the encrypted character includes:

[0016] For any of the original characters, the character mapped in the locally stored character mapping table is replaced by the encrypted character corresponding to the character mapping relationship.

[0017] Optionally, the key switching conditions include any of the following: key life cycle expiration conditions, security policy update conditions, preset policy dynamic adjustment conditions, key usage frequency conditions, character processing quantity conditions, external instruction triggering conditions, resource load perception conditions, and user behavior pattern conditions.

[0018] Optionally, the key lifecycle termination condition includes: the current key validity period ends; the key validity period is determined by the following key aging algorithm:

[0019] (2);

[0020] In formula (2), Indicates the current key validity period. Indicates the current security level and the value is an integer. Indicates the usage frequency of the current target key. and Indicates a preset constant.

[0021] Optionally, the security policy update condition includes any of the following: 、 and Updated, added key geographical location restrictions, and enabled quantum-resistant encryption algorithms;

[0022] The preset policy dynamic adjustment condition includes: an update in the key aging algorithm causes an update of T.

[0023] Optionally, the key usage frequency condition includes: the usage frequency of the current target key exceeds a preset frequency threshold;

[0024] The character processing quantity condition includes: encrypting a preset number of consecutive original characters according to the current target key.

[0025] As a second aspect of the present application, an electronic device is provided, wherein the electronic device includes:

[0026] one or more processors;

[0027] A memory having one or more computer programs stored thereon, wherein when the one or more computer programs are executed by the one or more processors, the one or more processors implement the character encryption method according to the first aspect of the present application.

[0028] As a third aspect of the present application, a computer-readable medium is provided, on which a computer program is stored, wherein when the computer program is executed by a processor, the character encryption method according to the first aspect of the present application is implemented.

[0029] The character encryption method provided in the present application establishes a dynamic key encryption mechanism and presets a special data structure, obtains encrypted characters that conform to the preset data structure according to the original character encapsulation, and then converts the plaintext prompt words sent by the user device into ciphertext prompt words based on the character mapping relationship between the original characters and the encrypted characters, and provides them to a natural language processing system that can directly process the ciphertext prompt words to obtain an output ciphertext response, and finally decrypts the ciphertext response to obtain a plaintext response and feeds it back to the user device. This method can significantly reduce the risk of data leakage and tampering and improve data security based on the fine-grained dynamic encryption method of characters, and avoid occupying the computing resources of the natural language processing system and increasing the inference delay of the natural language processing system, thereby improving the efficiency of natural language processing and improving the user's human-computer interaction experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] The present application will be further described below with reference to the accompanying drawings:

[0031] Figure 1This is a flowchart of an implementation method of the character encryption method provided in an embodiment of the present application;

[0032] Figure 2 This is a flowchart of an implementation method of encapsulating encrypted characters provided in an embodiment of the present application;

[0033] Figure 3 This is a flowchart of an implementation method of updating a locally stored character mapping table provided in an embodiment of the present application;

[0034] Figure 4 This is a module diagram of an implementation of an electronic device provided in an embodiment of the present application;

[0035] Figure 5 It is a schematic diagram of the computer-readable medium provided in an embodiment of the present application.

[0036] Description of Reference Numerals

[0037] 101: Processor 102: Memory

[0038] 103: I / O interface 104: bus DETAILED DESCRIPTION

[0039] The embodiments of the present application are described in detail below. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described in the embodiments are intended to be used to explain the present application and are not to be construed as limiting the present application.

[0040] References in this specification to "one embodiment," "an example," or "an example" mean that a particular feature, structure, or characteristic described in connection with the embodiment itself can be included in at least one embodiment disclosed herein. The appearances of the phrase "in one embodiment" in various places in the specification are not necessarily all referring to the same embodiment.

[0041] Natural language processing (NLP) is a key branch of artificial intelligence (AI) models. One key human-computer interaction method involves outputting natural language responses based on user-entered prompts. Traditional NLP systems typically use plaintext input and output, posing risks of data leakage and tampering. Some NLP systems employ key encryption mechanisms to address this issue, but these traditional encryption methods require additional computing resources to support real-time encryption, significantly impacting processing efficiency. Furthermore, fixed keys are susceptible to brute force attacks. In summary, traditional NLP systems present numerous data security challenges, including high risks of data leakage and tampering, low processing efficiency, and reduced data security.

[0042] Based on the above important findings, the applicant of this application has innovatively proposed to establish a dynamic key encryption mechanism and preset a special data structure, obtain encrypted characters that conform to the preset data structure based on the original character encapsulation, and then convert the plaintext prompt words sent by the user device into ciphertext prompt words based on the character mapping relationship between the original characters and the encrypted characters, and provide them to a natural language processing system that can directly process the ciphertext prompt words to obtain an output ciphertext response, and finally decrypt the ciphertext response to obtain a plaintext response and feed it back to the user device. This can not only significantly reduce the risk of data leakage and tampering and improve data security, but also avoid occupying the computing resources of the natural language processing system, thereby improving the efficiency of natural language processing.

[0043] As a first aspect of the embodiment of the present application, a character encryption method is provided, such as Figure 1 As shown, the method includes:

[0044] Step S110: If the key switching condition is met, determining a target key group after switching and a target key in the target key group from a pre-built key library; wherein the key library includes a first preset number of key groups, and the key group includes a second preset number of keys;

[0045] Step S120, encapsulating the target key group, the target key, and the original character to obtain an encrypted character that conforms to a preset data structure;

[0046] Step S130: updating a locally stored character mapping table based on a character mapping relationship between the original character and the encrypted character, so that a gateway associated with the device converts the plaintext prompt word sent by the user device into a ciphertext prompt word based on the updated character mapping table;

[0047] In step S140, the ciphertext prompt word is input into the natural language processing system encrypted based on the character mapping relationship to obtain a ciphertext response output by the natural language processing system, so that the gateway decrypts the ciphertext response to obtain a plaintext response and sends the plaintext response to the user device.

[0048] The embodiments of this application do not specifically limit the key switching conditions. For example, key switching conditions with different switching frequencies and timings can be specified based on actual natural language processing scenarios (such as intelligent question-answering in the financial field, medical health consultations, and corporate confidential document generation). The embodiments of this application switch the target key group and target key based on the key switching conditions, which is a dynamic key encryption mechanism.

[0049] The embodiments of the present application do not specifically limit how to determine the target key group and target key after switching from the pre-built key library. For example, the target key can be determined according to a random selection algorithm, or the target key can be selected by rotating the keys within the key group according to the Fibonacci sequence algorithm. The embodiments of the present application do not specifically limit the random selection algorithm. For example, random sampling, reservoir sampling, stratified sampling, random number generator, etc. can be used.

[0050] Among them, the embodiment of the present application first generates a basic key matrix in a secure key generation method, and then divides the key matrix into a first preset number of key groups according to the grouping strategy, each key group includes a second preset number of keys, thereby constructing a key library.

[0051] Among them, the embodiment of the present application can pre-construct an original character set that supports the Unicode standard (including terms, symbols, etc. of the corresponding industry, and expandable characters when necessary), and then encrypt and encapsulate each original character in the original character set to obtain a character mapping relationship between each original character and its corresponding encrypted character.

[0052] Among them, the embodiment of the present application does not make any special restrictions on whether all original characters use completely consistent target key groups and target keys to encapsulate encrypted characters. That is to say, different original characters can be encapsulated using different target key groups and target keys. It is sufficient to ensure that an original character is uniquely mapped to an encrypted character, and an encrypted character is also uniquely mapped to an original character. Of course, in order to prevent data ambiguity or security vulnerabilities caused by collisions, it is also possible to consider further ensuring that different original characters are uniquely mapped to an encrypted character. and The collision probability between is less than a certain threshold, e.g. , thus ensuring that the probability of different original characters mapping to the same encrypted character is also extremely low.

[0053] Among them, the embodiment of the present application does not make any specific restrictions on how to obtain a natural language processing system based on character mapping relationship encryption, as long as the obtained natural language processing system can accurately process the ciphertext prompt words obtained based on the character mapping relationship conversion.

[0054] The embodiments of the present application do not specifically limit the natural language processing system. For example, the natural language processing system may include a natural language processing model and its associated text processing module. The embodiments of the present application do not specifically limit the natural language processing model. For example, the natural language processing model may include any of the following: a large language model (LLM) or a multimodal large language model (MLLM).

[0055] Among them, the embodiment of the present application does not make any special restrictions on whether the gateway associated with this device (i.e., the device that executes the character encryption method and has the natural language processing system loaded or installed) is independent of this device. That is, the gateway can include an independent device installed on the communication link between the user device and this device, or it can include a module in this device that integrates the gateway function.

[0056] The gateway converts the plaintext prompt words sent by the user device into ciphertext prompt words based on a real-time updated character mapping table, and then inputs the ciphertext prompt words into the encrypted natural language processing system to obtain the ciphertext response output by the encrypted natural language processing system. Finally, the gateway decrypts the ciphertext response to obtain the plaintext response and sends the plaintext response to the user device. In this way, the user device does not need to encrypt the prompt words. It can receive the plaintext response by sending the plaintext prompt words. The human-computer interaction process is transparent and burden-free, which can not only improve data security but also enhance the user's human-computer interaction experience.

[0057] The character encryption method provided in the embodiment of the present application establishes a dynamic key encryption mechanism and presets a special data structure, obtains encrypted characters that conform to the preset data structure based on the original character encapsulation, and then converts the plaintext prompt words sent by the user device into ciphertext prompt words based on the character mapping relationship between the original characters and the encrypted characters, and provides them to a natural language processing system that can directly process the ciphertext prompt words to obtain an output ciphertext response, and finally decrypts the ciphertext response to obtain a plaintext response and feeds it back to the user device. This can significantly reduce the risk of data leakage and tampering and improve data security based on the fine-grained dynamic encryption method of characters, and avoid occupying the computing resources of the natural language processing system and increasing the inference delay of the natural language processing system, thereby improving the efficiency of natural language processing and improving the user's human-computer interaction experience.

[0058] The applicant of this application further proposed to encapsulate the byte length of the encrypted data bytes, the currently used encryption algorithm, the identifier of the target key group and the identifier of the target key as control data (ControlByte) in the encrypted character structure, which can not only significantly improve data security by taking advantage of the irregular characteristics of the dynamic key encryption mechanism, but also enable the gateway to directly decrypt the characters of the ciphertext response output by the natural language processing system, thereby further improving the efficiency of natural language processing.

[0059] Accordingly, in some embodiments, the target key group, the target key and the original character are encapsulated to obtain the encrypted character that conforms to the preset data structure (ie, the encrypted character involved in step S120), such as Figure 2 Shown, including:

[0060] Step S210, generating encrypted data bytes according to the target key and the original characters;

[0061] Step S220, based on the byte length of the encrypted data bytes, the currently used encryption algorithm, the identifier of the target key group and the identifier of the target key, sequentially generate the encrypted data byte length field, the encryption algorithm field, the key group identifier field and the key identifier field to form control data; wherein the encrypted characters include the encrypted data bytes and the control data.

[0062] The embodiments of the present application do not specifically limit the encryption algorithm. For example, the Advanced Encryption Standard (AES) algorithm, the SMS4 block cipher algorithm, the Base64 encoding algorithm, etc. can be used as the encryption algorithm.

[0063] Among them, the embodiments of the present application are not limited to generating the encryption algorithm field according to the currently used encryption algorithm. For example, the encryption algorithm field can also be generated according to the currently used encryption algorithm and the corresponding encryption mode (such as counter mode (Counter, CTR), cipher block chaining mode (Cipher Block Chaining, CBC), electronic codebook mode (Electronic Codebook, ECB), etc.).

[0064] Among them, the embodiment of the present application does not make any specific restrictions on the order between the encrypted data bytes and the control data in the encrypted characters. That is to say, in the data structure of the encrypted characters, the control data can be in front and the encrypted data bytes can be in the back, or the encrypted data bytes can be in front and the control data can be in the back.

[0065] The definable control data structure provided in the embodiment of the present application can control the length of the control data to be as small as 1 byte, which can also save storage space and reduce resource consumption.

[0066] It should be understood that, regardless of whether the gateway is independent of the device, it must synchronize information with the module executing the character encryption method on the device, including the key library, the number of bits in each field in the preset data structure, and the specific content indicated by the values ​​of each field. Thus, after the natural language processing system in the device outputs a ciphertext response, the gateway can directly parse the control data and encrypted data bytes from each encrypted character in the ciphertext response, decrypt the encrypted data bytes based on the content indicated by the control data in the same encrypted character, and ultimately obtain a plaintext response.

[0067] In some embodiments, each field in the control data includes a corresponding preset number of bits, and the byte length of the encrypted data byte does not exceed the maximum value that can be represented by the encrypted data byte length field; the byte length of the encrypted data byte includes:

[0068] (1);

[0069] In formula (1), Indicates the byte length of the encrypted data bytes, Related to the encryption algorithm currently in use, Indicates the original byte length of the encrypted data, Indicates the extended byte length, The value of is greater than or equal to 1.

[0070] The following uses the number of bits included in the encrypted data byte length field and the encryption algorithm field in the control data as N and M, respectively, to illustrate the information indicated by these two fields:

[0071] For example, if N=2, if the value of the encrypted data byte length field is "00", it means that the encrypted data byte length is 1; if the value of the encrypted data byte length field is "01", it means that the encrypted data byte length is 2; if the value of the encrypted data byte length field is "10", it means that the encrypted data byte length is 3; if the value of the encrypted data byte length field is "11", it means that the encrypted data byte length is 4.

[0072] For example, if M=4 and the value of the encryption algorithm field is "0000", it means that the currently used encryption algorithm and the corresponding encryption mode are SM4 and CTR respectively; if the value of the encryption algorithm field is "0001", it means that the currently used encryption algorithm and the corresponding encryption mode are SM4 and CBC respectively; if the value of the encryption algorithm field is "0100", it means that the currently used encryption algorithm and the corresponding encryption mode are AES and ECB respectively; if the value of the encryption algorithm field is "1111", it means that the currently used encryption algorithm is AES and SM4.

[0073] For example, if M=2, if the value of the encryption algorithm field is "00", it means that the currently used encryption algorithm and the corresponding encryption mode are SM4 and CTR respectively; if the value of the encryption algorithm field is "01", it means that the currently used encryption algorithm and the corresponding encryption mode are SM4 and ECB respectively; if the value of the encryption algorithm field is "10", it means that the currently used encryption algorithm and the corresponding encryption mode are AES and CTR respectively; if the value of the encryption algorithm field is "11", it means that the currently used encryption algorithm and the corresponding encryption mode are AES and ECB respectively.

[0074] It should be emphasized that the embodiments of the present application are not limited to the number of bits, values ​​and indicated contents of each field in the above examples. The above is only an exemplary description.

[0075] The key group identification field in the control data indicates the key group number of the target key group currently in use. The key group number can be expanded infinitely to ensure global uniqueness. The key identification field in the control data indicates the key number of the target key currently in use. The key number can be expanded infinitely to ensure global uniqueness.

[0076] In the embodiment of the present application, the character mapping relationship can be dynamically updated (it is sufficient to ensure that an original character is uniquely mapped to an encrypted character before and after the update, and an encrypted character is also uniquely mapped to an original character). When the character mapping relationship is updated, the locally stored character mapping table is synchronously updated to ensure that the character mapping table is also kept up to date in real time. Accordingly, in some embodiments, the locally stored character mapping table is updated based on the character mapping relationship between the original character and the encrypted character (i.e., step S130 involved), such as Figure 3 Shown, including:

[0077] Step S310: For any of the original characters, the character mapped in the locally stored character mapping table is replaced with the encrypted character corresponding to the character mapping relationship.

[0078] It is understandable that the locally stored character map records the mapping relationship between all original characters and corresponding encrypted characters. When the encrypted character corresponding to an original character changes, the mapped character needs to be updated in the character map.

[0079] It is understood that the character mapping relationship includes both the forward mapping relationship from the original character to the encrypted character (for example, represented as , 、 Representing encrypted characters and encrypted original characters respectively), and also including the reverse mapping relationship from encrypted characters to original characters (for example, represented as Although the locally stored character mapping table is updated based on the forward mapping relationship in the embodiment of the present application, the applicant of the present application also proposes that the reverse mapping relationship of each historical version (i.e., the reverse mapping relationship obtained each time step S120 is executed) can be stored. In this way, the locally stored character mapping table can be rolled back to the version before any key switch based on the reverse mapping relationship. Through this lightweight parameter update mechanism, it is possible to support second-level switching and version rollback, thereby improving disaster tolerance and processing efficiency.

[0080] The applicant of this application further proposes that key switching conditions can be formulated based on a variety of factors. Accordingly, in some embodiments, the key switching conditions include any of the following: key lifecycle expiration conditions, security policy update conditions, preset policy dynamic adjustment conditions, key usage frequency conditions, character processing quantity conditions, external instruction trigger conditions, resource load perception conditions, and user behavior pattern conditions.

[0081] Among them, the key life cycle termination conditions, security policy update conditions, and preset policy dynamic adjustment conditions are all related to the key aging algorithm; the key usage frequency conditions are related to the key usage frequency; the character processing quantity conditions are related to the number of characters processed continuously by a certain key; and the external instruction trigger condition refers to the receipt of an external input key switching instruction.

[0082] Accordingly, in some embodiments, the key lifecycle termination condition includes: the current key validity period ends; the key validity period is determined by the following key aging algorithm:

[0083] (2);

[0084] In formula (2), Indicates the current key validity period. Indicates the current security level and the value is an integer. Indicates the usage frequency of the current target key. and Indicates a preset constant.

[0085] It can be understood that the "current" in formula (2) refers to the time when the key validity period is calculated based on formula (2).

[0086] Among them, the embodiment of the present application is about the security level The value range of is not specifically limited. For example, the security level The value range of can be [1,5].

[0087] Accordingly, in some embodiments, the security policy update condition includes any of the following: 、 and Updated, added key geographical location restrictions, and enabled quantum-resistant encryption algorithms;

[0088] The preset strategy dynamic adjustment conditions include: The update of leads to the update of T.

[0089] Security policy updates refer to the modification or upgrading of established security rules, parameters, or processes based on external environmental changes (such as escalating security threats or adjusted business needs) or internal state changes (such as system resource load or changes in user permissions). The core goal is to dynamically adapt to new security requirements and ensure the system maintains optimal protection.

[0090] In the embodiment of the present application, the calculation of the key validity period depends on the security level in the key aging algorithm. and preset constants 、 , when the security policy is updated, you can adjust 、 、 For example, in a financial transaction scenario, if an abnormal attack behavior is detected, the system can proactively increase the security level (for example, from S=3 to S=5), thereby shortening the key validity period and enhancing anti-cracking capabilities. 、 , it can be adjusted according to industry standards (for example, switching from general data encryption to medical privacy protection). Adjust a to control the sensitivity of the security level, and adjust b to balance the impact of usage frequency to adapt to the security needs of different scenarios.

[0091] The embodiments of the present application are not limited to security policy updates. Security policy updates can also include geo-location restrictions (e.g., prohibiting access from overseas IP addresses), which can also trigger a key switch, restricting the key to only be effective in a specific region. For another example, a security policy update can also force the use of quantum-resistant encryption algorithms when a quantum computing threat is detected, which can also trigger a key switch.

[0092] It is understandable that after the security policy is updated, the gateway and this device will automatically synchronize the latest version of the character mapping relationship.

[0093] The embodiments of the present application can flexibly respond to new attack methods (such as quantum computing, side-channel attacks) or compliance requirements (such as GDPR, HIPAA) through security policy updates, avoiding security vulnerabilities caused by fixed policies.

[0094] Among them, dynamic adjustment of preset strategies refers to automatically adjusting preset strategy parameters or rules based on real-time operating status (such as load, performance indicators) or external input (such as user instructions, environmental sensor data) to optimize resource utilization efficiency or security. Its characteristics are that no manual intervention is required, and the adjustment process conforms to the predefined logical framework. In the embodiment of the present application, the key aging algorithm adaptively and dynamically adjusts the strategy parameters, and the key validity period and the frequency of key usage The relationship is logarithmic, which avoids a sudden drop in validity due to high-frequency use (e.g. When the key lifecycle increases from 100 to 1000 times per second, the validity period is reduced by only log(10) times. This design dynamically adjusts the key lifecycle through preset policies, balancing security and availability.

[0095] It is understandable that if a security policy update, dynamic adjustment of a preset policy, etc., causes a key conflict, the character mapping table can be quickly rolled back to a stable state based on the character reverse mapping relationship of the historical version.

[0096] Accordingly, in some embodiments, the key usage frequency condition includes: the usage frequency of the current target key exceeds a preset frequency threshold;

[0097] The character processing quantity condition includes: encrypting a preset number of consecutive original characters according to the current target key.

[0098] For example, when N consecutive original characters have been encrypted according to the current target key, the target key group is automatically switched, and the target key is selected in rotation according to the Fibonacci sequence algorithm within the switched target key group.

[0099] In addition, resource load awareness and user behavior pattern conditions are both scenario-based policy switching conditions. Resource load awareness means that if the processor load exceeds a threshold (e.g., CPU usage > 80%), a dynamic switch to a low-computational-overhead encryption algorithm (e.g., switching from SM4 to ChaCha20) is detected, while simultaneously shortening the key validity period to compensate for security losses. User behavior pattern conditions dynamically adjust the key switching frequency based on the key validity period selected by the user (e.g., enabling short-term keys for high-frequency chatbot interactions and using long-term keys for low-frequency document generation tasks).

[0100] As a second aspect of the embodiments of the present application, an electronic device is provided, wherein, Figure 4 As shown, the electronic device includes:

[0101] One or more processors 101;

[0102] The memory 102 stores one or more computer programs. When the one or more computer programs are executed by the one or more processors 101, the one or more processors 101 implement the character encryption method provided in the first aspect of the embodiment of the present application.

[0103] The electronic device may further include one or more I / O interfaces 103 connected between the processor 101 and the memory 102 and configured to implement information exchange between the processor 101 and the memory 102 .

[0104] Among them, the processor 101 is a device with data processing capabilities, including but not limited to a central processing unit (CPU); the memory 102 is a device with data storage capabilities, including but not limited to random access memory (RAM, more specifically such as SDRAM, DDR, etc.), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), and flash memory (FLASH); the I / O interface (read-write interface) is connected between the processor and the memory, and can realize information exchange between the processor and the memory, including but not limited to a data bus (Bus), etc.

[0105] In some embodiments, the processor 101 , the memory 102 , and the I / O interface 103 are connected to each other via a bus 104 , and further connected to other components of the computing device.

[0106] As a third aspect of the embodiment of this application, Figure 5 As shown, a computer-readable medium is provided, on which a computer program is stored, wherein when the computer program is executed by a processor, the character encryption method provided in the first aspect of the embodiment of the present application is implemented.

[0107] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program. Accordingly, the computer program can be stored in a non-volatile computer-readable storage medium, and when the computer program is executed, it can implement the method of any of the above-mentioned embodiments. Among them, any reference to memory, storage, database or other media used in the embodiments provided in the embodiments of the present application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0108] The above are only specific embodiments of the present application, but the scope of protection of the present application is not limited thereto. Those skilled in the art should understand that the present application includes but is not limited to the contents described in the drawings and the above specific embodiments. Any modifications that do not deviate from the functional and structural principles of the present application are included within the scope of the claims.

Claims

1. A character encryption method, characterized in that: The method comprises: When a key switching condition is met, determining a target key group after switching and a target key in the target key group from a pre-built key library; wherein the key library includes a first preset number of key groups, and the key group includes a second preset number of keys; Encapsulating, according to the target key group, the target key and the original character, an encrypted character conforming to a preset data structure; updating a locally stored character mapping table according to a character mapping relationship between the original character and the encrypted character, so that a gateway associated with the device converts a plaintext prompt word sent by the user device into a ciphertext prompt word based on the updated character mapping table; Inputting the ciphertext prompt word into a natural language processing system encrypted based on the character mapping relationship to obtain a ciphertext response output by the natural language processing system, so that the gateway decrypts the ciphertext response to obtain a plaintext response, and sends the plaintext response to the user device; The encapsulating, according to the target key group, the target key and the original character, to obtain an encrypted character conforming to a preset data structure comprises: Generate encrypted data bytes based on the target key and the original characters; According to the byte length of the encrypted data bytes, the currently used encryption algorithm, the identifier of the target key group and the identifier of the target key, the encrypted data byte length field, the encryption algorithm field, the key group identification field and the key identification field are generated in sequence to form control data; wherein the encrypted characters include the encrypted data bytes and the control data.

2. The method according to claim 1, characterized in that Each field in the control data includes a corresponding preset number of bits, and the byte length of the encrypted data byte does not exceed the maximum value that can be represented by the encrypted data byte length field; the byte length of the encrypted data byte includes: (1); In formula (1), Indicates the byte length of the encrypted data bytes, Related to the encryption algorithm currently in use, Indicates the original byte length of the encrypted data, Indicates the extended byte length, The value of is greater than or equal to 1.

3. The method according to claim 1, characterized in that The updating of the locally stored character mapping table according to the character mapping relationship between the original character and the encrypted character includes: For any of the original characters, the character mapped in the locally stored character mapping table is replaced by the encrypted character corresponding to the character mapping relationship.

4. The method according to any one of claims 1 to 3, characterized in that The key switching conditions include any of the following: key life cycle termination conditions, security policy update conditions, preset policy dynamic adjustment conditions, key usage frequency conditions, character processing quantity conditions, external instruction triggering conditions, resource load perception conditions, and user behavior pattern conditions.

5. The method according to claim 4, characterized in that The key lifecycle termination condition includes: the current key validity period ends; the key validity period is determined by the following key aging algorithm: (2); In formula (2), Indicates the current key validity period. Indicates the current security level and the value is an integer. Indicates the usage frequency of the current target key. and Indicates a preset constant.

6. The method according to claim 5, characterized in that The security policy update condition includes any of the following: 、 and Updated, added key geographical location restrictions, and enabled quantum-resistant encryption algorithms; The preset strategy dynamic adjustment conditions include: The update of leads to the update of T.

7. The method according to claim 4, characterized in that The key usage frequency condition includes: the usage frequency of the current target key exceeds a preset frequency threshold; The character processing quantity condition includes: encrypting a preset number of consecutive original characters according to the current target key.

8. An electronic device, characterized in that: The electronic device comprises: one or more processors; A memory having one or more computer programs stored thereon, wherein when the one or more computer programs are executed by the one or more processors, the one or more processors implement the character encryption method according to any one of claims 1 to 7.

9. A computer-readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the character encryption method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Homomorphic encryption method of deep learning model for natural language processing

    CN115987479A