Encryption and decryption method and system based on dynamic offset embedding
By embedding PSSH data in the video file according to dynamic offsets, the problems of DRM information leakage and low security in traditional DRM systems are solved, and higher concealment and security are achieved, and copyright protection is enhanced.
Patent Information
- Application Number
- CN202411167587.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-23
- Publication Date
- 2024-11-12
AI Technical Summary
Traditional DRM systems directly place DRM key information such as PSSH in MPD files, resulting in extremely high risk of leakage during transmission and storage. Attackers can easily locate and parse MPD files to obtain PSSH data, reducing the DRM system. overall security.
Using encryption and decryption methods based on dynamic offset embedding, the embed offset is calculated by obtaining the key information of the video file (such as file size, bit rate, unique identifier and file name), and inserting or extracting it at the offset. PSSH data to avoid direct exposure to MPD files or other accessible metadata.
It improves the concealment and security of DRM information, reduces the risk of DRM information being leaked during transmission and storage, and enhances the protection capabilities of the DRM system and the copyright protection of video content.
Smart Images

Figure CN118945398A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to an encryption and decryption method and system based on dynamic offset embedding. Background Art
[0002] With the popularity of digital content, such as video, audio, and e-books, digital rights management (DRM) technology has become increasingly important. DRM systems are designed to protect the copyright of digital content and prevent unauthorized copying, distribution, and abuse. However, traditional DRM systems have some significant limitations and challenges in implementation. In particular, traditional DRM systems usually embed key DRM information such as PSSH (Protection System Specific Header) data directly into MPD files or other accessible metadata. Although this approach simplifies the implementation of DRM, it also greatly increases the risk of DRM information being leaked and attacked.
[0003] At present, there are the following technical problems for encryption and decryption of DRM systems:
[0004] (1) The traditional method places key DRM information such as PSSH directly in the MPD file. Since the MPD file is usually transmitted in plain text and is a file that must be accessed when playing the video, any user who can obtain the file can directly read and parse the PSSH data in it, which makes the DRM information face a very high risk of leakage during transmission and storage.
[0005] (2) Due to the direct exposure of PSSH information, attackers can easily locate and parse MPD files to obtain PSSH data, making it easy for attackers to bypass DRM protection and copy, tamper with, and pirate video content, thereby reducing the overall security of the DRM system. Summary of the invention
[0006] The object of the present invention is to provide a method and system for encryption and decryption based on dynamic offset embedding, so as to solve the problems mentioned in the above background technology that the existing DRM information is exposed and has been exploited by attackers.
[0007] To achieve the above object, the present invention adopts the following technical solutions:
[0008] According to one aspect of the present invention, a method for encryption and decryption based on dynamic offset embedding is provided, the method comprising:
[0009] Acquire key information of the video file, and calculate the embedding offset according to the key information, wherein the key information includes file size, bit rate, unique identifier and file name;
[0010] Inserting PSSH data at the embedding offset of the video file during encryption to reassemble the video file;
[0011] During decryption, the PSSH data is extracted from the embedded offset of the video file, and the PSSH data is used for decryption.
[0012] Based on the above solution, the step of calculating the embedding offset according to the key information includes:
[0013] Define a constant as the maximum offset;
[0014] Summing the ASCII code value of each character of the unique identifier to generate a first numerical value;
[0015] Performing a hash operation on the file name to generate a second value;
[0016] Taking the file size, the bit rate, and the unique identifier modulo the maximum offset, respectively, to obtain a first modulus value, a second modulus value, and a third modulus value;
[0017] The first modulus value, the second modulus value, the third modulus value, the first numerical value, and the second numerical value are added together, and then the modulus of the maximum offset is taken to obtain the embedded offset.
[0018] Based on the above scheme, the first value and the second value are integer values, and the second value is an integer converted from a hexadecimal string after hash calculation of the file name.
[0019] Based on the above scheme, the reassembling of the video file includes defining the data structure of the video file into three parts: the initial position of the video file to the embedded offset as the first file block; the remaining part of the video file as the second file block; and the PSSH data.
[0020] Based on the above scheme, the binary data of the video file is read and stored, and a data container is created. In the data container, the first file block, the PSSH data, and the second file block are reassembled and written back to the original video file for replacement.
[0021] Based on the aforementioned scheme, the decryption using the PSSH data includes decrypting the video content using a corresponding DRM system or key management service according to the PSSH data.
[0022] Based on the above scheme, the encryption process includes obtaining the key information of the video file, calculating the embedding offset, and inserting the PSSH data at the embedding offset to reassemble the video file.
[0023] Based on the aforementioned scheme, the decryption process includes obtaining the key information of the video file, calculating the embedded offset, extracting the PSSH data at the embedded offset, and decrypting the video content using the corresponding DRM system or key management service according to the PSSH data.
[0024] According to another aspect of the present invention, there is provided a system for encryption and decryption based on dynamic offset embedding, the system comprising: an information acquisition module, a data embedding module, and a data extraction module;
[0025] The information acquisition module reads the video file and obtains key information, and calculates the embedding offset according to the key information;
[0026] The data embedding module is used to insert PSSH data at the embedding offset during encryption to reassemble the video file;
[0027] The data extraction module is used to extract the PSSH data at the embedded offset during decryption and perform decryption based on the PSSH data.
[0028] Based on the aforementioned scheme, the key information includes but is not limited to file size, bit rate, unique identifier and file name.
[0029] It can be seen from the above technical solutions that the present invention has at least the following advantages and positive effects compared with the prior art:
[0030] The embedding offset is dynamically calculated according to specific key information of the video file, and the PSSH data is inserted into the video file at the embedding offset, so that the position of the PSSH data is difficult to predict and locate, thereby improving the concealment and security of the DRM information; the PSSH data is embedded in the video file data instead of being placed directly in the MPD file or other accessible metadata, which effectively reduces the risk of DRM information being leaked during transmission and storage.
[0031] The present invention should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] The drawings herein are incorporated into and constitute a part of the specification, showing embodiments consistent with the present invention, and together with the specification, are used to explain the principles of the present invention. Obviously, the drawings described below are only some embodiments of the present invention, and for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0033] Figure 1 A schematic diagram of an encryption and decryption method based on dynamic offset embedding according to the present invention;
[0034] Figure 2 A schematic diagram of a method for calculating an embedding offset according to the present invention;
[0035] Figure 3 This is a schematic diagram of encryption based on dynamic offset embedding according to the present invention;
[0036] Figure 4 A schematic diagram of decryption based on dynamic offset embedding of the present invention;
[0037] Figure 5 The present invention is a schematic diagram of an encryption and decryption system based on dynamic offset embedding. DETAILED DESCRIPTION
[0038] In order to more clearly explain the purpose, technical solutions and advantages of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. The example implementation methods can be implemented in various forms and should not be understood as being limited to the examples described herein. On the contrary, these implementation methods are provided to make the present invention more comprehensive and complete, and to fully convey the concepts of the example implementation methods to those skilled in the art.
[0039] In addition, the described features, structures or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present invention. However, those skilled in the art will appreciate that the technical solution of the present invention can be practiced without one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known methods, devices, implementations or operations are not shown or described in detail to avoid blurring various aspects of the present invention.
[0040] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0041] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0042] The present invention is described in detail below in conjunction with specific embodiments:
[0043] Example 1
[0044] like Figure 1 As shown, this embodiment provides an encryption and decryption method based on dynamic offset embedding, and the specific steps of the method are as follows:
[0045] S1: Acquire key information of a video file, and calculate an embedding offset according to the key information, wherein the key information includes file size, bit rate, unique identifier, and file name.
[0046] In this embodiment, ffmpeg is used to obtain the file size and bit rate of the video file, Python's uuid library is used to generate a unique identifier for the video file, and finally the file name is defined according to business requirements. Specifically, the key information of the obtained video file is as follows:
[0047] File size: file_size = 50000000 bytes;
[0048] Bit rate: bitrate = 2000000bps;
[0049] Video unique identifier: video_id = 'abc123xyz';
[0050] File name: filename="example_video.mp4".
[0051] like Figure 2 As shown, the calculation of the embedding offset according to the key information includes:
[0052] Define a constant as the maximum offset; sum the ASCII code value of each character of the unique identifier to generate a first value; perform a hash operation on the file name to generate a second value; take the file size, the bit rate, and the unique identifier modulo the maximum offset to obtain a first modulus value, a second modulus value, and a third modulus value respectively; add the first modulus value, the second modulus value, the third modulus value, the first value, and the second value, and then take the modulus of the maximum offset to obtain the embedded offset.
[0053] Furthermore, the first value and the second value are integer values, and the second value is an integer converted from a hexadecimal string after hash calculation of the file name; the maximum offset is set to 1MB to ensure that the calculated offset is within 1MB.
[0054] Specifically, define a constant max_offset, whose value is 1MB (i.e., 1024*1024 bytes). This maximum offset constant is used to ensure that all calculated embedding offsets are within 1MB and do not exceed the predetermined safe or effective range; assume that the unique identifier (video_id) of the video file obtained is 'abc123xyz', the file name (filename) of the video file is "example_video.mp4", the file size (file_size) of the video file is 50000000 bytes, and the bit rate (bitrate) of the video file is 2000000bps;
[0055] Further, the ASCII code value of each character of the unique identifier is summed to generate a first value, including: traversing each character in the unique identifier (video_id) of the video file, obtaining the ASCII code value of each character, adding all the ASCII code values, and obtaining the ASCII code sum of the unique identifier (video_id), which is the first value. The first value is 807 obtained by summing the ASCII codes according to the above parameter video_id='abc123xyz';
[0056] Further, performing a hash operation on the file name to generate a second value includes: using the hashlib.sha256() function to perform a SHA-256 hash operation on the file name (filename), and converting the obtained hash value (a hexadecimal string by default) into an integer using the int() function and base 16, recorded as filename_hash, which is the second value;
[0057] Specifically, the calculation process is: hash "example_video.mp4" and convert it into an integer: filename_hash = int(hashlib.sha256(filename.encode()).hexdigest(),16), where the second value can be obtained as: 63559141560301356635582117621287335408947010327390883848911386115325248693898;
[0058] Further, the file size, the bit rate, and the unique identifier are respectively modulo the maximum offset to obtain a first modulus value, a second modulus value, and a third modulus value, respectively, including: performing a modulo operation on the file size (file_size), the modulus being max_offset, to obtain mod_file_size, which is the first modulus value; performing a modulo operation on the bit rate (bitrate), the modulus being max_offset, to obtain mod_bitrate, which is the second modulus value; performing a modulo operation on the unique identifier (video_id), the modulus being max_offset, to obtain mod_video_id, which is the third modulus value; specifically, the calculation process is:
[0059] mod_file_size=file_size%max_offset;50000000%1048576=764416;
[0060] mod_bitrate=bitrate%max_offset;2000000%1048576=905424;
[0061] mod_video_id=video_id%max_offset;807%1048576=807;
[0062] Further, the first modulus value, the second modulus value, the third modulus value, the first value and the second value are added together and then the maximum offset is modulo-calculated to obtain the embedded offset, including: adding mod_file_size, mod_bitrate, mod_video_id and filename_hash and then performing a modulus operation, the modulus being max_offset, to obtain the embedded offset (offset); specifically, the calculation process is:
[0063] offset=(mod_file_size+mod_bitrate+mod_video_id+filename_hash)%max_offset; result of interpolation calculation (example): offset=732325.
[0064] S2: inserting PSSH data at the embedding offset of the video file during encryption to reassemble the video file;
[0065] Specifically, the reassembling of the video file includes defining the data structure of the video file into three parts: the start position of the video file to the embedded offset as the first file block; the remaining part of the video file as the second file block; and the PSSH data.
[0066] Furthermore, binary data of the video file is read and stored, and a data container is created. The first file block, the PSSH data, and the second file block are reassembled in the data container and written back to the original video file for replacement.
[0067] Specifically, PSSH (Protection System Specific Header), that is, protection system specific header information, is a mechanism used in the DRM system to identify and transmit specific system information related to content protection; it is usually embedded in the metadata of the media stream or media file so that the DRM client can identify and process the protected content. In the process of streaming media transmission, PSSH data is an important basis for the DRM client to request the decryption key from the license server; the client parses the information in the PSSH data, constructs a key request message, and sends it to the license server; the server verifies the client's authority based on the PSSH data in the request and returns the corresponding decryption key. By embedding PSSH data, the DRM system can monitor and control the distribution and use of content, prevent unauthorized copying, dissemination and tampering, and thus protect the copyright and interests of content creators. Furthermore, when the client plays the protected content, it will first parse the PSSH data and construct a key request message based on the information therein; after receiving the request, the license server will verify the client's authority and return the corresponding decryption key, so that the client can play the protected content normally.
[0068] In this embodiment, after the PSSH data is encrypted, it is not directly exposed to the file or data stream. Instead, a dynamic calculation algorithm is used to determine the embedding position of the PSSH data, that is, the embedding offset, and the encrypted PSSH data is embedded into the video transmission data based on the offset. This not only makes the position of the PSSH data in the video file difficult to predict and extract, thereby increasing the security or compatibility of the video file during transmission or storage, but also significantly enhances the protection capability of the DRM system and the copyright protection level of the video content.
[0069] Specifically, in this embodiment, Python is used to open the video file in binary reading mode, the content of the entire video file is read into video_data, a new data container new_data is created, and the first offset bytes of the video file are first copied to new_data; PSSH data is inserted at the offset position of new_data; the remaining part of the video file is then appended to new_data, and finally new_data is written back to the original video file to replace the original video content.
[0070] Furthermore, the embedding offset (offset) calculated in step S1 divides the original video file into two parts: a first file block and a second file block; the first file block is all bytes from the beginning of the video file to the embedding offset (offset) (excluding the bytes at the embedding offset position), and the second file block is all bytes from the embedding offset position to the end of the video file. PSSH data is inserted between the first file block and the second file block data, that is, the first file block, PSSH data and the second file block are connected (or spliced) to form a new byte string new_data; new_data is the complete video data including PSSH data, and new_data is written back to the file system; optionally, the original video file is overwritten, the original video file is opened in binary write mode and new_data is written to the file; or, it is written to a new file.
[0071] It should be noted that if Figure 3 As shown, the encryption process includes obtaining the key information of the video file, calculating the embedding offset according to the key information, and inserting the PSSH data at the embedding offset to reassemble the video file.
[0072] S3: extracting the PSSH data from the embedded offset of the video file during decryption, and using the PSSH data for decryption.
[0073] In this embodiment, the decrypting using the PSSH data includes decrypting the video content using a corresponding DRM system or a key management service according to the PSSH data.
[0074] Specifically, Figure 4As shown, the decryption process includes obtaining the key information of the video file, calculating the embedding offset, extracting the PSSH data at the embedding offset, and decrypting the video content using the corresponding DRM system or key management service according to the PSSH data. Further, during decryption, first repeat step S1 to obtain the key information of the video file, and use the same algorithm to calculate the embedding offset (offset); extract the PSSH data from the embedding offset (offset) position of the video file, and the size and format of the PSSH data need to be defined in advance or determined according to the specific DRM system specification; according to the extracted PSSH data, use the corresponding DRM system or key management service to decrypt the video content, so that the decrypted video content can be re-encoded or directly played.
[0075] It should be noted that, in this embodiment, even for the same video file, the calculated embedding offset may be different in different situations, which mainly depends on whether the key information used to calculate the embedding offset has changed and how the key information is used in the calculation process; the key information includes file size, bit rate, unique identifier and file name, and any change in any of the parameters may result in a different embedding offset calculated in the end. For example, for file size, if the video file is edited or compressed before encryption, resulting in a change in file size, the calculated embedding offset will also change accordingly; for bit rate, although the content of the video file may not change, if the bit rate is re-encoded or adjusted (for example, from high definition to standard definition), the change in bit rate will also affect the calculation of the embedding offset; for unique identifier, if the unique identifier of the video file (such as generated by a certain hash algorithm) is generated based on the current timestamp, random number or other dynamic factors each time it is encrypted, then even if the video content is the same, the unique identifier will be different, resulting in different embedding offsets; for file name, the file name may also contain dynamic information, such as date, timestamp or user ID, if the file name is changed or contains dynamic elements during the encryption process, then this will also affect the calculation of the embedding offset.
[0076] Example 2
[0077] like Figure 5 As shown, this embodiment exemplarily presents an encryption and decryption system based on dynamic offset embedding, including an information acquisition module, a data embedding module, and a data extraction module;
[0078] The information acquisition module reads the video file and obtains key information, and calculates the embedding offset according to the key information; the data embedding module is used to insert PSSH data at the embedding offset during encryption and reassemble the video file; the data extraction module is used to extract the PSSH data at the embedding offset during decryption and perform decryption based on the PSSH data.
[0079] In this embodiment, the information acquisition module reads the video file and obtains key information, including file size, bit rate, unique identifier and file name, and calculates the embedding offset based on these key information for inserting PSSH data into the video file; the interface design is implemented: the input is the video file path, and the output is the key information and the embedding offset. The data embedding module inserts the PSSH data into the video file at the calculated embedding offset to ensure that the insertion operation does not destroy the integrity and playability of the video file, and reassembles the video file after completion; the interface design is implemented: the input is the video file, PSSH data, and the embedding offset, and the output is the encrypted video file. The data extraction module reads the encrypted video file, extracts the PSSH data from the specified position according to the calculated embedding offset, verifies the integrity and correctness of the extracted PSSH data, performs the decryption operation using the PSSH data extracted from the video file, and restores the original content of the video file according to the decryption key or related information contained in the PSSH; the interface design is implemented: the input is the encrypted video file and the embedding offset, and the output is the decrypted video file. Optionally, a user interface or API interface is provided to coordinate the workflow of the above modules and manage encryption and decryption tasks, including error handling and logging.
[0080] Those skilled in the art will readily appreciate other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. This application is intended to cover any modification, use or adaptation of the present invention, which follows the general principles of the present invention and includes common knowledge or customary techniques in the art that are not disclosed by the present invention. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present invention are indicated by the claims. It should be understood that the present invention is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.
Claims
1. A method for encryption and decryption based on dynamic offset embedding, characterized in that: The method comprises: Acquire key information of the video file, and calculate the embedding offset according to the key information, wherein the key information includes file size, bit rate, unique identifier and file name; Inserting PSSH data at the embedding offset of the video file during encryption to reassemble the video file; During decryption, the PSSH data is extracted from the embedded offset of the video file, and the PSSH data is used for decryption.
2. The method for encryption and decryption based on dynamic offset embedding according to claim 1, characterized in that: The calculating the embedding offset according to the key information includes: Define a constant as the maximum offset; Summing the ASCII code value of each character of the unique identifier to generate a first numerical value; Performing a hash operation on the file name to generate a second value; Taking the file size, the bit rate, and the unique identifier modulo the maximum offset, respectively, to obtain a first modulus value, a second modulus value, and a third modulus value; The first modulus value, the second modulus value, the third modulus value, the first numerical value, and the second numerical value are added together, and then the modulus of the maximum offset is taken to obtain the embedded offset.
3. The method for encryption and decryption based on dynamic offset embedding according to claim 2, characterized in that: The first value and the second value are integer values, and the second value is an integer converted from a hexadecimal string after hash calculation of the file name.
4. The method for encryption and decryption based on dynamic offset embedding according to claim 1, characterized in that: The reassembling of the video file includes defining the data structure of the video file into three parts: the start position of the video file to the embedded offset as the first file block; the remaining part of the video file as the second file block; and the PSSH data.
5. The method for encryption and decryption based on dynamic offset embedding according to claim 4, characterized in that: The binary data of the video file is read and stored, and a data container is created. The first file block, the PSSH data, and the second file block are reassembled in the data container and written back to the original video file for replacement.
6. The method for encryption and decryption based on dynamic offset embedding according to claim 1, characterized in that: The using the PSSH data to decrypt includes using a corresponding DRM system or a key management service to decrypt the video content according to the PSSH data.
7. The method of encryption and decryption based on dynamic offset embedding according to claim 1, characterized in that: The encryption process includes obtaining the key information of the video file, calculating the embedding offset, inserting the PSSH data at the embedding offset, and reassembling the video file.
8. The method for encryption and decryption based on dynamic offset embedding according to claim 1, characterized in that: The decryption process includes obtaining the key information of the video file, calculating the embedding offset, extracting the PSSH data at the embedding offset, and decrypting the video content using the corresponding DRM system or key management service according to the PSSH data.
9. A system for encryption and decryption based on dynamic offset embedding, characterized in that: It includes information acquisition module, data embedding module and data extraction module; The information acquisition module reads the video file and obtains key information, and calculates the embedding offset according to the key information; The data embedding module is used to insert PSSH data at the embedding offset during encryption to reassemble the video file; The data extraction module is used to extract the PSSH data at the embedded offset during decryption and perform decryption based on the PSSH data.
10. The system for encryption and decryption based on dynamic offset embedding according to claim 9, characterized in that: The key information includes, but is not limited to, file size, bit rate, unique identifier, and file name.
