Lightweight video stream data encryption method, system and device based on password card
By segmenting the video stream into multiple segments and sorting and encrypting them using a Gray code sequence, the problems of low efficiency and insufficient security of video stream encryption in the prior art are solved, and efficient and secure video stream data transmission is achieved.
Patent Information
- Application Number
- CN202411390169.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-30
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2044-09-30
AI Technical Summary
Existing video stream encryption methods are inefficient and insecure when the video traffic is large, especially the single random key consumes high computing resources and is less secure for video stream encryption.
Using a lightweight video stream data encryption method based on a password card, the video stream is divided into multiple segments to generate different Gray code sequences, and the segments are reordered according to the size of the Gray code, using different types of segments. The key encrypts each segment, and encrypts the Gray code sequence and key to generate a key file, which is transmitted to the decryption end for processing.
It improves the efficiency and security of video stream encryption, reduces computing resource consumption, and encrypts each video segment through different keys, enhancing the security of data transmission.
Smart Images

Figure CN118921508B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of video encryption technology, and in particular to a lightweight video stream data encryption method, system and device based on a cryptographic card. Background Art
[0002] The current method for encrypting video streams is usually to use a random key to encrypt the video stream to prevent unauthorized visitors or malware from obtaining the plaintext data of the video stream. However, when the video traffic is large, a large amount of computing resources will be consumed, the efficiency of encrypting the data stream will be relatively low, and the security of encrypting the video stream with a single random key is also low. Summary of the invention
[0003] In view of this, the present application provides a lightweight video stream data encryption method, system and device based on a cryptographic card to improve the efficiency and security of lightweight video stream data encryption based on a cryptographic card.
[0004] The technical solutions provided by this application are as follows:
[0005] According to an embodiment of the first aspect of the present application, a lightweight video stream data encryption method based on a cryptographic card is proposed. The method is applied to an encryption terminal device. The method includes:
[0006] The obtained reference video stream is divided into N video segments, and a Gray code sequence is generated for the N video segments; wherein the Gray code sequence includes N different Gray codes, the N Gray codes correspond to the N video segments respectively, and N is an integer not less than 2; the arrangement order of the N Gray codes in the Gray code sequence is a first arrangement order, and the arrangement order of the N video segments corresponding to the N Gray codes is a second arrangement order;
[0007] Determining a third arrangement order of the N Gray codes according to the sizes of the N Gray codes, and determining a fourth arrangement order of the N video segments based on the third arrangement order of the N Gray codes;
[0008] Generate a target video stream corresponding to the reference video stream, the target video stream including the N video segments, the N video segments in the target video stream being arranged according to the fourth arrangement order;
[0009] For each video segment in the target video stream, encrypt the video segment based on the first key corresponding to the video segment to obtain an encrypted segment corresponding to the video segment; generate an encrypted video stream corresponding to the target video stream based on the encrypted segment corresponding to each video segment; the first key is obtained from a password card deployed on the encryption terminal device;
[0010] Encrypting the Gray code sequence and the first key corresponding to each video segment to obtain a key file;
[0011] The encrypted video stream and the key file are sent to a decryption end device, so that the decryption end device processes the encrypted video stream based on the key file to obtain the reference video stream.
[0012] Optionally, for the Gray code in the Gray code sequence, the number of binary bits M of the Gray code is determined according to the logarithm of N with base 2;
[0013] The first Gray code in the Gray code sequence is a randomly generated M-bit Gray code, and adjacent Gray codes in the Gray code sequence have values that differ in only one binary bit.
[0014] Optionally, encrypting the video segment based on a first key corresponding to the video segment to obtain an encrypted fragment corresponding to the video segment includes:
[0015] For each video segment in the target video stream, obtaining a first key corresponding to the video segment from the password card; wherein the first key corresponding to the video segment is generated by the password card according to a random number generated by the password card for the video segment;
[0016] The video segment is encrypted using the first key to obtain an encrypted fragment corresponding to the video segment.
[0017] Optionally, encrypting the Gray code sequence and each first key to obtain a key file includes:
[0018] Encrypting the first keys corresponding to the N video segments using the second key to obtain reference key data, and encrypting the Gray code sequence using the second key to obtain an encrypted Gray code sequence, wherein the reference key data includes the N encrypted first keys;
[0019] Performing integrity check on the second key, the reference key data, the encrypted Gray code sequence and the obtained file description information to obtain an integrity check code; the file description information includes a file version number, the number N of first keys and a file generation date;
[0020] Generate a key file, wherein the key file includes the integrity check code, the second key, the reference key data, the encrypted Gray code sequence, and the file description information.
[0021] Optionally, before encrypting the first keys corresponding to the N video segments using the second key to obtain the reference key data, the method further includes:
[0022] Obtaining an encryption end user access PIN code, wherein the encryption end user access PIN code is a specific numeric sequence used to verify the identity of the encryption end device user;
[0023] The encryption end user access PIN code is processed based on a target verification algorithm to obtain an encryption end user access PIN code verification value, and the encryption end user access PIN code verification value is used as a second key.
[0024] According to an embodiment of the second aspect of the present application, a lightweight video stream data decryption method based on a cryptographic card is proposed. The method is applied to a decryption terminal device. The method includes:
[0025] Receiving an encrypted video stream and a key file; the encrypted video stream includes encrypted segments corresponding to N video segments;
[0026] Decrypting the key file to obtain a Gray code sequence and a first key corresponding to the N video segments;
[0027] For each encrypted segment corresponding to the video segment, decrypt the encrypted segment using the first key corresponding to the video segment to obtain the video segment;
[0028] Generate a target video stream based on N video segments, wherein the N video segments in the target video stream are arranged in a fourth arrangement order; wherein the fourth arrangement order is determined according to a third arrangement order corresponding to the sizes of the N Gray codes in the Gray code sequence;
[0029] Arranging the N video segments in the target video stream in a second arrangement order based on a first arrangement order of the N Gray codes in the Gray code sequence; the second arrangement order is determined according to the first arrangement order of the N Gray codes in the Gray code sequence;
[0030] A reference video stream is generated, wherein the reference video stream includes N video segments arranged in the second arrangement order.
[0031] Optionally, the key file includes an integrity check code, a second key, reference key data, an encrypted Gray code sequence, and file description information; and the decrypting the key file to obtain the Gray code sequence and the first keys corresponding to the N video segments includes:
[0032] Compare the obtained target key with the second key included in the key file, and if the target key is the same as the second key, the identity verification is successful;
[0033] If the identity verification is successful, an integrity check is performed on the second key, the reference key data, the encrypted Gray code sequence and the file description information to obtain a reference verification code of the key file; the file description information includes a version number of the key file, the number N of the encrypted first keys stored in the key file and a generation date of the key file;
[0034] Compare the reference check code with the integrity check code, and if the reference check code is the same as the integrity check code, the check passes;
[0035] If the verification is passed, obtaining reference key data from the key file, the reference key data including N encrypted first keys; decrypting the reference key data using the second key to obtain the first keys corresponding to the N video segments;
[0036] The encrypted Gray code sequence is obtained from the key file, and the encrypted Gray code sequence is decrypted by using a second key to obtain a Gray code sequence.
[0037] Optionally, the method for obtaining the target key includes:
[0038] Obtaining a decryption end user access PIN code, wherein the decryption end user access PIN code is a specific digital sequence used to verify the identity of the decryption end device user;
[0039] The decryption end user access PIN code is processed based on a target verification algorithm to obtain a decryption end user access PIN code verification value, and the decryption end user access PIN code verification value is used as a target key.
[0040] According to an embodiment of the third aspect of the present application, a lightweight video stream data encryption device based on a cryptographic card is proposed. The device is applied to an encryption terminal device, and the device includes:
[0041] A segmentation unit, configured to segment the obtained reference video stream into N video segments, and generate a Gray code sequence for the N video segments; wherein the Gray code sequence includes N different Gray codes, the N Gray codes correspond to the N video segments respectively, and N is an integer not less than 2; the arrangement order of the N Gray codes in the Gray code sequence is a first arrangement order, and the arrangement order of the N video segments corresponding to the N Gray codes is a second arrangement order;
[0042] a sorting unit, configured to determine a third arrangement order of the N Gray codes according to the sizes of the N Gray codes, and determine a fourth arrangement order of the N video segments based on the third arrangement order of the N Gray codes;
[0043] Generate a target video stream corresponding to the reference video stream, the target video stream including the N video segments, the N video segments in the target video stream being arranged according to the fourth arrangement order;
[0044] The encryption unit is used to encrypt each video segment in the target video stream based on a first key corresponding to the video segment to obtain an encrypted segment corresponding to the video segment; based on the encrypted segment corresponding to each video segment, an encrypted video stream corresponding to the target video stream is generated; the first key is obtained from a password card deployed on the encryption terminal device;
[0045] Encrypting the Gray code sequence and the first key corresponding to each video segment to obtain a key file;
[0046] The sending unit is used to send the encrypted video stream and the key file to a decryption end device, so that the decryption end device processes the encrypted video stream based on the key file to obtain the reference video stream.
[0047] According to an embodiment of the fourth aspect of the present application, a lightweight video stream data decryption device based on a password card is proposed, and the device is applied to a decryption terminal device, and the device includes:
[0048] A receiving unit, configured to receive an encrypted video stream and a key file; the encrypted video stream includes encrypted segments corresponding to N video segments;
[0049] A decryption unit, used for decrypting the key file to obtain a Gray code sequence and a first key corresponding to the N video segments;
[0050] For each encrypted segment corresponding to the video segment, decrypt the encrypted segment using the first key corresponding to the video segment to obtain the video segment;
[0051] Generate a target video stream based on N video segments, wherein the N video segments in the target video stream are arranged in a fourth arrangement order; wherein the fourth arrangement order is determined according to a third arrangement order corresponding to the sizes of the N Gray codes in the Gray code sequence;
[0052] a sorting unit, configured to sort the N video segments in the target video stream according to a second sorting order based on the first sorting order of the N Gray codes in the Gray code sequence; the second sorting order is determined according to the first sorting order of the N Gray codes in the Gray code sequence;
[0053] A reference video stream is generated, wherein the reference video stream includes N video segments arranged in the second arrangement order.
[0054] According to an embodiment of the fifth aspect of the present application, a lightweight video stream data encryption system based on a cryptographic card is proposed, comprising:
[0055] An encryption terminal device, used to execute the method according to the first aspect;
[0056] A password card, deployed in the encryption terminal device, for generating a first key corresponding to each video segment in the target video stream;
[0057] The decryption terminal device is used to execute the method described in the second aspect.
[0058] According to an embodiment of the sixth aspect of the present application, an electronic device is proposed, comprising a processor and a computer-readable storage medium, wherein the computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by the processor, the processor executes the method as described in the first aspect.
[0059] According to an embodiment of the seventh aspect of the present application, a computer-readable storage medium is provided, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the processor executes the method as described in the first aspect.
[0060] It can be seen from the above technical scheme that the present application divides the reference video stream to be encrypted into N video segments, and generates N Gray codes corresponding to the video segments one by one, and then reorders the N video segments according to the size order of the N Gray codes, and encrypts each video segment with the corresponding first key to obtain an encrypted video stream, thereby reducing the consumption of computing resources and improving the response speed; at the same time, different keys are used to encrypt different video segments, thereby improving the security of lightweight video stream data encryption based on the password card; the Gray code sequence and the first key are further encrypted to obtain a key file, and the encrypted video stream and the key file are sent to the decryption end device, so that the decryption end device processes the encrypted video stream based on the key file to obtain the reference video stream, thereby ensuring that the video stream is more secure and efficient during transmission. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0062] Figure 1 A flowchart of a lightweight video stream data encryption method based on a password card provided in an embodiment of the present application;
[0063] Figure 2 A flow chart of the Gray code sequence generation process provided in the embodiment of the present application;
[0064] Figure 3 A schematic diagram of the correspondence between the four-bit binary Gray code, the binary code and the decimal value provided in the embodiment of the present application;
[0065] Figure 4 An exemplary schematic diagram of scrambling video segments according to a Gray code sequence provided in an embodiment of the present application;
[0066] Figure 5 A flowchart of encrypting keys corresponding to video segments provided in an embodiment of the present application;
[0067] Figure 6 A flowchart of key file generation provided in an embodiment of the present application;
[0068] Figure 7 A schematic diagram of a key file provided in an embodiment of the present application;
[0069] Figure 8 A flowchart of a lightweight video stream data decryption method based on a cryptographic card provided in an embodiment of the present application;
[0070] Fig. 9 A video stream decryption flow chart provided in an embodiment of the present application;
[0071] Fig.10 A schematic diagram of the structure of a lightweight video stream data encryption system based on a password card provided in an embodiment of the present application;
[0072] Fig.11 An overall schematic diagram of a lightweight video stream data encryption process based on a password card provided in an embodiment of the present application;
[0073] Fig.12 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;
[0074] Fig.13 A structural diagram of a lightweight video stream data encryption device based on a password card provided in an embodiment of the present application;
[0075] Fig.14 A structural diagram of a lightweight video stream data decryption device based on a cryptographic card provided in an embodiment of the present application. DETAILED DESCRIPTION
[0076] In order to enable those skilled in the art to better understand the technical solutions provided by the embodiments of the present application and to make the above-mentioned purposes, features and advantages of the embodiments of the present application more obvious and understandable, the technical solutions in the embodiments of the present application are further described in detail below in conjunction with the accompanying drawings.
[0077] Video streaming services involve a large amount of data transmitted over the Internet. During the transmission of video streams over the network, they are vulnerable to network attacks, such as hacking into servers, to eavesdrop or tamper with the video streams. Therefore, in order to ensure the security of video stream transmission, the video streams need to be fully encrypted.
[0078] In order to achieve efficient video stream transmission and processing, lightweight technologies or algorithms (such as H.264, H.265, DVC, etc.) are often used to collect, encode, transmit and play the video stream data to obtain lightweight video stream data. By adopting some lightweight video stream libraries, such as JSMPEG, very low latency and efficient video stream processing can be achieved through customized binary data stream transmission.
[0079] During the video stream transmission and storage process, a password card is usually integrated into the device to implement data encryption and decryption. The password card is a hardware encryption and decryption card that can improve the processing speed of data encryption and decryption. The current method for encrypting video streams is usually to use a random key to encrypt the entire video stream to prevent unauthorized visitors or malware from obtaining the plaintext data of the video stream. However, when the entire video traffic is large, a large amount of computing resources will be consumed, and the efficiency of encrypting the entire data stream will be relatively low. At the same time, the security of encryption with a single random key is also low.
[0080] Based on this, the present application proposes a lightweight video stream data encryption method based on a password card to improve the efficiency and security of video stream data encryption.
[0081] Please refer to Figure 1 , Figure 1 A flowchart of a lightweight video stream data encryption method based on a password card provided in an embodiment of the present application, wherein the method is applied to the encryption end of an electronic device.
[0082] like Figure 1 As shown, the method may include the following steps:
[0083] Step 101 : Segment the obtained reference video stream into N video segments, and generate Gray code sequences for the N video segments.
[0084] In this embodiment, the reference video stream is a video stream that needs to be encrypted and transmitted, and the reference video stream may be the above-mentioned lightweight video stream.
[0085] In order to avoid the encryption efficiency being too low due to the reference video stream including too much data, the reference video stream can be divided into N video segments, where N is a preset integer not less than 2, and the value of N can be adjusted according to the amount of data included in the reference video stream. As an embodiment, the larger the amount of data included in the reference video stream, the larger the N value is set.
[0086] In this embodiment, the data volume of each video segment may be the same or different, and this application does not impose any limitation on this.
[0087] In this embodiment, after the reference video stream is divided into N video segments, a Gray code sequence may be generated corresponding to the N video segments. The Gray code sequence includes N different Gray codes, and the N Gray codes correspond to the N video segments in sequence.
[0088] In this embodiment, the arrangement order of the N Gray codes in the generated Gray code sequence can be recorded as the first arrangement order. Since each Gray code corresponds to a video segment, the arrangement order of the N video segments corresponding to the N Gray codes can be recorded as the second arrangement order. The second arrangement order is the initial arrangement order of the N video segments after the reference video stream is divided into N video segments. The reference video stream can be restored by splicing the N video segments according to the second arrangement order.
[0089] As an embodiment, the number of binary digits M of the Gray code in the Gray code sequence is determined according to the logarithm of N with base 2.
[0090] In this embodiment, the number of binary digits M of the generated Gray code can be determined first according to the value of N. Specifically, the number of binary digits of the generated Gray code can be determined by the following formula:
[0091]
[0092] Where M is the number of binary bits of the generated Gray code, N is the number of video segments, represents the logarithm of N to base 2, express The result is rounded up.
[0093] After determining the number of binary bits of the generated Gray code, an initial Gray code of M bits may be randomly generated as the first Gray code in the Gray code sequence.
[0094] In this embodiment, the first Gray code in the Gray code sequence is a randomly generated M-bit Gray code, and adjacent Gray codes in the Gray code sequence have values different in only one binary bit.
[0095] It should be noted that Gray code is a binary encoding method in which two adjacent Gray codes differ by only one binary digit. This encoding method is also called reflected binary or cyclic binary code. For example, if a number is represented by 4 bits of binary, the normal binary sequence is 0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111. The corresponding Gray code sequence is 0000, 0001, 0011, 0010, 0110, 0111, 0101, 0100, 1100, 1101, 1111, 1110, 1010, 1011, 1001, 1000. It can be seen that the adjacent values of Gray code differ by only one binary digit.
[0096] In this embodiment, the first Gray code can be transformed to obtain a Gray code adjacent to the first Gray code in the Gray code sequence, and the adjacent Gray code is different from the first Gray code in only one binary bit. As an embodiment, assuming that the first Gray code is 000, the adjacent Gray code can be 001, or 010, or 100, that is, compared with the first Gray code, only one binary bit has changed.
[0097] Specifically, the method of transforming the Gray code may be to exchange two or more binary bits of the Gray code, or to flip one or more binary bits of the Gray code (ie, flip 0 to 1, flip 1 to 0), etc., and the present application does not limit this.
[0098] It should be noted that after the above transformation is performed on the first Gray code, the obtained code pattern is not necessarily an adjacent Gray code that truly meets the requirements (only one binary bit is different from the initial Gray code), so after the transformation, the obtained code pattern can be further tested to determine whether it is the code pattern of an adjacent Gray code. In the case of determining that it is the code pattern of an adjacent Gray code, it can be further tested whether the code pattern already exists in the Gray code sequence. If so, it indicates that the code pattern cannot be used as an adjacent Gray code.
[0099] After the adjacent Gray code of the first Gray code is determined and added to the Gray code sequence, if the number of Gray codes in the Gray code sequence has not yet reached N, the adjacent Gray code is used as the current Gray code, and the adjacent Gray code of the current Gray code is continuously searched until the number of Gray codes in the Gray code list reaches N, thereby completing the generation of the Gray code sequence.
[0100] According to the following Figure 2 Briefly describe the generation process of a Gray code sequence.
[0101] Please refer to Figure 2 , Figure 2 A flow chart of a Gray code sequence generation process provided in an embodiment of the present application.
[0102] like Figure 2 As shown, after determining the binary bit M of the Gray code to be generated according to N, a Gray code of M bits is randomly generated and saved in the Gray code sequence, and the Gray code is randomly transformed (some bits are exchanged and / or some bits are flipped) to obtain a new code pattern, and further detect whether the new code pattern is valid or repeated. If the new code pattern is valid and not repeated, the code pattern is saved as the Gray code in the Gray code sequence. If the number of Gray codes in the Gray code sequence does not reach N at this time, the step of generating a new Gray code is returned.
[0103] This concludes Figure 2 Description of the Gray code sequence generation process in .
[0104] After the Gray code sequence is determined, the N Gray codes can be respectively matched with the N video segments according to the arrangement order of the Gray codes in the Gray code sequence. The Gray code sequence records the corresponding relationship between the N Gray codes and the N video segments.
[0105] Exemplarily, the corresponding relationship can be that the first Gray code in the Gray code sequence corresponds to the first video segment, the second Gray code in the Gray code sequence corresponds to the second video segment, ..., the Nth Gray code corresponds to the Nth video segment; or the first Gray code in the Gray code sequence corresponds to the Nth video segment, the second Gray code in the Gray code sequence corresponds to the N-1th video segment, ..., the Nth Gray code corresponds to the first video segment, etc., and the present application does not impose any restrictions on this.
[0106] At this point, the description of step 101 ends, and step 102 is executed next.
[0107] Step 102: determining a third arrangement order of the N Gray codes according to the sizes of the N Gray codes, and determining a fourth arrangement order of the N video segments based on the third arrangement order of the N Gray codes.
[0108] In this embodiment, after the Gray code sequence and the video segments corresponding to each Gray code are determined, the video segments corresponding to the Gray code can be sorted according to the sizes of the N Gray codes in the Gray code sequence, and the arrangement of the original video segments can be scrambled.
[0109] In this embodiment, the third arrangement order of the N Gray codes can be determined according to the sizes of the N Gray codes. The size of the Gray code can be determined according to the decimal value corresponding to the Gray code. For example, the larger the decimal value corresponding to the Gray code is, the larger the size of the Gray code is.
[0110] Please refer to Figure 3 , Figure 3 A schematic diagram of the correspondence between a four-bit binary Gray code, a binary code, and a decimal value provided in an embodiment of the present application.
[0111] like Figure 3 As shown, Figure 3 Each four-bit binary Gray code corresponds to a fixed decimal value, and the decimal value corresponding to the Gray code is also different from the arrangement order of the Gray code itself in the Gray code sequence, so the N Gray codes in the Gray code sequence can be reordered by the decimal value corresponding to the Gray code to obtain a third arrangement order.
[0112] Furthermore, since the N Gray codes correspond one to one to the N video segments, after the N Gray codes are sorted according to the third arrangement order, the corresponding N video segments will also be re-arranged to obtain an order different from the original arrangement order, which is recorded as the fourth arrangement order.
[0113] Please refer to Figure 4 , Figure 4 An exemplary schematic diagram of scrambling video segments according to a Gray code sequence is provided in an embodiment of the present application.
[0114] like Figure 4 As shown, the randomly generated Gray code sequence is 10, 00, 01, 11, corresponding to segment 1, segment 2, segment 3 and segment 4 respectively.
[0115] Among them, the decimal numbers corresponding to the Gray codes in the Gray code sequence are 3, 0, 1, and 2, that is, Gray code 10 corresponds to decimal number 3, Gray code sequence 00 corresponds to decimal number 0, Gray code sequence 01 corresponds to decimal number 1, and Gray code sequence 11 corresponds to decimal number 2. Therefore, the Gray codes are sorted in ascending order according to the decimal numbers corresponding to the Gray codes, and the third arrangement order of the Gray codes is 00, 01, 11, 10. The corresponding fourth arrangement order of the video segments is segment 2, segment 3, segment 4, and segment 1, and the scrambled video segments are obtained.
[0116] At this point, the description of step 102 ends, and step 103 is executed next.
[0117] Step 103: Generate a target video stream corresponding to the reference video stream, the target video stream includes N video segments, and the N video segments in the target video stream are arranged according to a fourth arrangement order.
[0118] In this embodiment, when the fourth arrangement order is determined, the N video segments may be sorted according to the fourth arrangement order, and the sorted N video segments may be merged to generate a new video stream, which is recorded as a target video stream.
[0119] At this point, the description of step 103 ends, and step 104 is executed next.
[0120] Step 104: for each video segment in the target video stream, encrypt the video segment based on the first key corresponding to the video segment to obtain an encrypted fragment corresponding to the video segment; and generate an encrypted video stream corresponding to the target video stream based on the encrypted fragment corresponding to each video segment.
[0121] In this embodiment, each video segment corresponds to a first key used to encrypt the video segment. The first keys corresponding to different video segments are the same or different. The first key corresponding to each video segment is obtained from a password card deployed on the encryption end device.
[0122] For each video segment, the video segment may be encrypted using a first key corresponding to the video segment to obtain an encrypted fragment corresponding to the video segment.
[0123] As an embodiment, a specific method of encrypting the video segment based on the first key corresponding to the video segment to obtain the encrypted segment corresponding to the video segment may include:
[0124] For each video segment in the target video stream, a first key corresponding to the video segment is obtained from the password card; wherein the first key corresponding to the video segment is generated by the password card according to a random number generated by the password card for the video segment;
[0125] The video segment is encrypted using a first key to obtain an encrypted fragment corresponding to the video segment.
[0126] In this embodiment, for each video segment, the password card generates a random number for the video segment, and generates a first key corresponding to the video segment based on the random number, so the first key corresponding to each video segment can be obtained from the deployed password card. In other words, each video segment has its own independent first key, and different video segments are protected by different first keys, thereby improving the security of data transmission.
[0127] In this embodiment, after obtaining the encrypted fragments corresponding to each video segment, an encrypted video stream corresponding to the target video stream can be generated based on the encrypted fragments corresponding to each video segment, wherein the arrangement order of the encrypted fragments corresponding to each video segment in the encrypted video stream is the same as the arrangement order of each video segment in the target video stream, that is, the fourth arrangement order.
[0128] At this point, the description of step 104 ends, and step 105 is executed next.
[0129] Step 105: encrypt the Gray code sequence and the first key corresponding to each video segment to obtain a key file.
[0130] In this embodiment, after the encrypted video stream is determined, the initial Gray code sequence and the first key corresponding to each video segment may be encrypted to obtain a key file, which is used to protect the Gray code sequence and each first key from being intercepted in plain text.
[0131] As an embodiment, a specific method of encrypting the Gray code sequence and each first key to obtain a key file may include:
[0132] Encrypting the first keys corresponding to the N video segments using the second key to obtain reference key data, and encrypting the Gray code sequence using the second key to obtain an encrypted Gray code sequence, wherein the reference key data includes the N encrypted first keys;
[0133] Performing integrity check on the second key, the reference key data, the encrypted Gray code sequence and the obtained file description information to obtain an integrity check code; the file description information includes a file version number, the number N of the first keys and a file generation date;
[0134] Generate a key file, which includes an integrity check code, a second key, reference key data, an encrypted Gray code sequence, and file description information.
[0135] In this embodiment, the first keys and Gray code sequences corresponding to the N video segments can be encrypted respectively by using the obtained second key to obtain the first keys corresponding to the N video segments after encryption and the Gray code sequences after encryption. The first keys corresponding to the N video segments after encryption are recorded as reference key data.
[0136] Furthermore, integrity check is performed on the second key, the reference key data, the encrypted Gray code sequence and the obtained file description information to obtain an integrity check code of the key file, which is used to check whether the key file has been tampered with.
[0137] Finally, a key file is generated according to the integrity check code, the second key, the reference key data, the encrypted Gray code sequence and the file description information.
[0138] As an embodiment, before encrypting the first keys corresponding to the N video segments using the second key to obtain the reference key data, the method proposed in this embodiment may further include:
[0139] Obtain the encryption end user access PIN, which is a specific numeric sequence used to verify the identity of the encryption end device user;
[0140] The encryption end user access PIN code is processed based on the target verification algorithm to obtain the encryption end user access PIN code verification value, and the encryption end user access PIN code verification value is used as the second key.
[0141] In this embodiment, the encryption end user access PIN code verification value obtained by processing the encryption end user access PIN code through the target verification algorithm can be used as the second key.
[0142] As an embodiment, the target verification algorithm may be a verification algorithm such as SM3-HASH, SHA-256, etc., and this application does not impose any limitation on this.
[0143] As an embodiment, for the first key corresponding to each video segment, the SM3-HASH verification value of the user access PIN code can be used as the second key, and the first key corresponding to each video segment can be encrypted based on the SM4-CTR algorithm using Base64 or Hex encoding to obtain reference key data.
[0144] Combine the following Figure 5 The process of encrypting the keys corresponding to the video segments proposed in this embodiment is described.
[0145] Please refer to Figure 5 , Figure 5 A flowchart for encrypting keys corresponding to video segments provided in an embodiment of the present application.
[0146] like Figure 5 As shown, the method may include:
[0147] Step 501, encrypt the first key corresponding to each video segment through Mbedtls or Openssl library, select SM4-CTR mode as the encryption algorithm, and select SM3-HASH check value of the user access PIN code as the second key.
[0148] Step 502: Encode the encrypted data using Base64 or Hex.
[0149] Step 503: write the index number of the second key and the encrypted and encoded reference key data into the key file.
[0150] Combine the following Figure 6 The key file generation process provided in the embodiment of the present application proposed in this embodiment is described.
[0151] Please refer to Figure 6 , Figure 6 A flowchart for generating a key file provided in an embodiment of the present application.
[0152] like Figure 6 As shown, the method may include:
[0153] Step 601: Use the SM3-HASH algorithm to calculate the user access PIN code to generate an SM3-HASH check value (as the second key).
[0154] Step 602: The first key and Gray code sequence corresponding to each video segment are processed in turn by encryption and encoding.
[0155] In this embodiment, step 601 and step 602 are actually the process of encrypting the key corresponding to the video segment. Figure 5 The Gray code sequence is encrypted and encoded in the same manner as the key corresponding to the video segment is encrypted and encoded.
[0156] Step 603, write the used encoding method and the SM3-HASH check value of the user access PIN code into the second line of the key file.
[0157] Step 604, write the version number, total number of keys, generation date, and necessary description information of the key file into the corresponding lines of the key file in sequence.
[0158] In this embodiment, the description information of the reference key data may include the version number of the key file, the total number of keys, the generation date, necessary description information, etc., and this application does not impose any restrictions on this.
[0159] Step 605: write the Gray code sequence and each key data (ie, each first key encrypted by the second key) into corresponding lines in the key file.
[0160] Step 606: Use the SM4-HMAC algorithm to calculate all data information of the key file except the first line to generate an integrity check code for the key file.
[0161] Step 607: write the integrity check code into the first line of the key file.
[0162] Step 608, generating the key file.
[0163] In this embodiment, the key file generation process is completed. Please refer to Figure 7 , Figure 7 A schematic diagram of a key file provided for an embodiment of the present application.
[0164] like Figure 7 As shown, the first line of the key file includes the integrity check code of all the information in the key file, which is calculated and generated by the SM4-HMAC algorithm using all the data information of the key file except the first line.
[0165] The second line of the key file includes the key data and the data format of the information package (ie, the encoding method) and the second key, ie, the SM3-HASH value of the user access PIN code required to parse the key file.
[0166] The third line of the key file contains the version number of the key file.
[0167] The fourth line of the key file includes the total number of key data stored in the key file.
[0168] The fifth line of the key file contains the date the key file was generated.
[0169] The sixth line of the key file includes necessary descriptive information of the key file, such as the data size.
[0170] The seventh line of the key file includes the encrypted Gray code sequence data.
[0171] The subsequent lines of the key file record the specific data content of each reference key data.
[0172] This concludes the description of the key file.
[0173] At this point, the description of step 105 ends, and step 106 is executed next.
[0174] Step 106: Send the encrypted video stream and the key file to the decryption end device, so that the decryption end device processes the encrypted video stream based on the key file to obtain a reference video stream.
[0175] In this embodiment, after completing the encryption process of the video stream, the encrypted video stream and the key file can be sent to the decryption end device. After receiving the encrypted video stream and the key file, the decryption end device can process the encrypted video stream based on the key file to obtain a reference video stream, thereby completing the encrypted transmission of the video stream.
[0176] At this point, the description of step 106 is completed. The decryption process of the decryption terminal device will be described in detail below and will not be repeated here.
[0177] This concludes Figure 1 Description of the flowchart of the lightweight video stream data encryption method based on cryptographic card.
[0178] The present application divides a reference video stream to be encrypted into N video segments, generates N Gray codes corresponding to the video segments one by one, and then reorders the N video segments according to the size order of the N Gray codes, encrypts each video segment with a corresponding first key to obtain an encrypted video stream, thereby reducing the consumption of computing resources and improving the response speed; at the same time, different keys are used to encrypt different video segments, thereby improving the security of lightweight video stream data encryption based on a password card; further, the Gray code sequence and the first key are encrypted to obtain a key file, and the encrypted video stream and the key file are sent to a decryption end device, so that the decryption end device processes the encrypted video stream based on the key file to obtain a reference video stream, thereby ensuring that the video stream is more secure and efficient during transmission.
[0179] Please refer to Figure 8 , Figure 8 A flowchart of a lightweight video stream data decryption method based on a cryptographic card provided in an embodiment of the present application, wherein the method is applied to a decryption terminal device.
[0180] like Figure 8 As shown, the method specifically comprises the following steps:
[0181] Step 801, receiving an encrypted video stream and a key file.
[0182] In this embodiment, the decryption end device receives an encrypted video stream and a key file, and the encrypted video stream includes encrypted segments corresponding to N video segments. The encrypted video stream and the key file can be sent directly from the encryption end device to the decryption end device, or sent from the encryption end device to other devices, which are forwarded to the decryption end device by the other devices, and this application does not limit this.
[0183] Step 802: decrypt the key file to obtain a Gray code sequence and a first key corresponding to the N video segments.
[0184] In this embodiment, the key file includes an integrity check code, a second key, reference key data, an encrypted Gray code sequence, and file description information; a specific method of decrypting the key file to obtain the Gray code sequence and the first keys corresponding to the N video segments may include:
[0185] Compare the obtained target key with the second key included in the key file. If the target key is the same as the second key, the identity verification is successful.
[0186] If the identity verification is successful, the second key, the reference key data, the encrypted Gray code sequence and the file description information are integrity checked to obtain a reference verification code of the key file; the file description information includes the version number of the key file, the number N of the encrypted first keys stored in the key file and the generation date of the key file;
[0187] Compare the reference check code with the integrity check code. If the reference check code and the integrity check code are the same, the check passes.
[0188] If the verification is passed, reference key data is obtained from the key file, where the reference key data includes N encrypted first keys; the reference key data is decrypted using the second key to obtain the first keys corresponding to the N video segments;
[0189] The encrypted Gray code sequence is obtained from the key file, and the encrypted Gray code sequence is decrypted by using a second key to obtain a Gray code sequence.
[0190] In this embodiment, after receiving the encrypted video stream and the key file, the decryption end device may first parse the key file to parse out the Gray code sequence and the first keys corresponding to the N video segments from the key file.
[0191] Specifically, after receiving the key file, the decryption end device can compare the obtained target key with the second key included in the key file. Since the second key included in the key file is used to verify the identity of the decryption end device, if the target key obtained by the decryption end device is the same as the second key, it means that the identity verification is successful, and the holder of the current target key is allowed to continue to access the key file.
[0192] After completing the identity verification, the second key, reference key data, encrypted Gray code sequence, file description information and integrity check code included in the key file can be obtained. At this time, the reference check code of the current key file can be calculated based on the second key, reference key data, encrypted Gray code sequence, and file description information included in the key file, and the reference check code is compared with the integrity check code. If the reference check code is the same as the integrity check code, it indicates that the data included in the key file has not been tampered with, and the key file has passed the integrity check.
[0193] If the verification is passed, reference key data can be obtained from the key file, and the reference key data can be decrypted by the second key to obtain the first keys corresponding to the N video segments; and the encrypted Gray code sequence can be obtained from the key file, and the encrypted Gray code sequence can be decrypted by the second key to obtain the Gray code sequence.
[0194] As an embodiment, a method for obtaining a target key may include:
[0195] Obtain a decryption end user access PIN code, which is a specific numeric sequence used to verify the identity of the decryption end device user;
[0196] The decryption end user access PIN code is processed based on the target verification algorithm to obtain the decryption end user access PIN code verification value, and the decryption end user access PIN code verification value is used as the target key.
[0197] In this embodiment, the decryption-end user access PIN code verification value obtained by calculating the decryption-end user access PIN code of the decryption-end device through a target verification algorithm can be used as the target key. The target verification algorithm here is the same as the target verification algorithm corresponding to the encryption-end user access PIN code in the encryption-end device, and the decryption-end user access PIN code of the decryption-end device that is allowed to access the key file should be consistent with the encryption-end user access PIN code of the encryption-end device.
[0198] Step 803: For each encrypted segment corresponding to the video segment, the encrypted segment is decrypted using the first key corresponding to the video segment to obtain the video segment.
[0199] In this embodiment, after the first key corresponding to each video segment is determined, the encrypted segment can be decrypted according to the first key corresponding to the video segment to obtain the video segment.
[0200] Step 804: Generate a target video stream based on the N video segments, and arrange the N video segments in the target video stream according to a fourth arrangement order.
[0201] In this embodiment, the fourth arrangement order is determined according to the third arrangement order corresponding to the size of the N Gray codes in the Gray code sequence. After decrypting each encrypted fragment to obtain N video segments, the N video segments are generated into a target video stream according to the fourth arrangement order.
[0202] Step 805 , based on the first arrangement order of the N Gray codes in the Gray code sequence, arrange the N video segments in the target video stream in a second arrangement order.
[0203] In this embodiment, the second arrangement order is determined according to the first arrangement order of the N Gray codes in the Gray code sequence, and the N video segments in the target video stream can be restored to the second arrangement order based on the first arrangement order of the N Gray codes in the Gray code sequence.
[0204] Step 806: Generate a reference video stream, where the reference video stream includes N video segments arranged in a second arrangement order.
[0205] In this embodiment, after the N video segments are restored to the second arrangement order, the N video segments are synthesized to obtain a reference video stream that initially needs to be encrypted and transmitted.
[0206] This concludes Figure 8 Description of the flowchart of the lightweight video stream data decryption method based on cryptographic card.
[0207] Please refer to Fig. 9 , Fig. 9 A video stream decryption flow chart provided in an embodiment of the present application.
[0208] like Fig. 9 As shown, after receiving the key file, the decryption-end device can input the decryption-end access PIN code to verify the second key included in the key file through the decryption-end access PIN code verification value, that is, to determine whether the user himself parses the key file through the user access PIN code, and then parse the key file after the verification is passed.
[0209] If the verification is successful, the encrypted Gray code sequence is restored through decoding, decryption and other operations, that is, the encryption process is carried out ( Figure 4 and Figure 5 ) to obtain the Gray code sequence.
[0210] Further, by obtaining the total number of reference key data, the corresponding reference key data that needs to be decrypted is obtained according to the key index, and it is determined whether the first key corresponding to the index exists. If it exists, the reference key data is restored through decoding and decryption operations to obtain the first key corresponding to each video segment.
[0211] After the first keys corresponding to the video segments are determined, the encrypted video streams may be further decrypted according to the first keys to obtain the video segments.
[0212] After obtaining each video segment, each video segment can be restored according to the Gray code sequence to obtain a reference video stream.
[0213] Specifically, the video segments corresponding to the Gray codes may be reordered according to the arrangement order of the Gray codes in the Gray code sequence, and the reordered video segments may be merged to obtain a reference video stream.
[0214] In this embodiment, according to the arrangement order of the Gray codes in the Gray code sequence (first arrangement order), the scrambled video segments are reordered (second arrangement order) to restore the initial arrangement, and then the video segments are merged to parse the original reference video stream.
[0215] So far, the end Fig. 9Description of the video stream decryption flow chart.
[0216] Please refer to Fig.10 , Fig.10 A schematic diagram of the structure of a lightweight video stream data encryption system based on a cryptographic card provided in an embodiment of the present application.
[0217] like Fig.10 As shown, the lightweight video stream data encryption system based on the cryptographic card includes:
[0218] Encryption terminal device, used to perform Figure 1 The method shown;
[0219] A cryptographic card, deployed on an encryption terminal device, for generating a first key corresponding to each video segment in a target video stream;
[0220] Decryption terminal device, used to perform Figure 8 The method shown.
[0221] The functions and specific implementation methods of each device in the lightweight video stream data encryption system based on the password card have been described in detail above and will not be repeated here.
[0222] This concludes Fig.10 Description of a lightweight video stream data encryption system based on cryptographic cards.
[0223] Please refer to Fig.11 , Fig.11 An overall schematic diagram of a lightweight video stream data encryption process based on a password card provided in an embodiment of the present application.
[0224] like Fig.11 As shown, after receiving the lightweight video stream from the outside, the input module sends the lightweight video stream to be encrypted to the segment scrambling module.
[0225] The segment scrambling module generates a segment scrambled video stream (video segments arranged in a fourth arrangement order) and a Gray code sequence, and sends the scrambled video stream and the Gray code sequence to the encryption module.
[0226] After receiving the video stream after the segmented scrambling module sends the video stream, the encryption module encrypts each segment of the video stream using the password card to generate an encrypted video stream.
[0227] The key file encapsulation module encrypts the generated key and Gray code sequence, generates a key file, and sends it to the output module.
[0228] After receiving the encrypted video stream sent by the encryption module and the key file sent by the key file encapsulation module, the output module packages the encrypted video stream and the key file and sends them to the receiving module.
[0229] After the receiving module unpacks the key file, it sends the key file to the key file parsing module. After the key file parsing module parses the key file, it sends the key and Gray code sequence in the key file to the decryption module.
[0230] The decryption module receives the encrypted video stream sent by the receiving module and the key and Gray code sequence sent by the key file parsing module.
[0231] The decryption module decrypts each encrypted video stream, restores the order of the video stream through the Gray code sequence, and obtains the original video stream.
[0232] It is easy to understand that the functions of the above modules can be based on Figure 1 as well as Figure 8 The method shown is specifically implemented.
[0233] This concludes Fig.11 Description of the overall schematic diagram of the lightweight video stream data encryption process based on cryptographic cards.
[0234] Please refer to Fig.12 , Fig.12 It is a schematic structural diagram of an electronic device proposed in an embodiment of the present application. At the hardware level, the electronic device includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and of course may also include hardware required for other services. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it, forming a terminal interaction device at the logical level. Of course, in addition to the software implementation method, this application does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0235] Please refer to Fig.13 , Fig.13 1 is a structural diagram of a lightweight video stream data encryption device based on a password card proposed in an embodiment of the present application, and the device is applied to the encryption end of an electronic device. Fig.13 As shown, the lightweight video stream data encryption device based on the password card may include a segmentation unit 1301, a sorting unit 1302, an encryption unit 1303 and a sending unit 1304. Specifically, the device includes:
[0236] The segmentation unit 1301 is used to segment the obtained reference video stream into N video segments, and generate a Gray code sequence for the N video segments; wherein the Gray code sequence includes N different Gray codes, the N Gray codes correspond to the N video segments respectively, and N is an integer not less than 2; the arrangement order of the N Gray codes in the Gray code sequence is a first arrangement order, and the arrangement order of the N video segments corresponding to the N Gray codes is a second arrangement order;
[0237] The sorting unit 1302 is used to determine a third arrangement order of the N Gray codes according to the sizes of the N Gray codes, and determine a fourth arrangement order of the N video segments based on the third arrangement order of the N Gray codes;
[0238] Generate a target video stream corresponding to the reference video stream, the target video stream including N video segments, and the N video segments in the target video stream are arranged according to a fourth arrangement order;
[0239] The encryption unit 1303 is used to encrypt each video segment in the target video stream based on the first key corresponding to the video segment to obtain an encrypted segment corresponding to the video segment; based on the encrypted segment corresponding to each video segment, an encrypted video stream corresponding to the target video stream is generated; the first key is obtained from a password card deployed on the encryption terminal device;
[0240] Encrypting the Gray code sequence and the first key corresponding to each video segment to obtain a key file;
[0241] The sending unit 1304 is used to send the encrypted video stream and the key file to the decryption end device, so that the decryption end device processes the encrypted video stream based on the key file to obtain a reference video stream.
[0242] Optionally, for a Gray code in a Gray code sequence, a binary digit M of the Gray code is determined according to a logarithm of N with base 2;
[0243] The first Gray code in the Gray code sequence is a randomly generated M-bit Gray code, and adjacent Gray codes in the Gray code sequence have values different in only one binary bit.
[0244] Optionally, the encryption unit 1303 is specifically used for:
[0245] For each video segment in the target video stream, a first key corresponding to the video segment is obtained from the password card; wherein the first key corresponding to the video segment is generated by the password card according to a random number generated by the password card for the video segment;
[0246] The video segment is encrypted using a first key to obtain an encrypted fragment corresponding to the video segment.
[0247] Optionally, the encryption unit 1303 is specifically used for:
[0248] Encrypting the first keys corresponding to the N video segments using the second key to obtain reference key data, and encrypting the Gray code sequence using the second key to obtain an encrypted Gray code sequence, wherein the reference key data includes the N encrypted first keys;
[0249] Performing integrity check on the second key, the reference key data, the encrypted Gray code sequence and the obtained file description information to obtain an integrity check code; the file description information includes a file version number, the number N of the first keys and a file generation date;
[0250] Generate a key file, which includes an integrity check code, a second key, reference key data, an encrypted Gray code sequence, and file description information.
[0251] Optionally, before encrypting the first keys corresponding to the N video segments using the second key to obtain the reference key data, the encryption unit 1303 is further used to:
[0252] Obtain the encryption end user access PIN, which is a specific numeric sequence used to verify the identity of the encryption end device user;
[0253] The encryption end user access PIN code is processed based on the target verification algorithm to obtain the encryption end user access PIN code verification value, and the encryption end user access PIN code verification value is used as the second key.
[0254] So far, completed Fig.13 Description of a lightweight video stream data encryption device based on a cryptographic card.
[0255] Please refer to Fig.14 , Fig.14 1 is a structural diagram of a lightweight video stream data decryption device based on a password card proposed in an embodiment of the present application, and the device is applied to the decryption end of an electronic device. Fig.14 As shown, the lightweight video stream data decryption device based on the password card may include a receiving unit 1401, a decryption unit 1402 and a sorting unit 1403. Specifically, the device includes:
[0256] The receiving unit 1401 is used to receive an encrypted video stream and a key file; the encrypted video stream includes encrypted segments corresponding to N video segments;
[0257] A decryption unit 1402 is used to decrypt the key file to obtain a Gray code sequence and a first key corresponding to the N video segments;
[0258] For each encrypted segment corresponding to the video segment, decrypt the encrypted segment using the first key corresponding to the video segment to obtain the video segment;
[0259] Generating a target video stream based on the N video segments, wherein the N video segments in the target video stream are arranged according to a fourth arrangement order; wherein the fourth arrangement order is determined according to a third arrangement order corresponding to the sizes of the N Gray codes in the Gray code sequence;
[0260] The sorting unit 1403 is used to sort the N video segments in the target video stream according to a second sorting order based on the first sorting order of the N Gray codes in the Gray code sequence; the second sorting order is determined according to the first sorting order of the N Gray codes in the Gray code sequence;
[0261] A reference video stream is generated, wherein the reference video stream includes N video segments arranged in a second arrangement order.
[0262] Optionally, the key file includes an integrity check code, a second key, reference key data, an encrypted Gray code sequence, and file description information; the decryption unit 1402 is specifically used for:
[0263] Compare the obtained target key with the second key included in the key file. If the target key is the same as the second key, the identity verification is successful.
[0264] If the identity verification is successful, the second key, the reference key data, the encrypted Gray code sequence and the file description information are integrity checked to obtain a reference verification code of the key file; the file description information includes the version number of the key file, the number N of the encrypted first keys stored in the key file and the generation date of the key file;
[0265] Compare the reference check code with the integrity check code. If the reference check code and the integrity check code are the same, the check passes.
[0266] If the verification is passed, reference key data is obtained from the key file, where the reference key data includes N encrypted first keys; the reference key data is decrypted using the second key to obtain the first keys corresponding to the N video segments;
[0267] The encrypted Gray code sequence is obtained from the key file, and the encrypted Gray code sequence is decrypted by using a second key to obtain a Gray code sequence.
[0268] Optionally, the method for obtaining the target key includes:
[0269] Obtain a decryption end user access PIN code, which is a specific numeric sequence used to verify the identity of the decryption end device user;
[0270] The decryption end user access PIN code is processed based on the target verification algorithm to obtain the decryption end user access PIN code verification value, and the decryption end user access PIN code verification value is used as the target key.
[0271] So far, completed Fig.14 A description of a lightweight video stream data decryption device based on a cryptographic card.
[0272] Correspondingly, in this embodiment, the embodiment of the present application also provides a computer-readable storage medium, on which a number of computer instructions are stored. When the computer instructions are executed, the method disclosed in the above example of the present application can be implemented.
[0273] Exemplarily, the computer-readable storage medium may be any electronic, magnetic, optical or other physical storage device that may contain or store information, such as executable instructions, data, etc. For example, the computer-readable storage medium may be: RAM (Radom Access Memory), volatile memory, non-volatile memory, flash memory, storage drive (such as hard disk drive), solid state drive, any type of storage disk (such as optical disk, DVD, etc.), or similar storage medium, or a combination thereof.
[0274] The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the scope of protection of the present application.
Claims
1. A lightweight video stream data encryption method based on a password card, characterized in that: The method is applied to an encryption end device, and the method includes: The obtained reference video stream is divided into N video segments, and a Gray code sequence is generated for the N video segments; wherein the Gray code sequence includes N different Gray codes, the N Gray codes correspond to the N video segments respectively, and N is an integer not less than 2; the arrangement order of the N Gray codes in the Gray code sequence is a first arrangement order, and the arrangement order of the N video segments corresponding to the N Gray codes is a second arrangement order; Determining a third arrangement order of the N Gray codes according to the sizes of the N Gray codes, and determining a fourth arrangement order of the N video segments based on the third arrangement order of the N Gray codes; Generate a target video stream corresponding to the reference video stream, the target video stream including the N video segments, the N video segments in the target video stream being arranged according to the fourth arrangement order; For each video segment in the target video stream, encrypt the video segment based on the first key corresponding to the video segment to obtain an encrypted segment corresponding to the video segment; generate an encrypted video stream corresponding to the target video stream based on the encrypted segment corresponding to each video segment; the first key is obtained from a password card deployed on the encryption terminal device; Encrypting the Gray code sequence and the first key corresponding to each video segment to obtain a key file; The encrypted video stream and the key file are sent to a decryption end device, so that the decryption end device processes the encrypted video stream based on the key file to obtain the reference video stream.
2. The method according to claim 1, characterized in that For the Gray code in the Gray code sequence, the number of binary bits M of the Gray code is determined according to the logarithm of N with base 2; The first Gray code in the Gray code sequence is a randomly generated M-bit Gray code, and adjacent Gray codes in the Gray code sequence have values that differ in only one binary bit.
3. The method according to claim 1, characterized in that The step of encrypting the video segment based on the first key corresponding to the video segment to obtain an encrypted segment corresponding to the video segment includes: For each video segment in the target video stream, obtaining a first key corresponding to the video segment from the password card; wherein the first key corresponding to the video segment is generated by the password card according to a random number generated by the password card for the video segment; The video segment is encrypted using the first key to obtain an encrypted fragment corresponding to the video segment.
4. The method according to claim 1, characterized in that: The step of encrypting the Gray code sequence and each first key to obtain a key file includes: Encrypting the first keys corresponding to the N video segments using the second key to obtain reference key data, and encrypting the Gray code sequence using the second key to obtain an encrypted Gray code sequence, wherein the reference key data includes the N encrypted first keys; Performing integrity check on the second key, the reference key data, the encrypted Gray code sequence and the obtained file description information to obtain an integrity check code; the file description information includes a file version number, the number N of first keys and a file generation date; Generate a key file, wherein the key file includes the integrity check code, the second key, the reference key data, the encrypted Gray code sequence, and the file description information.
5. The method according to claim 4, characterized in that Before encrypting the first keys corresponding to the N video segments using the second key to obtain the reference key data, the method further includes: Obtaining an encryption end user access PIN code, wherein the encryption end user access PIN code is a specific numeric sequence used to verify the identity of the encryption end device user; The encryption end user access PIN code is processed based on a target verification algorithm to obtain an encryption end user access PIN code verification value, and the encryption end user access PIN code verification value is used as a second key.
6. A lightweight video stream data decryption method based on a cryptographic card, characterized in that: The method is applied to a decryption terminal device, and the method comprises: Receiving an encrypted video stream and a key file; the encrypted video stream includes encrypted segments corresponding to N video segments; Decrypting the key file to obtain a Gray code sequence and a first key corresponding to the N video segments; For each encrypted segment corresponding to the video segment, decrypt the encrypted segment using the first key corresponding to the video segment to obtain the video segment; Generate a target video stream based on N video segments, wherein the N video segments in the target video stream are arranged in a fourth arrangement order; wherein the fourth arrangement order is determined according to a third arrangement order corresponding to the sizes of the N Gray codes in the Gray code sequence; Arranging the N video segments in the target video stream in a second arrangement order based on a first arrangement order of the N Gray codes in the Gray code sequence; the second arrangement order is determined according to the first arrangement order of the N Gray codes in the Gray code sequence; A reference video stream is generated, wherein the reference video stream includes N video segments arranged in the second arrangement order.
7. The method according to claim 6, characterized in that The key file includes an integrity check code, a second key, reference key data, an encrypted Gray code sequence, and file description information; the decryption process of the key file to obtain the Gray code sequence and the first keys corresponding to the N video segments includes: Compare the obtained target key with the second key included in the key file, and if the target key is the same as the second key, the identity verification is successful; If the identity verification is successful, an integrity check is performed on the second key, the reference key data, the encrypted Gray code sequence and the file description information to obtain a reference verification code of the key file; the file description information includes a version number of the key file, the number N of the encrypted first keys stored in the key file and a generation date of the key file; Compare the reference check code with the integrity check code, and if the reference check code is the same as the integrity check code, the check passes; If the verification is passed, obtaining reference key data from the key file, the reference key data including N encrypted first keys; decrypting the reference key data using the second key to obtain the first keys corresponding to the N video segments; The encrypted Gray code sequence is obtained from the key file, and the encrypted Gray code sequence is decrypted by using a second key to obtain a Gray code sequence.
8. The method according to claim 7, characterized in that The method for obtaining the target key includes: Obtaining a decryption end user access PIN code, wherein the decryption end user access PIN code is a specific digital sequence used to verify the identity of the decryption end device user; The decryption end user access PIN code is processed based on a target verification algorithm to obtain a decryption end user access PIN code verification value, and the decryption end user access PIN code verification value is used as a target key.
9. A lightweight video stream data encryption device based on a password card, characterized in that: The device is applied to an encryption terminal device, and the device includes: A segmentation unit, configured to segment the obtained reference video stream into N video segments, and generate a Gray code sequence for the N video segments; wherein the Gray code sequence includes N different Gray codes, the N Gray codes correspond to the N video segments respectively, and N is an integer not less than 2; the arrangement order of the N Gray codes in the Gray code sequence is a first arrangement order, and the arrangement order of the N video segments corresponding to the N Gray codes is a second arrangement order; a sorting unit, configured to determine a third arrangement order of the N Gray codes according to the sizes of the N Gray codes, and determine a fourth arrangement order of the N video segments based on the third arrangement order of the N Gray codes; Generate a target video stream corresponding to the reference video stream, the target video stream including the N video segments, the N video segments in the target video stream being arranged according to the fourth arrangement order; The encryption unit is used to encrypt each video segment in the target video stream based on a first key corresponding to the video segment to obtain an encrypted segment corresponding to the video segment; based on the encrypted segment corresponding to each video segment, an encrypted video stream corresponding to the target video stream is generated; the first key is obtained from a password card deployed on the encryption terminal device; Encrypting the Gray code sequence and the first key corresponding to each video segment to obtain a key file; The sending unit is used to send the encrypted video stream and the key file to a decryption end device, so that the decryption end device processes the encrypted video stream based on the key file to obtain the reference video stream.
10. A lightweight video stream data decryption device based on a password card, characterized in that: The device is applied to a decryption terminal device, and comprises: A receiving unit, configured to receive an encrypted video stream and a key file; the encrypted video stream includes encrypted segments corresponding to N video segments; A decryption unit, used for decrypting the key file to obtain a Gray code sequence and a first key corresponding to the N video segments; For each encrypted segment corresponding to the video segment, decrypt the encrypted segment using the first key corresponding to the video segment to obtain the video segment; Generate a target video stream based on N video segments, wherein the N video segments in the target video stream are arranged in a fourth arrangement order; wherein the fourth arrangement order is determined according to a third arrangement order corresponding to the sizes of the N Gray codes in the Gray code sequence; a sorting unit, configured to sort the N video segments in the target video stream according to a second sorting order based on the first sorting order of the N Gray codes in the Gray code sequence; the second sorting order is determined according to the first sorting order of the N Gray codes in the Gray code sequence; A reference video stream is generated, wherein the reference video stream includes N video segments arranged in the second arrangement order.
11. A lightweight video stream data encryption system based on a cryptographic card, characterized in that: include: An encryption terminal device, used to execute the method according to any one of claims 1 to 5; A password card, deployed in the encryption terminal device, for generating a first key corresponding to each video segment in the target video stream; A decryption terminal device, used to execute the method as described in any one of claims 6 to 8.
