Data encryption and decryption method based on user identity and user group identity
Through the personalized initial vector generation method based on user identity and user group identity, the problem of insecure initial vector selection in the prior art is solved, and the security and management efficiency of data encryption are improved.
Patent Information
- Application Number
- CN202410745697.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-11
- Publication Date
- 2025-04-04
- Estimated Expiration
- 2044-06-11
AI Technical Summary
In the existing data encryption technology, the selection of initial vectors is not secure enough, which may lead to a reduction in the security of the encryption algorithm and a high management cost.
Based on user identity and user group identity, a personalized initial vector generation method is adopted to calculate the Hash value through user identity identification and group identity identification, and an initial vector is generated through mathematical transformation for the encryption and decryption process.
It improves the actual protection capabilities of the encryption algorithm, ensures differentiation of passwords for different users, enhances security, and reduces management costs.
Smart Images

Figure CN118694513B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data encryption, and in particular to a data encryption and decryption method based on user identity and user group identity. Background Art
[0002] Data encryption is a commonly used technical method for protecting data. There are two major types of data encryption algorithms, namely public key encryption algorithms and symmetric encryption algorithms. The encryption key of the public key encryption algorithm can be made public, called the public key, but the decryption key needs to be kept by the user, called the private key. The public key encryption algorithm is suitable for network platforms that serve a large number of users. The symmetric encryption algorithm requires the encryption party and the decryption party to use the same key, so it involves key management issues and is suitable for use within mutually trusted organizations.
[0003] The basic principle of the symmetric encryption algorithm Enc is: given a key k and a plaintext message m, output a ciphertext c, satisfying the equation c = Enc (k, m). Each symmetric encryption algorithm Enc corresponds to a decryption algorithm Dec, satisfying Dec (c) = Dec (Enc (k, m)) = m, that is, given a key k and a ciphertext c, the decryption algorithm outputs the original plaintext message m.
[0004] In actual use, encryption algorithms are often accompanied by an initialization vector. For example, the cipher block chaining mode (i.e., CBC mode) of a block cipher requires an initialization vector IV equal to the block length, and the counter mode (i.e., CTR mode) of a block cipher requires a counter Ctr, which can also be regarded as an initialization vector. Therefore, during the execution of the encryption algorithm, in addition to providing the algorithm with the encryption key and the encrypted message, an initialization vector IV should also be provided. It should be noted that when decrypting the ciphertext, the same key and the same initialization vector IV need to be provided, so IV cannot use a random number that is lost as it is used.
[0005] For the convenience of operation, some data service platforms may not pay attention to the selection of IV, resulting in the selection of insecure IV, such as an all-zero string. It is also possible that all users use the same initial vector IV, which reduces the security of the encryption algorithm and is not conducive to the differentiation of ciphertexts, that is, the same plaintext corresponds to the same ciphertext. Although the initial vector IV does not need to be kept confidential, a safe way to use it is to let different users use different IVs. However, this will bring more management costs. Summary of the invention
[0006] The purpose of the present invention is to provide a data encryption and decryption method based on user identity and user group identity, propose a personalized initialization vector generation method based on user identity and user group identity, and provide a convenient encryption method based on this, thereby effectively improving the actual protection capability of the encryption algorithm.
[0007] To achieve the above object, the present invention provides a data encryption and decryption method based on user identity, including encrypting a message to obtain a ciphertext and decrypting the ciphertext to obtain a plaintext. In the process, an initial vector used for encryption is generated based on the user identity ID. It is assumed that each user has a unique identity ID, the block length of the encryption algorithm Enc is n, the system original key is k, and the decryption algorithm is Dec.
[0008] When encrypting a message m, the following steps are performed:
[0009] (1) Convert the user's identity ID into a standard binary code and record it as IDcode;
[0010] (2) Use the one-way hash function H to calculate the hash value of IDcode, and obtain h = H (IDcode);
[0011] (3) Use mathematical transformation F to convert h in step (2) into an array of n-bit string length as the initial vector IV, and obtain IV = F(h);
[0012] (4) Using IV as the initial vector and the system original key k or the upgraded key kc related to the user identity ID as the encryption key, the message m is appropriately segmented and encrypted. When the system original key k is used for encryption, the ciphertext c1=Enc(k, IV, m) is obtained. When the upgraded key kc related to the user identity ID is used for encryption, the ciphertext c2=Enc(kc, IV, m) is obtained.
[0013] When decrypting ciphertext c, perform the following steps:
[0014] (1) Convert the user's identity ID into a standard binary code and record it as IDcode;
[0015] (2) Use the hash function H to calculate the hash value of IDcode, and obtain h = H (IDcode);
[0016] (3) Use mathematical transformation F to convert h in step (2) into an array of n-bit string length as the initial vector IV, and obtain IV = F(h);
[0017] (4) Using IV as the initial vector, the ciphertext c is decrypted segment by segment using the decryption key. The decryption key corresponds to the encryption key. When k is used for decryption, the plaintext m1 = Dec (k, IV, c) is obtained; when kc is used for decryption, the plaintext m2 = Dec (kc, IV, c) is obtained.
[0018] The encryption and decryption method of the original system key k only focuses on using different initial vectors when encrypting and decrypting data of different users. In this way, even if two users have the same data, the encrypted ciphertexts are different. However, using the system key k to encrypt data can easily reduce its security due to frequent use of the key. Usually, the system key is only used to generate session encryption keys, so the present invention enhances the security of encryption by upgrading the key kc.
[0019] Preferably, the method for obtaining the upgrade key kc is: using the message authentication code algorithm MAC and the system original key k to calculate MAC (k, IDcode), intercepting the first n bits of the output to obtain the upgrade key kc;
[0020] The method for obtaining the decryption key kc is: use the MAC algorithm and the system original key k to calculate MAC(k, IDcode), intercept the first n bits of the output to obtain the decryption key kc.
[0021] In practical applications, a data processing platform usually serves several users. Some users have certain grouping attributes. For example, users of a smart medical data management center may come from different medical institutions. Users of the same medical institution can be divided into a group, or users with certain attributes can be divided into a group. The present invention only assumes that each user has a unique identity and belongs to a fixed group. This assumption does not affect practical applications. If the user changes the group, it only needs to be noted in the database that records the user information, because the group to which the user belongs is searched based on the user's identity. Considering that each user belongs to a group. In order to avoid the inability to encrypt and decrypt data between different members of the same group, the group identity is used to generate the initial vector used for encryption. The method is as follows:
[0022] The data encryption and decryption method based on user group identity includes encrypting a message to obtain a ciphertext and decrypting the ciphertext to obtain a plaintext. In the process, an initial vector used for encryption is generated based on the user group identity. It is assumed that users belong to different fixed groups, each group has a unique identity identifier GID, and member users belonging to the same group can perform data encryption and decryption operations on each other. Each user has a unique identity identifier ID. The block length of the encryption algorithm Enc is n, the system original key is k, and the decryption algorithm is Dec.
[0023] When encrypting a message m, the following steps are performed:
[0024] (1) Convert the user's identity ID into a standard binary code and record it as IDcode;
[0025] (2) Convert the user group identity GID into a standard binary code, recorded as GIDcode;
[0026] (3) Use the one-way hash function H to calculate the hash value of GIDcode, and obtain h = H (GIDcode);
[0027] (4) Use mathematical transformation F to convert h in step (2) into an array of n-bit string length as the initial vector IV, and obtain IV = F(h);
[0028] (5) Using the IV obtained in step (4) as the initial vector, the message m is appropriately segmented and then encrypted using the encryption key. When the encryption key uses the system original key k, the ciphertext c1=Enc(k, IV, m) is obtained. When the encryption key uses the upgrade key kc related to the user identity ID, the ciphertext c2=Enc(kc, IV, m) is obtained. When the encryption key uses the upgrade key kc related to the user group identity GID, the ciphertext c3=Enc(kc, IV, m) is obtained.
[0029] When decrypting ciphertext c, perform the following steps:
[0030] (1) Convert the user's identity ID into a standard binary code and record it as IDcode;
[0031] (2) Convert the user group identity GID into a standard binary code, recorded as GIDcode;
[0032] (3) Use the hash function H to calculate the hash value of IDcode, and obtain h = H (GIDcode);
[0033] (4) Use mathematical transformation F to convert h in step (2) into an array of n-bit string length as the initial vector IV, and obtain IV = F(h);
[0034] (5) Using IV as the initial vector, the ciphertext c is decrypted segment by segment using the decryption key. The decryption key corresponds to the encryption key. When decrypting with k, the plaintext m1 = Dec (k, IV, c) is obtained; when decrypting with kc, the plaintext m2 = Dec (kc, IV, c) or m3 = Dec (kc, IV, c) is obtained.
[0035] After using the group identity GID to generate the initial vector, members of the same group can perform data encryption and decryption operations with each other. However, using the same system key to encrypt and decrypt user data is not suitable for long-term service. Therefore, the present invention designs an encryption key generation method based on individual user identity to complete data encryption and decryption.
[0036] Preferably, the method for obtaining the upgrade key kc related to the user identity ID is: using the message authentication code algorithm MAC and the system original key k to calculate MAC (k, IDcode), intercepting the first n bits of the output to obtain the upgrade key kc;
[0037] The method for obtaining the corresponding decryption key kc is: use the MAC algorithm and the system original key k to calculate MAC(k, IDcode), intercept the first n bits of the output to obtain the decryption key kc.
[0038] Members belonging to the same group have a higher degree of trust in each other. Group members can encrypt and decrypt data using a public key associated with the user group identity GID to share data information.
[0039] Preferably, the method for obtaining the upgrade key kc related to the user group identity GID is: using the message authentication code algorithm MAC and the system original key k to calculate MAC (k, GIDcode), intercepting the first n bits of the output to obtain the upgrade key kc;
[0040] The method for obtaining the corresponding decryption key kc is: use the MAC algorithm and the system original key k to calculate MAC(k, GIDcode), intercept the first n bits of the output to obtain the decryption key kc.
[0041] Therefore, the present invention adopts a data encryption and decryption method based on user identity in the above steps, and designs an encryption key generation method based on user individual identity and an encryption key generation method based on group identity, respectively, combined with an initial vector generation method based on different identity identifiers to complete data encryption and decryption, thereby effectively improving the protection capability of the algorithm.
[0042] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 This is an encryption process diagram of Embodiment 1 of the data encryption and decryption method based on user identity of the present invention;
[0044] Figure 2 This is an encryption process diagram of Embodiment 2 of the present invention;
[0045] Figure 3 This is a diagram of the encryption process of Example 3 of the present invention. DETAILED DESCRIPTION
[0046] The technical solution of the present invention is further described below through the accompanying drawings and embodiments.
[0047] Example 1
[0048] First, consider how to generate the initial vector for encryption based on the user identity ID and encrypt it with the original system key. This embodiment only explains the encryption process, and its execution steps are as Figure 1 shown. Assume that the system key k is held by the data management platform. The user identity is "Zhang San", the encryption algorithm is the national standard algorithm SM4, and its block length is n = 128 bits. MD5 is used as the Hash function. Then the encryption process is performed as follows:
[0049] (1) Using the UTF8 encoding method, convert "Zhang San" into binary encoding to obtain 5F20 4E09.
[0050] (2) Use the Hash function MD5 to calculate h:
[0051] h = MD5(5F204E09) = E3DA84C9A3EE327EE0D7ED5510D50091.
[0052] (3) Since the output of MD5 is exactly 128 bits, no conversion is required, that is, F is the identity transformation, and we get IV = E3DA84C9A3EE327EE0D7ED5510D50091.
[0053] (4) Use the CBC mode of SM4 to encrypt the message m. It is necessary to input the message m, the initial vector IV, and the system key. The algorithm automatically divides m into 128-bit message blocks and then encrypts them sequentially using the CBC mode of SM4 to obtain the ciphertext c = SM4CBC(k, IV, m).
[0054] Embodiment 2
[0055] Consider the method steps of generating the initial vector for encryption based on the user group identity ID and generating the encryption key using the user identity ID, as Figure 2 shown. Assume that the system key k = "1234abcd" is held by the data management platform. The user identity is "Zhang San", the group identity ID is "Encryption Research Institute", the encryption algorithm is the national standard algorithm SM4, and its block length is n = 128 bits. SHA1 is used as the Hash function. The encryption process is performed as follows:
[0056] (1) Using the UTF8 encoding method, convert "Zhang San" into binary encoding to obtain 5F20 4E09.
[0057] (2) Using the UTF8 encoding method, convert "Encryption Research Institute" into binary encoding to obtain 52A05BC6 78147A76 6240.
[0058] (3) Use the hash function SHA1 to calculate h=SHA1(52A05BC678147A766240)=58DA83BA25C512DFB95F042BCFF3EAB06B7EF4A3.
[0059] (4) Since the output of SHA1 is 160 bits, it needs to be transformed. Let F be the transformation of the first 128 bits, and get IV = F(h) = 58DA83BA25C512DFB95F042BCFF3EAB0.
[0060] (5) Select the HMAC algorithm based on SHA1 as the message authentication code algorithm and calculate first:
[0061] HMAC(1234abcd,5F204E09)=
[0062] 5E1A88B90E3E887237E513BCFCC32B89A1009550,
[0063] Then intercept the first 128 bits as the encryption key and get:
[0064] kc=5E1A88B90E3E887237E513BCFCC32B89.
[0065] (6) To encrypt message m using SM4's CBC mode, you need to input message m, initial vector IV, and key kc. The algorithm automatically divides m into 128-bit message blocks, and then encrypts them one by one using SM4's CBC mode to obtain ciphertext c = SM4CBC (kc, IV, m).
[0066] Example 3
[0067] Consider the case where the initialization vector and encryption key used for encryption are generated based on the user group identity GID, such as Figure 3 As shown. Assume that the system key k = "1234abcd" is controlled by the data management platform. The user identity is "Zhang San", the group identity is "Cryptography Research Institute", the encryption algorithm is the national standard algorithm SM4, and its block length is n = 128 bits. Use SHA256 as the hash function. The encryption process performs the following steps:
[0068] (2) Using the UTF8 encoding method, convert “Cryptography Research Institute” into binary code and obtain 52A05BC6 78147A76 6240.
[0069] (3) Use the hash function SHA256 to calculate h=SHA256(52A05BC678147A766240)=EE7A069EED434D6791F0AD35E1FEE5BFCE3FB9FBB02B0DAAC5E30F52192CE85D.
[0070] (4) Since the output of SHA256 is 256 bits, it needs to be converted. We can define F as follows: divide the 256-bit input into two 128-bit arrays, and perform an XOR operation on the two arrays, that is,
[0071] In this way, we can obtain IV=F(h)=CE3FB9FBB02B0DAAC5E30F52192CE85D.
[0072] (5) Select the HMAC algorithm based on SHA256 as the message authentication code algorithm and first calculate
[0073] HMAC(1234abcd,52A05BC678147A766240)=
[0074] 021371264C3C7D67A7DED4FF770D24F2566C675F70526AAF53EB2639BADDDD7F, and then intercept the first 128 bits as the encryption key to get:
[0075] kc=021371264C3C7D67A7DED4FF770D24F2.
[0076] (6) To encrypt message m using SM4's CBC mode, you need to input message m, initial vector IV, and key kc. The algorithm automatically divides m into 128-bit message blocks, and then encrypts them one by one using SM4's CBC mode to obtain ciphertext c = SM4CBC (kc, IV, m).
[0077] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that they can still modify or replace the technical solution of the present invention with equivalents, and these modifications or equivalent replacements cannot cause the modified technical solution to deviate from the spirit and scope of the technical solution of the present invention.
Claims
1. A data encryption and decryption method based on user identity, characterized in that: It includes encrypting the message to obtain the ciphertext and decrypting the ciphertext to obtain the plaintext. In the process, the initial vector used for encryption is generated based on the user identity ID. It is assumed that each user has a unique identity ID, the block length of the encryption algorithm Enc is n, the system original key is k, and the decryption algorithm is Dec. When encrypting a message m, the following steps are performed: (1) Convert the user's identity ID into a standard binary code and record it as IDcode; (2) Use the one-way hash function H to calculate the hash value of IDcode, and obtain h = H (IDcode); (3) Use mathematical transformation F to convert h in step (2) into an array of nbit string length as the initial vector IV, and obtain IV = F(h); (4) Using IV as the initial vector and the system original key k or the upgraded key kc related to the user identity ID as the encryption key, the message m is appropriately segmented and encrypted. When the system original key k is used for encryption, the ciphertext c1=Enc(k, IV, m) is obtained. When the upgraded key kc related to the user identity ID is used for encryption, the ciphertext c2=Enc(kc, IV, m) is obtained. When decrypting ciphertext c, perform the following steps: (1) Convert the user's identity ID into a standard binary code and record it as IDcode; (2) Use the hash function H to calculate the hash value of IDcode, and obtain h = H (IDcode); (3) Use mathematical transformation F to convert h in step (2) into an array of nbit string length as the initial vector IV, and obtain IV = F(h); (4) Using IV as the initial vector, the ciphertext c is decrypted segment by segment using the decryption key. The decryption key corresponds to the encryption key. When k is used for decryption, the plaintext m1 = Dec (k, IV, c) is obtained; when kc is used for decryption, the plaintext m2 = Dec (kc, IV, c) is obtained.
2. The method for data encryption and decryption based on user identity according to claim 1, characterized in that: The method for obtaining the upgrade key kc is: use the message authentication code algorithm MAC and the system original key k to calculate MAC (k, IDcode), intercept the previous nbit it output to obtain the upgrade key kc; The method for obtaining the decryption key kc is: use the MAC algorithm and the system original key k to calculate MAC(k, IDcode), and intercept the first n bits of the output to obtain the decryption key kc.
3. A data encryption and decryption method based on user identity and user group identity, characterized in that: It includes encrypting the message to obtain the ciphertext and decrypting the ciphertext to obtain the plaintext. In the process, the initial vector used for encryption is generated based on the user group identity. It is assumed that the users belong to different fixed groups, and each group has a unique identity G ID. Member users belonging to the same group perform data encryption and decryption operations on each other. Each user has a unique identity ID. The block length of the encryption algorithm Enc is n, the system original key is k, and the decryption algorithm is Dec. When encrypting a message m, the following steps are performed: (1) Convert the user's identity ID into a standard binary code and record it as IDcode; (2) Convert the user group identity G ID into a standard binary code, recorded as G IDcode; (3) Use the one-way hash function H to calculate the hash value of G IDcode, and obtain h = H (GIDcode); (4) Use mathematical transformation F to convert h in step (2) into an array of n-bit string length as the initial vector IV, and obtain IV = F(h); (5) Using the IV obtained in step (4) as the initial vector, the message m is appropriately segmented and then encrypted using the encryption key. When the encryption key uses the system original key k, the ciphertext c1=Enc(k, IV, m) is obtained. When the encryption key uses the upgrade key kc related to the user identity ID, the ciphertext c2=Enc(kc, IV, m) is obtained. When the encryption key uses the upgrade key kc related to the user group identity GID, the ciphertext c3=Enc(kc, IV, m) is obtained. When decrypting ciphertext c, perform the following steps: (1) Convert the user's identity ID into a standard binary code and record it as IDcode; (2) Convert the user group identity G ID into a standard binary code, recorded as G IDcode; (3) Use the hash function H to calculate the hash value of IDcode, and obtain h = H (GIDcode); (4) Use mathematical transformation F to convert h in step (2) into an array of n-bit string length as the initial vector IV, and obtain IV = F(h); (5) Using IV as the initial vector, the ciphertext c is decrypted segment by segment using the decryption key. The decryption key corresponds to the encryption key. When decrypting with k, the plaintext m1 = Dec (k, IV, c) is obtained; when decrypting with kc, the plaintext m2 = Dec (kc, IV, c) or m3 = Dec (kc, IV, c) is obtained.
4. The data encryption and decryption method based on user identity and user group identity according to claim 3, characterized in that: The method for obtaining the upgrade key kc related to the user identity ID is: using the message authentication code algorithm MAC and the system original key k to calculate MAC (k, IDcode), intercepting the previous nbit it output to obtain the upgrade key kc; The method for obtaining the corresponding decryption key kc is: use the MAC algorithm and the system original key k to calculate MAC (k, IDcode), and intercept the previous nbit output to obtain the decryption key kc.
5. The data encryption and decryption method based on user identity and user group identity according to claim 3, characterized in that: The method for obtaining the upgrade key kc related to the user group identity G ID is: using the message authentication code algorithm MAC and the system original key k to calculate MAC (k, G IDcode), intercepting the previous nbit output to obtain the upgrade key kc; The method for obtaining the corresponding decryption key kc is: use the MAC algorithm and the system original key k to calculate MAC (k, GIDcode), intercept the previous nbit output to obtain the decryption key kc.
Citation Information
Patent Citations
Encryption and decryption method and device with user / equipment identity authentication
CN103634113A
Data encryption method and system for industrial control system
CN110147678A