Secret key packaging encryption method and electronic equipment
By converting non-confidential data into vectors and combining block encryption and message authentication code encryption algorithms to pad and encrypt confidential data, the problems of low key transmission efficiency and insufficient security in existing technologies are solved, and efficient and secure key transmission is achieved.
Patent Information
- Application Number
- CN202511874330.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-12
- Publication Date
- 2026-03-03
AI Technical Summary
In existing technologies, encryption efficiency during key transmission is low, and sensitive attribute information is not protected, making it vulnerable to attacks.
A key-packaging encryption method is adopted, which converts non-confidential data into a vector, combines block encryption and message authentication code encryption algorithms to pad and encrypt confidential data, generates encryption key data, and performs integrity verification during transmission.
It improves the efficiency and security of key transmission, reduces computation time and resource consumption, simplifies encryption steps, and enhances key security during transmission.
Smart Images

Figure CN121603283A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of key transmission, and more particularly to a key packet encryption method and electronic device. Background Technology
[0002] During key transmission, the key needs to be encrypted to ensure security. The encryption methods in related technologies require a large number of keys and a long encryption process, resulting in low encryption efficiency. Summary of the Invention
[0003] The technical problem to be solved by the present invention is to provide a key packaging and encryption method and an electronic device to achieve a more efficient key packaging process.
[0004] To solve the above-mentioned technical problems, the present invention adopts the following technical solution: A key-packaging encryption method, applied to an electronic device, the method comprising: Obtain the key data to be encrypted and the key block encryption key, wherein the key data to be encrypted includes confidential data and non-confidential data; Convert the non-confidential data into a vector; After filling in the confidential data, the filled data is obtained. The padding data, the vector, and the key block encryption key are input into the encryption algorithm to obtain the encryption key data.
[0005] To solve the above-mentioned technical problems, another technical solution adopted by the present invention is as follows: An electronic device includes a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor executes the computer program to implement the steps of the aforementioned key-packaging encryption method.
[0006] The beneficial effects of this invention are as follows: This application obtains the key data to be encrypted and the key block encryption key. The data to be encrypted includes confidential data and non-confidential data. The vector converted from the non-confidential data is used as the parameter for encrypting the confidential data. The confidential data is encrypted by combining the key block encryption key and the encryption algorithm to complete the encryption process and obtain the encryption key data. In this process, since the encryption algorithm of this application combines block encryption and message authentication code encryption to achieve data encryption and integrity verification, this application does not need to perform an additional key derivation process for the key block encryption key. It can generate ciphertext and MAC in one operation, reducing the computation time and resource consumption, improving the key protection efficiency, thereby simplifying the encryption steps and speeding up the encryption efficiency.
[0007] Furthermore, this application pads the confidential data that needs to be encrypted so that the length of the padded confidential data conforms to the encryption length of the key block encryption key, while also obfuscating the actual length of the confidential data, thereby further improving the security of the key data during transmission and balancing efficiency and security. Attached Figure Description
[0008] Figure 1 A flowchart illustrating the steps of a key packaging and encryption method provided in an embodiment of the present invention; Figure 2 This is a schematic diagram illustrating a process of generating a key transmission packet based on a key block encryption key, provided by an embodiment of the present invention. Figure 3 A schematic diagram illustrating the process of generating a key block encryption key from a key block protection key, as provided in an embodiment of the present invention. Figure 4 This is a schematic diagram illustrating the process of deriving an integrity protection key from a key block protection key, as provided in an embodiment of the present invention. Figure 5 A flowchart illustrating the steps of a key packaging and encryption method provided by an embodiment of the present invention in a real-world scenario. Figure 6 This is a schematic diagram of the structure of a key transmission packet provided in an embodiment of the present invention; Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0009] To make the technical problems, technical solutions, and beneficial effects to be solved by this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and are not intended to limit the scope of this application.
[0010] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.
[0011] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.
[0012] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0013] In related technologies, the key is the most important data in electronic devices, especially financial devices such as POS terminals. The security of the key determines the security of the entire payment system. The key needs to be transmitted to the electronic device during manufacturing or subsequent maintenance for its use. However, it is difficult to guarantee the security of the physical environment in which the electronic device is located during maintenance. The remote key transmission methods in related technologies often only encrypt the plaintext of the key, such as using symmetric algorithms. Other key attributes, especially sensitive key-related information such as the algorithm corresponding to the key, its purpose, and length, are not protected, thus providing a vulnerability for attackers. If an attacker tamperes with the sensitive attributes of the key, it will compromise the key's security. Furthermore, in the process of encrypting and transmitting the key, related technologies typically derive a key block encryption key and an integrity protection key from a key block protection key. The key block encryption key is used to encrypt the key, and the integrity protection key is used to generate an integrity authentication code containing the transmitted data of the key. This indicates that an additional key derivation process is required, prolonging the encryption process.
[0014] To address the aforementioned problems, this application provides a key packaging and encryption method. The key packaging and encryption method of this application is described in detail below.
[0015] The key packet encryption method described in this application can be used in electronic devices that need to receive or send keys, such as various hosts capable of key distribution. The electronic devices in this application can be financial electronic devices, such as cash registers, POS machines, and key distribution devices.
[0016] The following describes a key packaging and encryption method of the present invention in detail, with reference to the appendix. Figure 1 This includes steps 110-140.
[0017] Step 110: Obtain the key data to be encrypted and the key block encryption key. The key data to be encrypted includes confidential data and non-confidential data.
[0018] Confidential data can be keys and sensitive attributes related to keys, such as key length; non-confidential data can be non-sensitive attributes of keys, such as key indexes. In electronic devices with many keys, the corresponding key can be quickly found using the key index.
[0019] Step 120: Convert non-confidential data into vectors.
[0020] Non-confidential data can be converted into a vector by calculating a hash value or using other binarization methods, ensuring the randomness of the parameters required for encryption. For example, please refer to... Figure 2 The hash value corresponding to the non-confidential data is calculated using the SHA256 algorithm, and the hash value is used as the vector IV.
[0021] Step 130: After filling in the confidential data, the filled data is obtained.
[0022] The filling method can use standard filling algorithms such as PKCS#5 and PKCS#7, or generate corresponding random numbers for filling each time confidential data needs to be filled.
[0023] Step 140: Input the padding data, vector, and key block encryption key into the encryption algorithm to obtain encryption key data. The encryption algorithm combines block encryption and message authentication code encryption to achieve data encryption and integrity verification.
[0024] Since the vector is derived from non-confidential data, the result calculated by the encryption algorithm can not only verify confidential data but also assist in verifying non-confidential data. If the non-confidential data received by the receiver changes, the corresponding vector will also change, and the confidential data cannot be successfully decrypted, thus failing to achieve integrity verification.
[0025] Through steps 110 to 140, for the key data to be encrypted, the non-confidential data is used as a parameter in the encryption process of the confidential data. Therefore, the decryption process also needs to be completed using the non-confidential data, thus verifying whether the non-confidential data has been tampered with. At the same time, the confidential data is padded and then encrypted using the vector generated from the non-confidential data and the key block encryption key, which obfuscates the original length of the confidential data, thereby improving the security of the confidential data during transmission. Even if the confidential data is intercepted, it is impossible to obtain the original length of the confidential data and to parse out the complete readable information. Furthermore, by inputting the padded data after the confidential data is padded, the vector corresponding to the non-confidential data, and the key block encryption key into the encryption algorithm, the padded data is encrypted into encryption key data without the need for a key derivation process, thus ensuring the efficiency of key encryption while ensuring security.
[0026] Please refer to Figure 3 as well as Figure 4 This provides an explanation of the key derivation process in related technologies. (Refer to...) Figure 2 Using the Key Block Protection Key (KBPK) as the base key for the key derivation algorithm, and taking the first key derivation data 01 00 00 00 00 04 01 00 and the second key derivation data 02 00 00 00 00 04 0100 as input data for the algorithm, the first key block encryption key and the second key block encryption key are obtained respectively. The first key block encryption key and the second key block encryption key are then concatenated to obtain the Key Block Encryption Key (KBEK). (Refer to...) Figure 3 Using the key block protection key as the base key for the key derivation algorithm, and taking the third key derivation data 01 00 01 00 00 04 01 00 and the fourth key derivation data 02 00 01 00 0004 01 00 as input data for the key derivation algorithm, the first integrity protection key and the second integrity protection key are obtained respectively. The first integrity protection key and the second integrity protection key are then concatenated to obtain the integrity protection key (KeyBlock MAC Key, KBAK). It is evident that if the key block encryption key and the integrity protection key are generated separately through key derivation, it requires four additional key derivation data inputs, four key derivation processes, and two key concatenation processes. To ensure the security of data transmission, especially for key transmission, a one-time pad approach is usually used. Therefore, the key derivation process needs to be repeated for each transmission, reducing the efficiency of key transmission. However, by combining block encryption and message authentication code encryption, only one key is needed to complete the encryption process and the integrity authentication code generation process, eliminating the key derivation process and thus improving encryption efficiency.
[0027] In one embodiment of this application, step 120 includes steps 121 to 122.
[0028] Step 121: Calculate the hash value corresponding to the non-confidential data.
[0029] If non-confidential data changes, its corresponding hash value will also change accordingly, thus ensuring the randomness of the hash value and thereby improving the security of encryption.
[0030] Step 122: Treat the hash value as a vector.
[0031] The calculated hash value is already in numerical form, so it can be used directly as a vector.
[0032] In this way, the hash value calculated from non-confidential data is used as a vector, and this vector participates in the encryption process of confidential data. Correspondingly, if the non-confidential data is tampered with during the decryption process, the calculated vector will also change, and the decryption of confidential data cannot be completed. This achieves simultaneous verification of non-confidential and confidential data.
[0033] In one embodiment of this application, step 130 includes steps 1311 to 1313.
[0034] Step 1311: Determine the current key length range based on the attribute information of the key block encryption key.
[0035] The key block encryption key has a corresponding encryptable unit length. The length of the information to be encrypted needs to correspond to the encryptable unit length to ensure that the key block encryption key completes the correct encryption process to obtain the encryption key data. Furthermore, the corresponding encryption unit is different depending on the key block encryption key. Therefore, the current key length range here is the length range of the data that the key block encryption key can encrypt.
[0036] Step 1312: Determine the current key length based on the length of the confidential data and the current key length range.
[0037] The length of confidential data must be the length that the key block encryption key can encrypt; therefore, the length of confidential data must conform to the current key length range corresponding to the key block encryption key.
[0038] Step 1313: Add random numbers to the confidential data to fill the block, so that the length of the confidential data after block filling is the same as the current key length.
[0039] By adding randomness to the padding, the random number generated each time confidential data is encrypted is different, which increases the difficulty of cracking and thus ensures the security of the key transmission process.
[0040] In this way, the current key length range is first determined based on the attribute information of the key block encryption key, that is, the length range of data that the key block encryption key can encrypt. Then, the length of the data to be filled in for the confidential data is determined based on the length of the confidential data and the current key length range, so that the filled data meets the current key length range. During the filling process, random numbers are used to increase randomness and prevent data of the same length from being filled with the same data. If the same data is filled in, an attacker can deduce the actual length of the confidential data by intercepting multiple data. However, if the data filled in each time is random, even if the attacker intercepts multiple data, he cannot determine the end position of the confidential data, thereby improving the security of the key transmission process.
[0041] In one embodiment of this application, the confidential data includes a key and key-related data; step 130 also includes steps 1321 to 1322.
[0042] Step 1321: Obtain the key algorithm corresponding to the key, and determine the maximum key length based on the key algorithm.
[0043] Step 1322: Fill the key by adding random numbers to make the length of the filled key the same as the maximum key length. After obtaining the updated confidential data, proceed to step 1311.
[0044] In this method, the key within the confidential data is padded before being padded to the confidential data itself. During the padded process, the maximum key length is determined based on the key algorithm corresponding to the key, and the key is padded to the maximum key length. Therefore, even if the key algorithm is obtained, the actual key length cannot be determined, thus further protecting the key and obfuscating its length to enhance security during key transmission. Furthermore, after key padded, the confidential data is further padded with blocks. This not only hides the length of the key itself but also the length of sensitive attributes related to the key, preventing the leakage of sensitive attributes from affecting key security and further ensuring the security of the key transmission process.
[0045] In one embodiment of this application, step 1313 includes steps 1301 and 1302.
[0046] Step 1301: Generate random bytes in the range of 0x00 to 0xFF.
[0047] Step 1302: Add random bytes to the confidential data for block padding.
[0048] For example, if the key block encryption key in step 1311 corresponds to the AES algorithm, then the current key length range is an integer multiple of 16 bytes, including 16 bytes, 32 bytes, 48 bytes, 64 bytes, etc. In step 1312, if the length of the confidential data is 24 bytes, then the integer multiple of the length unit closest to and greater than the length of the confidential data is obtained. For example, the integer multiple of 16 bytes closest to and greater than 24 bytes is 32 bytes, so the current key length is determined to be 32 bytes. In step 1313, the confidential data is padded from 24 bytes to 32 bytes. The length of the random bytes to be generated can be determined by the difference between the current key length and the length of the confidential data. Then, random bytes of the corresponding length are generated in the range of 0x00 to 0xFF. The generated random bytes are added to the confidential data for block padding, so that the length of the padded confidential data reaches the current key length.
[0049] The same method can be used to fill random numbers in step 1322. After generating random bytes in the range of 0x00 to 0xFF, random bytes are added to the key to fill the key, so that the length of the filled key is the same as the maximum key length.
[0050] For example, if the key algorithm corresponding to the key in step 1321 is the TDES algorithm, and the maximum key length is 24 bytes, then in step 1322, a 16-byte random number is used to pad the key to a length of 24 bytes. In step 1322, the length of the random bytes to be generated can be determined by the difference between the maximum key length and the key length. Then, random bytes of the corresponding length are generated within the range of 0x00 to 0xFF to pad the key, so that the length of the padded key reaches the maximum key length.
[0051] This method avoids the problem of using the same padding algorithm (PKCS#5, PKCS#7) to pad with the same key, where the same data is always filled in. If the same key is always padded with the same data, the plaintext key and padding will be identical each time the same key is encrypted, resulting in identical ciphertext. If an attacker obtains a specific plaintext key and its corresponding ciphertext, they can check whether the receiving electronic device (e.g., a POS machine) stores the corresponding ciphertext, thus increasing the risk of attack. However, by generating random bytes within a larger range, the random bytes obtained for each padding will be different. This means that even with data of the same length, the final padding will use different random bytes, reducing the risk of the key data being cracked by an attacker. Furthermore, not only is the key length obfuscated through padding, but the key and key-related data are also obfuscated through padding. The random number used for padding is randomly generated each time. Therefore, even if the same plaintext data is encrypted with the same key each time, the encrypted ciphertext will be different each time because the padding data is different. This makes it impossible to know which keys are stored in the electronic device that received the key, thus further protecting the security of the key.
[0052] Please refer to Figure 2 In one embodiment of this application, step 140 includes step 141.
[0053] Step 141: Input the padding data, the initialization vector (IV), and the KeyBlock Encryption Key (KBEK) into the encryption algorithm to obtain the encrypted data (confidential data ciphertext) corresponding to the padding data and the Message Authentication Code (MAC) corresponding to the key data to be encrypted. The padding data includes the plaintext confidential data.
[0054] The encryption algorithm can be AES-GCM (Advanced Encryption Standard - Galois / Counter Mode), which can generate ciphertext and MAC in a single operation, thus reducing computation time and resource consumption. The AES-GCM algorithm uses the counter mode of the AES block cipher to encrypt data. Its counter mode combines a counter with the AES algorithm to generate a pseudo-random bitstream, which is then XORed with the confidential data to be encrypted to achieve encryption. Simultaneously, the Galois / Counter mode (GCM) is used to generate a message authentication code to verify the integrity and authenticity of the data. Therefore, the AES-GCM algorithm processes the encryption and message authentication code generation processes in parallel, resulting in fast encryption and decryption speeds. Furthermore, because it can generate both encryption and the message authentication code in a single computation, the implementation process is relatively simple, easy to understand and implement, and can resist most known attacks. At the same time, obtaining the initialization vector from non-confidential data ensures the uniqueness of the initialization vector, preventing replay attacks and thus improving security.
[0055] In this way, the integrity authentication code is calculated while the confidential data is being encrypted using the encryption algorithm. This eliminates the need to derive the encryption key from the key block and instead generates separate keys for the encryption process and the integrity authentication code generation process, thereby improving the efficiency of the encryption process.
[0056] In one embodiment of this application, step 140 is followed by step 150.
[0057] Step 150: Package the non-confidential data, encrypted key data, and integrity authentication code into a key transfer packet.
[0058] In this way, the key transmission process is completed in the form of key transmission packets. The receiver can first complete the integrity authentication process based on the integrity authentication code in the key transmission packet. If the integrity authentication is successful, the encrypted key data is decrypted to obtain confidential data, and the key is read from the confidential data and saved. If the integrity authentication code verification fails, it is considered that the key transmission packet has been tampered with, and the data in it is not decrypted to avoid receiving tampered data and ensure the security of the saved key.
[0059] In one embodiment of this application, steps 101 to 102 are also included.
[0060] Step 101: Obtain the key index and key attributes corresponding to the key data to be encrypted.
[0061] Step 102: Concatenate the key index and key attributes to obtain unencrypted data.
[0062] In this way, key indexes and non-sensitive key attributes are transmitted directly in plaintext, reducing the amount of data that needs to be encrypted during the encryption process, thereby improving encryption efficiency. Furthermore, the key index can accelerate the key retrieval process when a key is needed, and financial terminals that store a large number of keys can quickly locate the key required for the process.
[0063] In one embodiment of this application, step 121 includes calculating the hash value corresponding to the non-confidential data using the SHA256 algorithm.
[0064] In this way, the SHA256 algorithm outputs a fixed-length hash value, which can be directly converted into a vector for use. Subsequent operations are simple. Furthermore, the SHA256 algorithm outputs a 32-byte hash value, which has an extremely low collision probability. This ensures randomness even when the input non-confidential data is different, thereby improving the security of the encryption process and guaranteeing the security of the key transmission process.
[0065] In summary, this application directly encrypts the padded confidential data using vectors, key block encryption keys, and encryption algorithms to obtain encryption key data. The vectors used are converted from non-confidential data, integrating this data into the encryption process. This eliminates the need to derive the key block encryption key and integrity protection key through key derivation algorithms, thus simplifying the key encryption process and improving its efficiency. Encryption using the AES-GCM algorithm allows for the simultaneous generation of encryption key data and integrity authentication codes via the key block encryption key during the encryption process. This eliminates the need to derive separate key block encryption keys and integrity protection keys for the confidential data encryption and integrity protection processes, improving computational efficiency. Furthermore, before encryption, the key in the confidential data is padded with the maximum key length corresponding to the key algorithm, hiding the actual key length and reducing the probability of key leakage. Additionally, block padding is performed on the padded confidential data. Block padding ensures that the padded confidential data conforms to the current key length range corresponding to the key block encryption key, enabling successful encryption while also hiding the actual length of the confidential data, further enhancing key security during transmission.
[0066] The following describes specific application examples of this application. This application can apply the above scheme to the key distribution process, such as the key distribution process of a key distribution device with key distribution capabilities. Please refer to... Figure 5 The following details steps 210 to 270.
[0067] Step 210: Obtain non-confidential data, which includes the non-confidential information of the key and key block. This data is transmitted in plaintext without encryption. This is equivalent to step 110 above.
[0068] The non-confidential data includes the index and the configuration algorithm. The index can be a unique identifier (ID) for the key.
[0069] Step 220: Obtain confidential data. Confidential data includes the key itself and its corresponding sensitive attributes, such as key length. This is equivalent to step 110 above.
[0070] The key length can be stored directly as the key length itself; for example, if the key length is 8 bytes, it can be stored as "8 bytes". Alternatively, it can store a key length identifier, which is an identifier agreed upon by the receiver and sender for the key length. For example, 1 indicates "4 bytes" and 2 indicates "8 bytes". In this way, the key length is not directly displayed in confidential data, but rather indicated by the key length identifier. Step 230: Obtain the key algorithm corresponding to the key, determine the maximum key length based on the key algorithm, and fill the right side of the key with random numbers until the maximum key length is reached. This is equivalent to step 130 above.
[0071] For example, if the key algorithm is TDES (Triple Data Encryption Standard), its maximum key length is 24 bytes. If the key length is 8 bytes, 16 bytes of random numbers will be added to the right side of the key until a 24-byte key is obtained. Furthermore, the right-side padding here is just an example; padding can also be done on the left or both sides, as long as this is agreed upon beforehand with the receiving end to ensure that the receiving end can obtain the corresponding key based on the key length identifier.
[0072] Step 240: Obtain the key block encryption key. Based on the current key length range of the algorithm corresponding to the key block encryption key, perform block padding on the padded key and the corresponding sensitive attributes to obtain the padded data. This is equivalent to step 130 above.
[0073] For example, if the encryption key for a key block uses the AES algorithm, and its current key length is a multiple of 16 bytes, then the padding data after block padding needs to be a multiple of 16 bytes to complete the encryption process. Therefore, the padded key and its corresponding sensitive attributes need to be padded to a multiple of 16 bytes before proceeding with subsequent operations. To save computational resources, the total length of the sensitive data and the padded key can be obtained first. The closest multiple of 16 bytes to this total length can then be used as the current key length to complete the block padding process. This achieves the effect of obfuscating the actual data length while reducing the amount of padded data, thereby speeding up the data processing flow and reducing the amount of data that needs to be transmitted.
[0074] For example, if the encryption key of the key block corresponds to the AES algorithm, the total length of the padded key and the corresponding sensitive attributes of the key is 24 bytes. The nearest multiple of 24 bytes, which is 16 bytes, is 32 bytes. Therefore, the block padded process is completed with 32 bytes as the current key length, and the length of the padded data after padded is 32 bytes.
[0075] Step 250: Calculate the hash value of the non-confidential data, which will be used as one of the input data for the encryption algorithm: the initialization vector (IV). This is equivalent to step 120 above.
[0076] Among them, hash value algorithms can be used to calculate the hash value corresponding to non-confidential data, such as using the SHA256 algorithm to calculate the hash value corresponding to non-confidential data.
[0077] Step 260: Input the key block encryption key, initialization vector, and padding data into the encryption algorithm to obtain the encryption key data corresponding to the padding data and the Message Authentication Code (MAC). This is equivalent to step 140 above.
[0078] Since the initial vector is obtained from non-confidential data, the integrity authentication code can simultaneously verify the integrity of both the non-confidential and padding data. Therefore, a key derivation algorithm is unnecessary. Unlike existing technologies that require two separate calculations to generate the encryption and integrity authentication codes, this method only requires a single calculation to obtain both the encryption key and the integrity authentication code, thus accelerating the encryption process and improving data processing efficiency.
[0079] Step 270: Package the non-confidential data, encryption key data, and integrity authentication code into a key transmission packet, which will be used as the final key data stored in the electronic device. This is equivalent to step 150 above.
[0080] Reference Figure 6 This is an example of the format of the final key transmission packet obtained in this application, including a key block header, confidential data ciphertext, and an integrity protection value (Message Authentication Code, MAC). The key block header (KBH) includes a fixed header, additional information (including key index and key attributes), and key block header padding. The key block header contains the key and non-sensitive attribute information of the key block, which is transmitted in plaintext and is not encrypted. The fixed header has a fixed length, while the additional information and key block header padding are optional, and the length of the optional items is variable. The fixed header is confirmed according to the message format used for transmission, and it is agreed with the receiver that the information in the key transmission packet can be read normally.
[0081] Please refer to Figure 7 The present invention also provides an electronic device 300, including a memory 301 and a processor 302, and a computer program stored on the memory 301 and running on the processor 302. When the processor 302 executes the computer program, it implements the various steps in the key packing encryption method described above.
[0082] The beneficial effects of the electronic device of the present invention are the same as those of the method described above, and will not be repeated here.
[0083] The above are merely embodiments of the present invention and do not limit the patent scope of the present invention. Any equivalent modifications made based on the content of the present invention's specification and drawings, or direct or indirect applications in related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A key packaging and encryption method, characterized in that, Applied to electronic devices, the method includes: Obtain the key data to be encrypted and the key block encryption key, wherein the key data to be encrypted includes confidential data and non-confidential data; Convert the non-confidential data into a vector; After filling in the confidential data, the filled data is obtained. The padding data, the vector, and the key block encryption key are input into the encryption algorithm to obtain encryption key data. The encryption algorithm combines block encryption and message authentication code encryption to achieve data encryption and integrity verification.
2. The key packaging and encryption method according to claim 1, characterized in that, The step of converting the non-confidential data into a vector includes: Calculate the hash value corresponding to the non-confidential data; The hash value is used as a vector.
3. The key packaging and encryption method according to claim 2, characterized in that, The process of filling in the confidential data to obtain the filled data includes: The current key length range is determined based on the attribute information of the encryption key in the key block; The current key length is determined based on the length of the confidential data and the current key length range. Random numbers are added to the confidential data to fill the blocks, so that the length of the confidential data after block filling is the same as the length of the current key.
4. The key packaging and encryption method according to claim 3, characterized in that, The confidential data includes keys and key-related data; The process of filling in the confidential data to obtain the filled data includes: Obtain the key algorithm corresponding to the key, and determine the maximum key length based on the key algorithm; The key is filled by adding random numbers to it so that the length of the filled key is the same as the maximum key length. After obtaining the updated confidential data, the step of determining the current key length range based on the attribute information of the key block encryption key is executed.
5. The key packaging and encryption method according to claim 3, characterized in that, The step of adding random numbers to the confidential data for block filling includes: Generate random bytes in the range of 0x00 to 0xFF; The random bytes are added to the confidential data for block padding.
6. The key packaging and encryption method according to claim 1, characterized in that, The step of inputting the padding data, the vector, and the key block encryption key into the encryption algorithm to obtain encryption key data includes: The padding data, the vector, and the key block encryption key are input into the encryption algorithm to obtain the encrypted data corresponding to the padding data and the integrity authentication code corresponding to the key data to be encrypted.
7. The key packaging and encryption method according to claim 6, characterized in that, After inputting the padding data, the vector, and the key block encryption key into the encryption algorithm to obtain the encryption key data, the method further includes: The non-confidential data, encrypted data, and integrity authentication code are packaged into a key transmission packet.
8. The key packaging and encryption method according to claim 1, characterized in that, Also includes: Obtain the key index and key attributes corresponding to the key data to be encrypted; The unencrypted data is obtained by concatenating the key index and key attributes.
9. The key packaging and encryption method according to claim 2, characterized in that, The calculation of the hash value corresponding to the non-confidential data includes: The hash value corresponding to the non-confidential data is calculated using the SHA256 algorithm.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor, when executing the computer program, implements each step of the key-packaging encryption method according to any one of claims 1-9.