Data encryption method, device and data decryption method and device
By converting the user login identification code into an initialization vector and combining encryption and signature algorithms, the problem of low data encryption security in the existing technology is solved, high security in the data transmission process is achieved, and it is ensured that only legitimate users can decrypt the data. .
Patent Information
- Application Number
- CN202110556897.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-21
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2041-05-21
AI Technical Summary
The security of data encryption methods in the existing technology is not high, especially after the token or encryption key is obtained by a third party, resulting in an increased risk of illegal acquisition of the encrypted data.
By obtaining the user login identification code, convert it into an initialization vector using a preset conversion algorithm, and execute an encryption algorithm based on the vector to encrypt the plain text content, and then use a signature algorithm to sign the user login identification code, and combine the signature content and password The text content is combined as encrypted data to ensure the security of the data during transmission.
It effectively improves the security of user data, ensures that only legitimate users can decrypt data, prevents illegal acquisition and tampering, and improves the security of data transmission.
Smart Images

Figure CN113158218B
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet technology, and in particular to a data encryption method and device and a data decryption method and device. Background Art
[0002] With the continuous development of Internet technology and the widespread popularity of smart terminals, the functions of various business applications realized through smart terminals have become increasingly complex and diverse. Some applications only need to authenticate the user's identity, while some applications with higher security requirements also need to encrypt the transmitted data to prevent important data from being tampered with or leaked. For the former, the current more popular approach is to use a token-based identity authentication method; for the latter with higher security requirements, encryption algorithms will be used, such as the more common asymmetric encryption algorithms and symmetric encryption algorithms.
[0003] However, for the above-listed token-based authentication methods or encrypted data implemented using existing symmetric encryption / asymmetric encryption algorithms, once the token or encryption key is obtained by a third party, it will directly lead to the illegal acquisition of the encrypted data. In other words, the security of the data encryption method in the prior art is not high. Summary of the invention
[0004] The present application proposes a data encryption method and device, which can solve the problem of low security of data encryption methods in the prior art.
[0005] First, to achieve the above purpose, the present application provides a data encryption method, the method comprising:
[0006] Obtain the plaintext content to be encrypted and the user login identification code; convert the user login identification code into an initialization vector according to a preset conversion algorithm; encrypt the plaintext content based on the initialization vector according to a preset encryption algorithm to obtain ciphertext content; sign the user login identification code according to a preset signature algorithm to obtain signature content, and use the signature content and the ciphertext content as encrypted data.
[0007] In one example, the conversion algorithm is a message digest algorithm, and converting the user login identification code to obtain an initialization vector according to a preset conversion algorithm includes: converting the user login identification code into a character string of a preset byte length through the message digest algorithm, and recording the character string as the initialization vector.
[0008] In one example, the encryption algorithm is a symmetric encryption algorithm suitable for the byte length of the initialization vector.
[0009] In one example, after encrypting the plaintext content based on the initialization vector according to a preset encryption algorithm to obtain the ciphertext content, the method further includes: encrypting the ciphertext content according to a preset verification algorithm to obtain a ciphertext content verification value; signing the ciphertext content verification value and the user login identification code according to the signature algorithm to obtain signature content, and using the signature content and the ciphertext content as encrypted data.
[0010] Furthermore, the present application also provides a data decryption method, the method comprising:
[0011] Receive encrypted data to be decrypted; perform signature verification on the signature content in the encrypted data according to a preset signature verification rule; if the signature verification passes, extract the ciphertext content from the encrypted data and extract the user login identification code from the signature content; convert the user login identification code into an initialization vector according to a preset conversion algorithm; perform decryption on the ciphertext content based on the initialization vector according to a preset decryption algorithm to obtain plaintext content.
[0012] In one example, the conversion algorithm is a message digest algorithm, and converting the user login identification code to obtain an initialization vector according to a preset conversion algorithm includes: converting the user login identification code into a character string of a preset byte length through the message digest algorithm, and recording the character string as the initialization vector.
[0013] In one example, extracting the ciphertext content from the encrypted data and extracting the user login identification code from the signature content includes: extracting the ciphertext content from the data body corresponding to the encrypted data and extracting the user login identification code from the data body corresponding to the signature content according to a preset data format.
[0014] In one example, the signature content also includes a ciphertext content verification value. Before the step of decrypting the ciphertext content based on the initialization vector according to a preset decryption algorithm to obtain a plaintext content, the method also includes: encrypting the ciphertext content according to a preset verification algorithm to obtain an arithmetic check value; determining whether the arithmetic check value is the same as the ciphertext content verification value; if the arithmetic check value is not the same as the ciphertext content verification value, ending the data decryption process and prompting that the data decryption failed.
[0015] In addition, to achieve the above purpose, the present application also provides a data encryption device, the device comprising:
[0016] An acquisition module is used to acquire plaintext content to be encrypted and a user login identification code; a first conversion module is used to convert the user login identification code into an initialization vector according to a preset conversion algorithm; an encryption module is used to encrypt the plaintext content based on the initialization vector according to a preset encryption algorithm to obtain ciphertext content; a signature module is used to sign the user login identification code according to a preset signature algorithm to obtain signature content, and use the signature content and the ciphertext content as encrypted data.
[0017] Furthermore, the present application also provides a data decryption device, the device comprising:
[0018] A receiving module is used to receive encrypted data to be decrypted; a signature verification module is used to perform signature verification on the signature content in the encrypted data according to a preset signature verification rule; an extraction module is used to extract the ciphertext content from the encrypted data and the user login identification code from the signature content if the signature verification passes; a second conversion module is used to convert the user login identification code into an initialization vector according to a preset conversion algorithm; a decryption module is used to perform decryption on the ciphertext content based on the initialization vector according to a preset decryption algorithm to obtain a plaintext content.
[0019] Furthermore, the present application also proposes a computer device, which includes a memory and a processor, wherein the memory stores a computer program that can be executed on the processor, and when the computer program is executed by the processor, it implements the steps of the data encryption method as described above, or implements the steps of the data decryption method as described above.
[0020] Furthermore, to achieve the above-mentioned purpose, the present application also provides a computer-readable storage medium, which stores a computer program, and the computer program can be executed by at least one processor to enable the at least one processor to perform the steps of the data encryption method as described above, or to perform the steps of the data decryption method as described above.
[0021] Compared with the prior art, the data encryption method and device proposed in this application can obtain the plaintext content to be encrypted and the user login identification code; convert the user login identification code to obtain an initialization vector according to a preset conversion algorithm; encrypt the plaintext content based on the initialization vector according to a preset encryption algorithm to obtain ciphertext content; sign the user login identification code according to a preset signature algorithm to obtain signature content, and use the signature content and the ciphertext content as encrypted data. The user login identification code is converted into an initialization vector in the encryption process through a conversion algorithm, which is used to implement data encryption and signing, thereby effectively ensuring the security of the user data corresponding to the user login identification code. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 is a schematic diagram of an application environment of an embodiment of the present application;
[0023] Figure 2 It is a flowchart of a specific embodiment of the data encryption method of the present application;
[0024] Figure 3 It is a flowchart of a specific embodiment of the data decryption method of the present application;
[0025] Figure 4 It is a flow chart of a data encryption method in an exemplary example of the present application;
[0026] Figure 5 It is a flow chart of a data decryption method in an exemplary example of the present application;
[0027] Figure 6 It is a schematic diagram of a program module of an embodiment of a data encryption device of the present application;
[0028] Figure 7 It is a schematic diagram of a program module of an embodiment of a data decryption device of the present application;
[0029] Figure 8 It is a schematic diagram of an optional hardware architecture of the computer device of the present application. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.
[0031] It should be noted that the descriptions involving "first", "second", etc. in this application are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in this field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.
[0032] Figure 1 Schematic diagram of the application environment of an embodiment of the present application. Figure 1As shown, the computer device 1 is connected to the computer device 2, and the computer device 1 and the computer device 2 can exchange data with each other. When the computer device 1 or the computer device 2 sends data to the other party, a series of data encryption can be performed on the plain text content to be sent according to the pre-agreed encryption process to obtain encrypted data; then, when the computer device 2 or the computer device 1 receives the encrypted data sent by the other party, the data can be decrypted according to the inverse process of the data encryption process to obtain the plain text content corresponding to the encrypted data.
[0033] In this embodiment, the example of the computer device 1 sending data to the computer device 2 is used for explanation. The computer device 1 obtains the plaintext content to be encrypted and the user login identification code; then converts the user login identification code to obtain an initialization vector according to a preset conversion algorithm; then encrypts the plaintext content based on the initialization vector according to a preset encryption algorithm to obtain ciphertext content; finally, the user login identification code is signed according to a preset signature algorithm to obtain signature content, and the signature content and the ciphertext content are used as encrypted data, and the encrypted data is the data to be sent to the computer device 2.
[0034] Next, the computer device 2 receives the encrypted data to be decrypted, and then performs signature verification on the signature content in the encrypted data according to the preset signature verification rules; if the signature verification passes, the ciphertext content is extracted from the encrypted data, the user login identification code is extracted from the signature content, and then the user login identification code is converted into an initialization vector according to a preset conversion algorithm. Finally, the ciphertext content is decrypted based on the initialization vector according to a preset decryption algorithm to obtain plaintext content.
[0035] In this embodiment, the computer device 1 and the computer device 2 can both be used as electronic devices such as mobile phones, tablets, portable devices, PCs or servers.
[0036] Embodiment 1
[0037] Figure 2 It is a flowchart of an embodiment of the data encryption method of the present application. It can be understood that the flowchart in the embodiment of the method is not used to limit the order of executing steps. The following is an exemplary description using computer device 1 as the execution subject.
[0038] like Figure 2 As shown, the data encryption method may include steps S200 to S206.
[0039] Step S200, obtaining the plaintext content to be encrypted and the user login identification code.
[0040] Step S202: convert the user login identification code into an initialization vector according to a preset conversion algorithm.
[0041] Specifically, when a user logs into the application on the computer device 1, he generally needs to use a pre-registered login account, and then he can pass data to the computer device 2 through the account corresponding to the login account. In this embodiment, after the user logs in, the computer device 1 will obtain the corresponding user login identification code, that is, the unique string code registered by the user's login account on the server corresponding to the application. At the same time, the user passes data to the computer device 2 through the computer device 1, so the computer device 1 can also obtain the data that the user needs to pass, that is, the plain text content to be encrypted.
[0042] After obtaining the user login identification code, the computer device 1 will further convert the user login identification code into an initialization vector according to a preset conversion algorithm. In this embodiment, the conversion algorithm is a message digest algorithm, and the computer device 1 converts the user login identification code into an initialization vector according to the preset conversion algorithm, including: converting the user login identification code into a character string of preset byte length by using the message digest algorithm, and recording the character string as the initialization vector.
[0043] For example, the conversion algorithm is the MD5 (Message-Digest Algorithm 5) algorithm, which is a widely used cryptographic hash function that can operate on any character string to generate a 128-bit (16-byte) hash value to ensure that the information transmission is complete and consistent. The computer device 1 converts the user login identification code into an initialization vector of a preset number of bits, such as an ASCII character string of 16 bits in length, through the MD5 algorithm. Among them, in the field of cryptography, the initialization vector (IV), or the initialization vector, also known as the starting variable (SV), is an input value of a fixed length, generally a random number or a quasi-random number. The use of the initialization vector can achieve semantic security and enhance the security of encrypted data.
[0044] Step S204: encrypt the plaintext content based on the initialization vector according to a preset encryption algorithm to obtain ciphertext content.
[0045] Specifically, after the computer device 1 generates the initialization vector according to the user login identification code, it will further perform encryption on the plaintext content to be encrypted based on the initialization vector according to the preset encryption algorithm, and then obtain the corresponding ciphertext content. In this embodiment, the encryption algorithm is a symmetric encryption algorithm suitable for the byte length of the initialization vector. For example, the encryption algorithm can be an AES (Advanced Encryption Standard) algorithm, which is currently the most common symmetric encryption algorithm. Its key length is divided into: 128 bits, 192 bits and 256 bits, and has five encryption modes: ECB (Electronic Codebook Book), CBC (Cipher BlockChaining), CTR (Counter), CFB (Cipher FeedBack) and OFB (Output FeedBack). When the initialization vector is 16 bytes in length, then the computer device 1 can select the CBC mode in the AES algorithm, so as to be suitable for the byte length of the initialization vector.
[0046] The computer device 1 completes the data encryption process by mixing the initialization vector into the plaintext content according to the mixing rule preset in the encryption algorithm, and then encrypts the plaintext content mixed with the initialization vector according to the key preset in the encryption algorithm, thereby obtaining the corresponding ciphertext content.
[0047] Step S206: Sign the user login identification code according to a preset signature algorithm to obtain signature content, and use the signature content and the ciphertext content as encrypted data.
[0048] After the computer device 1 encrypts the plaintext content to obtain the corresponding ciphertext content, it will further sign the user login identification code to obtain the signature content, which is then sent to the computer device 2 together with the ciphertext content as encrypted data.
[0049] In this embodiment, the computer device 1 signs the user login identification code by means of a JWT (Json Web Token) token to obtain the signature content. Among them, JWT is a Json format token (token) composed of three parts: header information (header), message body (payload) and signature (signature hash value) (signature), which is used to transmit statements in network applications. For example, the RSA algorithm can be selected as the signature algorithm to sign the user login identification code, thereby generating a JWT token, and the JWT token includes the user login identification code and the signature hash value. RSA is the most widely used asymmetric encryption algorithm, which can be used for data encryption and decryption as well as digital signature authentication, and has high security.
[0050] Then, the computer device 1 generates encrypted data according to the signature content and the ciphertext content and sends it to the computer device 2, for example, by sending the encrypted data to the computer device 2 in the form of sending request data, wherein the signature content can be stored in the request header and the ciphertext content can be stored in the request body.
[0051] In another specific embodiment, after the computer device 1 encrypts the plaintext content based on the initialization vector according to the preset encryption algorithm to obtain the ciphertext content, it can also perform the steps of: encrypting the ciphertext content according to the preset verification algorithm to obtain the ciphertext content verification value; signing the ciphertext content verification value and the user login identification code according to the signature algorithm to obtain the signature content, and using the signature content and the ciphertext content as encrypted data. Among them, the computer device 1 signs the ciphertext content verification value and the user login identification code to obtain a corresponding signature content, and sends it to the computer device 2 together with the ciphertext content as encrypted data, so that, during the decryption process, the computer device 2 needs to verify the ciphertext content verification value and the user login identification code to ensure that the ciphertext content has not been tampered with, thereby ensuring the security of the ciphertext content.
[0052] For example, after obtaining the ciphertext content, the computer device 1 further encrypts the ciphertext content according to the MD5 algorithm to obtain a ciphertext content verification value, and then signs and encrypts the ciphertext content verification value and the user login identification code together to obtain the corresponding signature content, and then uses the signature content and the ciphertext content together as encrypted data; finally, the computer device 1 sends the encrypted data to the computer device 2.
[0053] As can be seen from the above content, the computer device 1 converts the user login identification code into an initialization vector and then uses it to encrypt the plaintext content, thereby obtaining the corresponding ciphertext content. Therefore, the encryption process must be executed after the user logs in through the original user login account. In an exemplary example, when the user is not logged in, the initialization vector is equal to the same key string of 16 bytes in length pre-agreed by the computer device 1 and the computer device 2, such as an encryption initialization vector of a fixed string; when the user logs in, the user login identification code is used as the initialization vector, so that the user login identification code can be cleverly linked to the encryption initialization vector. Therefore, in the decryption process, even if a third party obtains the encryption key, the signature verification rule and the initialization vector, it is limited to the current ciphertext content sent by the current user; when the user logs in again, the initialization vector will also be modified as the user login identification code is refreshed, so that the third party cannot crack the ciphertext content sent by the user next time, thereby greatly improving the security of the data transmitted by the user.
[0054] Embodiment 2
[0055] Figure 3 It is a flowchart of an embodiment of the data decryption method of the present application. It can be understood that the flowchart in the embodiment of the present method is not used to limit the order of executing steps. The following is an exemplary description using the computer device 2 as the execution subject.
[0056] like Figure 3 As shown, the data encryption method may include steps S300 to S308.
[0057] Step S300, receiving encrypted data to be decrypted.
[0058] Step S302: verify the signature content in the encrypted data according to a preset signature verification rule.
[0059] Step S304: If the signature verification is successful, the ciphertext content is extracted from the encrypted data, and the user login identification code is extracted from the signature content.
[0060] Specifically, after receiving the encrypted data sent by the computer device 1, the computer device 2 will perform signature verification on the signature content in the encrypted data according to the preset signature verification rules. For example, the signature verification rules include a verification method for the signature hash value in the signature content; when the computer device 2 verifies the signature hash value according to the signature verification rules, such as verifying the format, or verifying the string sorting, if the computer device 2 passes the signature verification, then the ciphertext content will be further extracted from the encrypted data and the user login identification code will be extracted from the signature content.
[0061] In a specific embodiment, the computer device 2 extracts the ciphertext content from the encrypted data and extracts the user login identification code from the signature content, including: extracting the ciphertext content from the data body corresponding to the encrypted data and extracting the user login identification code from the data body corresponding to the signature content according to a preset data format. For example, the data format corresponding to the encrypted data includes a request header and a request body, the ciphertext content is stored in the request body, the signature content is stored in the request header, and the user login identification code is included in the signature content, then the computer device 2 will first identify the request header and the request body in the data body corresponding to the encrypted data, and then extract the user login identification code and the ciphertext content from the request header and the request body according to the data formats corresponding to the request header and the request body, respectively.
[0062] Step S306: convert the user login identification code into an initialization vector according to a preset conversion algorithm.
[0063] Specifically, after the computer device 2 obtains the user login identification code, it will convert the user login identification code into an initialization vector according to a preset conversion algorithm. In a specific embodiment, the conversion algorithm is a message digest algorithm, and the computer device 2 converts the user login identification code into an initialization vector according to the preset conversion algorithm, including: converting the user login identification code into a character string of a preset byte length through the message digest algorithm, and recording the character string as the initialization vector. For example, the conversion algorithm is an MD5 algorithm, and the computer device 2 converts the user login identification code into an initialization vector of a preset number of bits, such as an ASCII character string of 16 bits in length, through the MD5 algorithm.
[0064] Step S308: Decrypt the ciphertext content based on the initialization vector according to a preset decryption algorithm to obtain plaintext content.
[0065] After the computer device 2 converts the user login identification code into the initialization vector, it further decrypts the ciphertext content based on the initialization vector according to a preset decryption algorithm, thereby decrypting the plaintext content corresponding to the ciphertext content. For example, the computer device 2 performs corresponding format conversion, or inserts and deletes character strings on the ciphertext content according to a preset decryption key and decryption rule, thereby obtaining the plaintext content corresponding to the ciphertext content.
[0066] In a specific embodiment, when the signature content also includes a ciphertext content verification value, the computer device 2 will also execute the steps of: encrypting the ciphertext content according to a preset verification algorithm to obtain an arithmetic check value; determining whether the arithmetic check value is the same as the ciphertext content verification value; if the arithmetic check value is different from the ciphertext content verification value, ending the data decryption process and prompting that the data decryption failed; if the arithmetic check value is the same as the ciphertext content verification value, then the computer device 2 will execute step S308.
[0067] See also Figure 4 and Figure 5 , Figure 4 is a flow chart of a data encryption method according to an exemplary embodiment of the present invention. Figure 5 FIG. 1 is a flow chart of a data decryption method according to an exemplary embodiment of the present invention. In this embodiment, when computer device 1 transmits data to computer device 2, computer device 1 encrypts the data and sends the data to computer device 2.
[0068] Among them, the data encryption process includes: the computer device 1 first obtains the data to be transmitted, that is, the plaintext content; then obtains the user login identification code; then, the computer device 1 calculates the initialization vector according to the user login identification code, for example, the initialization vector is calculated by the MD5 algorithm; then according to the initialization vector, and a preset encryption algorithm, such as AES encryption (aes-128-cbc), the plaintext content is encrypted to obtain the ciphertext content; then, the computer device 1 further performs MD5 encryption on the ciphertext content to generate a digital signature n of the ciphertext content; finally, the user login identification code and the digital signature n are signed, such as a JWT signature (RS256), so as to generate a token, and the token and the ciphertext content are sent to the computer device 2 as encrypted data.
[0069] For the data decryption process: the computer device 2 receives the encrypted data, and then verifies the token in the encrypted data, that is, JWT verification, and directly ends the data decryption process if the verification is unsuccessful; when the verification is successful, the computer device 2 obtains the ciphertext content from the encrypted data, and then encrypts the ciphertext content with MD5, thereby generating a digital signature n1 of the ciphertext content; then, the computer device 2 determines whether n1 is equal to n; when n1 is not equal to n, the data decryption process is directly ended; when n1 is equal to n, the computer device 2 further obtains the user login identification code from the token; then calculates the initialization vector based on the user login identification code, for example, calculates the initialization vector through the MD5 algorithm; finally, based on the initialization vector, according to a preset decryption algorithm, such as AES encryption (aes-128-cbc), the ciphertext content is decrypted to generate plaintext content.
[0070] Based on the contents described in the above-mentioned embodiments 1 and 2, it can be seen that compared with the prior art, in the data encryption process, the present application converts the user login identification code into an initialization vector in the encryption process through a conversion algorithm for performing data encryption and signing, while in the data decryption process, it is necessary to extract the user login identification code based on the received signature content, and then convert it into an initialization vector for performing data decryption; by realizing data encryption, decryption and signing based on the user login identification code, the security of the user data corresponding to the user login identification code can be effectively guaranteed.
[0071] Embodiment 3
[0072] Figure 6 The block diagram of the data encryption device according to the third embodiment of the present application is schematically shown, and the data encryption device can be divided into one or more program modules, and one or more program modules are stored in a storage medium and executed by one or more processors to complete the embodiment of the present application. The program module referred to in the embodiment of the present application refers to a series of computer program instruction segments that can complete specific functions. The following description will specifically introduce the functions of each program module in this embodiment.
[0073] like Figure 6 As shown, the data encryption device 400 may include an acquisition module 410, a first conversion module 420, an encryption module 430 and a signature module 440, wherein:
[0074] The acquisition module 410 is used to acquire the plain text content to be encrypted and the user login identification code.
[0075] The first conversion module 420 is used to convert the user login identification code into an initialization vector according to a preset conversion algorithm.
[0076] The encryption module 430 is used to encrypt the plaintext content based on the initialization vector according to a preset encryption algorithm to obtain ciphertext content. The encryption algorithm is a symmetric encryption algorithm suitable for the byte length of the initialization vector.
[0077] The signature module 440 is used to sign the user login identification code according to a preset signature algorithm to obtain signature content, and use the signature content and the ciphertext content as encrypted data.
[0078] In an exemplary embodiment, the conversion algorithm is a message digest algorithm, and the first conversion module 420 is further used to: convert the user login identification code into a character string of a preset byte length through the message digest algorithm, and record the character string as the initialization vector.
[0079] In an exemplary embodiment, the signature module 440 is also used to: encrypt the ciphertext content according to a preset verification algorithm to obtain a ciphertext content verification value; sign the ciphertext content verification value and the user login identification code according to the signature algorithm to obtain signature content, and use the signature content and the ciphertext content as encrypted data.
[0080] Embodiment 4
[0081] Figure 7 The block diagram of the data decryption device according to the fourth embodiment of the present application is schematically shown. The data decryption device can be divided into one or more program modules, and one or more program modules are stored in a storage medium and executed by one or more processors to complete the embodiment of the present application. The program module referred to in the embodiment of the present application refers to a series of computer program instruction segments that can complete specific functions. The following description will specifically introduce the functions of each program module in this embodiment.
[0082] like Figure 7 As shown, the data decryption device 600 may include a receiving module 610, a signature verification module 620, an extraction module 630, a second conversion module 640 and a decryption module 650, wherein:
[0083] The receiving module 610 is used to receive encrypted data to be decrypted.
[0084] The signature verification module 620 is used to perform signature verification on the signature content in the encrypted data according to a preset signature verification rule.
[0085] The extraction module 630 is used to extract the ciphertext content from the encrypted data and the user login identification code from the signature content if the signature verification is successful.
[0086] The second conversion module 640 is used to convert the user login identification code into an initialization vector according to a preset conversion algorithm.
[0087] The decryption module 650 is used to decrypt the ciphertext content based on the initialization vector according to a preset decryption algorithm to obtain plaintext content.
[0088] In an exemplary embodiment, the conversion algorithm is a message digest algorithm, and the second conversion module 640 is further used to: convert the user login identification code into a character string of a preset byte length through the message digest algorithm, and record the character string as the initialization vector.
[0089] In an exemplary embodiment, the extraction module 630 is further used to: extract the ciphertext content from the data body corresponding to the encrypted data according to a preset data format, and extract the user login identification code from the data body corresponding to the signature content.
[0090] In an exemplary embodiment, the ciphertext content also includes a check value, and the decryption module 650 is also used to: encrypt the ciphertext content according to a preset check algorithm to obtain an arithmetic check value; determine whether the arithmetic check value is the same as the ciphertext content check value; if the arithmetic check value is different from the ciphertext content check value, end the data decryption process and prompt that the data decryption failed.
[0091] Embodiment 5
[0092] Figure 8 The hardware architecture diagram of a computer device 1 suitable for implementing a data encryption method or a computer device 2 for implementing a data decryption method according to Embodiment 5 of the present application is schematically shown. In this embodiment, the computer device 100 is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. For example, it can be a rack server, blade server, tower server or cabinet server (including an independent server, or a server cluster composed of multiple servers) with a gateway function. Figure 8 As shown, the computer device 100 includes at least but is not limited to: a memory 510, a processor 520, and a network interface 530 that can communicate with each other through a system bus. Among them:
[0093] The memory 510 includes at least one type of computer-readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 510 can be an internal storage module of the computer device 100, such as a hard disk or memory of the computer device 100. In other embodiments, the memory 510 can also be an external storage device of the computer device 100, such as a plug-in hard disk equipped on the computer device 100, a smart memory card (Smart Media Card, referred to as SMC), a secure digital (Secure Digital, referred to as SD) card, a flash card, etc. Of course, the memory 510 can also include both the internal storage module of the computer device 100 and its external storage device. In this embodiment, the memory 510 is generally used to store an operating system and various application software installed on the computer device 100, such as program code of a data encryption method or program code of a data decryption method, etc. In addition, the memory 510 can also be used to temporarily store various data that have been output or are to be output.
[0094] In some embodiments, the processor 520 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip. The processor 520 is generally used to control the overall operation of the computer device 100, such as performing control and processing related to data interaction or communication with the computer device 100. In this embodiment, the processor 520 is used to run the program code stored in the memory 510 or process data.
[0095] The network interface 530 may include a wireless network interface or a wired network interface, and the network interface 530 is generally used to establish a communication link between the computer device 100 and other computer devices. For example, the network interface 530 is used to connect the computer device 100 to an external terminal through a network, and to establish a data transmission channel and a communication link between the computer device 100 and the external terminal. The network may be a wireless or wired network such as an intranet, the Internet, the Global System of Mobile communication (GSM), Wideband Code Division Multiple Access (WCDMA), 4G network, 5G network, Bluetooth, Wi-Fi, etc.
[0096] It should be pointed out that Figure 8 Only a computer device having components 510 - 530 is shown, but it should be understood that implementing all of the components shown is not a requirement, and more or fewer components may alternatively be implemented.
[0097] In this embodiment, the program code of the data encryption method or the program code of the data decryption method stored in the memory 510 can also be divided into one or more program modules and executed by one or more processors (processor 520 in this embodiment) to complete the embodiment of the present application.
[0098] Embodiment 6
[0099] This embodiment also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the data encryption method described in Embodiment 1 or the steps of the data decryption method described in Embodiment 2 are implemented.
[0100] In this embodiment, the computer-readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the computer-readable storage medium can be an internal storage unit of a computer device, such as a hard disk or memory of the computer device. In other embodiments, the computer-readable storage medium can also be an external storage device of a computer device, such as a plug-in hard disk equipped on the computer device, a smart memory card (Smart Media Card, referred to as SMC), a secure digital (Secure Digital, referred to as SD) card, a flash card, etc. Of course, the computer-readable storage medium can also include both the internal storage unit of the computer device and its external storage device. In this embodiment, the computer-readable storage medium is generally used to store the operating system and various application software installed on the computer device, such as the program code of the data encryption method in the embodiment, or the program code of the data decryption method, etc. In addition, the computer-readable storage medium can also be used to temporarily store various types of data that have been output or are to be output.
[0101] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of the present application are not limited to any specific combination of hardware and software.
[0102] The above are only preferred embodiments of the embodiments of the present application, and are not intended to limit the patent scope of the embodiments of the present application. Any equivalent structure or equivalent process transformation made using the description and drawings of the embodiments of the present application, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the embodiments of the present application.
Claims
1. A data encryption method, characterized in that: The method comprises: Obtain the plaintext content to be encrypted and the user login identification code; Converting the user login identification code to obtain an initialization vector according to a preset conversion algorithm; Encrypting the plaintext content based on the initialization vector according to a preset encryption algorithm to obtain ciphertext content; Signing the user login identification code according to a preset signature algorithm to obtain signature content, and using the signature content and the ciphertext content as encrypted data; After encrypting the plaintext content based on the initialization vector according to the preset encryption algorithm to obtain the ciphertext content, the method further includes: The ciphertext content is encrypted according to a preset verification algorithm to obtain a ciphertext content verification value; The ciphertext content check value and the user login identification code are signed according to the signature algorithm to obtain signature content, and the signature content and the ciphertext content are used as encrypted data.
2. The data encryption method according to claim 1, characterized in that: The conversion algorithm is a message digest algorithm, and the conversion of the user login identification code to obtain an initialization vector according to a preset conversion algorithm includes: The user login identification code is converted into a character string of preset byte length by using the message digest algorithm, and the character string is recorded as the initialization vector.
3. The data encryption method according to claim 2, characterized in that: The encryption algorithm is a symmetric encryption algorithm suitable for the byte length of the initialization vector.
4. A data decryption method, characterized in that: The method comprises: receiving encrypted data to be decrypted; Performing signature verification on the signature content in the encrypted data according to a preset signature verification rule; If the signature verification is successful, the ciphertext content is extracted from the encrypted data, and the user login identification code is extracted from the signature content; Converting the user login identification code to obtain an initialization vector according to a preset conversion algorithm; Decrypting the ciphertext content based on the initialization vector according to a preset decryption algorithm to obtain plaintext content; The signature content also includes a ciphertext content check value. Before the step of decrypting the ciphertext content based on the initialization vector according to a preset decryption algorithm to obtain the plaintext content, the method also includes: Encrypting the ciphertext content according to a preset verification algorithm to obtain an arithmetic check value; Determining whether the arithmetic check value is the same as the ciphertext content check value; If the arithmetic check value is different from the ciphertext content check value, the data decryption process is terminated and a prompt indicating that the data decryption has failed is displayed.
5. The data decryption method according to claim 4, characterized in that: The conversion algorithm is a message digest algorithm, and the conversion of the user login identification code to obtain an initialization vector according to a preset conversion algorithm includes: The user login identification code is converted into a character string of preset byte length by using the message digest algorithm, and the character string is recorded as the initialization vector.
6. The data decryption method according to claim 4, characterized in that: The extracting of the ciphertext content from the encrypted data and the extracting of the user login identification code from the signature content comprises: The ciphertext content is extracted from the data body corresponding to the encrypted data according to a preset data format, and the user login identification code is extracted from the data body corresponding to the signature content.
7. A data encryption device, characterized in that: The device comprises: An acquisition module, used to acquire the plain text content to be encrypted and the user login identification code; A first conversion module, used for converting the user login identification code into an initialization vector according to a preset conversion algorithm; An encryption module, used to encrypt the plaintext content based on the initialization vector according to a preset encryption algorithm to obtain ciphertext content; A signature module, used to sign the user login identification code according to a preset signature algorithm to obtain signature content, and use the signature content and the ciphertext content as encrypted data; After encrypting the plaintext content based on the initialization vector according to the preset encryption algorithm to obtain the ciphertext content, the method further includes: The ciphertext content is encrypted according to a preset verification algorithm to obtain a ciphertext content verification value; The ciphertext content check value and the user login identification code are signed according to the signature algorithm to obtain signature content, and the signature content and the ciphertext content are used as encrypted data.
8. A data decryption device, characterized in that: The device comprises: A receiving module, used for receiving encrypted data to be decrypted; A signature verification module, used to perform signature verification on the signature content in the encrypted data according to a preset signature verification rule; An extraction module, used to extract the ciphertext content from the encrypted data and the user login identification code from the signature content if the signature verification is passed; A second conversion module, used for converting the user login identification code into an initialization vector according to a preset conversion algorithm; A decryption module, used to decrypt the ciphertext content based on the initialization vector according to a preset decryption algorithm to obtain plaintext content; The signature content also includes a ciphertext content check value. Before decrypting the ciphertext content based on the initialization vector according to a preset decryption algorithm to obtain the plaintext content, the device is further used to: Encrypting the ciphertext content according to a preset verification algorithm to obtain an arithmetic check value; Determining whether the arithmetic check value is the same as the ciphertext content check value; If the arithmetic check value is different from the ciphertext content check value, the data decryption process is terminated and a prompt indicating that the data decryption has failed is displayed.
9. A computer device, characterized in that: The computer device includes a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the computer program is executed by the processor, the steps of the data encryption method described in any one of claims 1 to 3 are implemented, or the steps of the data decryption method described in any one of claims 4 to 6 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which can be executed by at least one processor to enable the at least one processor to perform the steps of the data encryption method as described in any one of claims 1-3, or to perform the steps of the data decryption method as described in any one of claims 4-6.
