Picture, audio and video encryption and decryption method and device and related components
By combining chaotic mapping and hash functions to generate AES keys and adjusting encryption strategies based on the characteristics of image and audio and video data, the problems of existing encryption algorithms being easily cracked and inefficient are solved, and a highly secure and efficient encryption and decryption process is achieved.
Patent Information
- Application Number
- CN202510938357.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-08
- Publication Date
- 2025-09-16
AI Technical Summary
Existing encryption algorithms are easily cracked and the encryption and decryption process is inefficient, resulting in compromised security and quality of multimedia files.
The AES key is generated by combining chaotic mapping and hash function. The number of encryption rounds and encryption priority are adjusted according to the characteristics of image and audio and video data, and differential encryption and decryption of image and audio and video data blocks are performed.
It improves the efficiency of encryption and decryption, ensures the security and quality of multimedia files, avoids the degradation of file quality due to over-encryption, and realizes a highly secure and efficient encryption and decryption process.
Smart Images

Figure CN120658833A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data encryption and decryption, and in particular to a method and device for encrypting and decrypting pictures, audio and video, and related components. Background Art
[0002] With the rapid development of internet technology, the dissemination and sharing of multimedia files, such as images, audio, and video, has become increasingly convenient. However, this also presents serious security risks, exposing users' private data and important information to theft and tampering. To protect the security and privacy of multimedia files, data encryption technology has become a crucial solution.
[0003] At present, common multimedia files are usually encrypted using encryption algorithms, but some encryption algorithms have low security and are easy to crack; and some encryption algorithms, although highly secure, are inefficient when processing image and audio and video files due to the large file data volume and complex format, which can easily lead to file quality damage, such as image distortion, audio and video freezes, or audio and video synchronization problems. Summary of the Invention
[0004] The embodiments of the present invention provide a method, device and related components for encrypting and decrypting images and audio and video, aiming to solve the problems that existing encryption algorithms are easily cracked and the encryption and decryption process is inefficient.
[0005] In a first aspect, an embodiment of the present invention provides a method for encrypting and decrypting images, audio, and video, including:
[0006] Generate AES keys based on a combination of chaotic mapping and hash functions;
[0007] Acquire an image file and an audio and video file, and pre-process the image file and the audio and video file respectively to obtain a plurality of image data blocks and a plurality of audio and video data blocks, wherein the audio and video data blocks include audio data blocks and video data blocks;
[0008] For the picture data blocks, adjusting the number of encryption rounds of the AES key according to the picture index position and data amount of each picture data block, and encrypting all picture data blocks using the AES key to obtain encrypted picture data;
[0009] For the audio data block, assign an encryption priority according to the frequency, energy or regional position of each audio and video data block, and encrypt all audio and video data blocks using the AES key to obtain encrypted audio and video data;
[0010] The encrypted image data or the encrypted audio and video data is received, the encrypted image data or the encrypted audio and video data is decrypted using the AES key to obtain decrypted data, and the decrypted data is reassembled to obtain the image file or the audio and video file.
[0011] In a second aspect, an embodiment of the present invention provides an image and audio / video encryption and decryption device, including:
[0012] A key generation unit, used to generate AES keys based on a combination of chaotic mapping and hash function;
[0013] a preprocessing unit, configured to obtain an image file and an audio and video file, and preprocess the image file and the audio and video file respectively to obtain a plurality of image data blocks and a plurality of audio and video data blocks, wherein the audio and video data blocks include audio data blocks and video data blocks;
[0014] an image encryption unit, configured to adjust the number of encryption rounds of the AES key according to the image index position and data amount of each image data block, and encrypt all image data blocks using the AES key to obtain encrypted image data;
[0015] an audio and video encryption unit, configured to assign an encryption priority to each audio and video data block according to the frequency, energy, or regional location of each audio and video data block, and encrypt all audio and video data blocks using the AES key to obtain encrypted audio and video data;
[0016] The decryption unit is used to receive the encrypted picture data or the encrypted audio and video data, decrypt the encrypted picture data or the encrypted audio and video data using the AES key to obtain decrypted data, and reassemble the decrypted data to obtain the picture file or the audio and video file.
[0017] In a third aspect, an embodiment of the present invention provides a computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the encryption and decryption method described above when executing the computer program.
[0018] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the encryption and decryption method as described above is implemented.
[0019] An embodiment of the present invention provides a method, device, and related components for encrypting and decrypting images and audio and video files. The method generates an AES key based on a combination of chaotic mapping and hash functions, encrypts each divided image data block and audio and video data block using the AES key, and, by adjusting the number of encryption rounds of the AES key for the image data block and assigning encryption priorities to the audio and video data blocks, adopts different encryption methods based on the different data characteristics of the image and audio and video files, thereby avoiding the problem of file quality degradation caused by excessive encryption and ensuring that the decrypted image and audio and video files can maintain their original clarity, fluency, and integrity. Furthermore, the use of different encryption strategies can ensure high security while improving the efficiency of encryption and decryption, effectively addressing the encryption needs of large amounts of image and audio and video files. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0021] Figure 1 A flowchart of a method for encrypting and decrypting images, audio, and video provided by an embodiment of the present invention;
[0022] Figure 2 A schematic block diagram of a device for encrypting and decrypting images, audio, and video provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0023] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0024] It will be understood that when used in this specification and the appended claims, the terms “comprises” and “comprising” indicate the presence of described features, integers, steps, operations, elements and / or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.
[0025] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the present invention. As used in the specification and appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms unless the context clearly indicates otherwise.
[0026] It should be further understood that the term "and / or" used in the present description and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
[0027] See also Figure 1 , an embodiment of the present invention provides a method for encrypting and decrypting images, audio, and video, including S10-S50:
[0028] S10, generating an AES key based on a combination of chaotic mapping and hash function;
[0029] In this step, the chaotic map is a nonlinear dynamic system with properties such as high sensitivity to initial conditions, pseudo-randomness, and ergodicity (covering the entire value range to avoid key duplication or periodic vulnerabilities). Common chaotic maps include the logistic map, the tent map, and the Henon map. A hash function can map an input of arbitrary length (such as a string or number, or in this case, the sequence output by the chaotic map) to an output of a fixed length (hash value) through a hash algorithm. Common lengths are 128, 192, and 256.
[0030] This step generates a fixed-length key that meets AES requirements as the AES key by hashing the sequence output by the chaotic map. By integrating the randomness of the chaotic system with the unidirectionality of the hash function, the security, complexity, and anti-attack capability of key generation can be significantly improved.
[0031] In practice, a distributed key storage approach is used to split the generated AES key into multiple key fragments (which can be split using the Shamir secret sharing scheme) and store them separately on different secure storage nodes. During the AES key distribution process, each key fragment is encrypted and transmitted using a secure key transmission protocol, combined with digital signature technology to ensure the integrity and non-repudiation of each key transmission.
[0032] In one embodiment, S10 includes:
[0033] Preselecting a mapping algorithm for the chaotic mapping and setting chaotic parameters;
[0034] Receiving a key seed input by a user and generating a chaotic sequence through the mapping algorithm;
[0035] Inputting the chaotic sequence into the hash function and outputting a hash value with a predetermined length;
[0036] Bytes of corresponding length are intercepted from the hash value as the AES key.
[0037] In this embodiment, the chaotic mapping selected is the Logistic mapping, and its corresponding mapping algorithm is: n+1 =r·x n ·(1-x n ), where x n ∈(0, 1), r is the control parameter, the chaos parameters include the initial value x0 and the control parameter r, the initial value x0 must be kept secret and can be n The control parameter r∈(3.57, 4] is set arbitrarily within the range to ensure that the entire mapping process is in a chaotic state. The key seed input by the user can be a password, a random number or a device ID. The specific implementation process is to set the mapping times n to 100 and obtain the mapping sequence {x1, x2, ..., x 100}, convert the obtained mapping sequence into a string or binary format, and concatenate the converted mapping sequence with the key seed input by the user to obtain a chaotic sequence.
[0038] The SHA-256 function is selected as the hash function, and the chaotic function is input into the SHA-256 function to obtain a 256-bit hash value. The length of the AES key includes AES-128 and AES-256. If the required AES key length is AES-128, then the first 128 bits of the hash value of the output of the SHA-256 function are taken as the AES-128 key to obtain the AES key; if the required AES key length is AES-256, then all the hash values of the output of the SHA-256 function are taken as the AES-256 key to obtain the AES key.
[0039] In other embodiments, the selected chaotic mapping may also be a Tent mapping or a Henon mapping. If the selected chaotic mapping is a Tent mapping, the corresponding mapping algorithm is:
[0040]
[0041] Among them, μ∈(1,2],x n ∈(0, 1), the chaos parameters include the initial value x0 and the control parameter μ. The initial value x0 must be kept secret and can be n The range can be set arbitrarily, but the initial value x0≠0.5, and the subsequent process is the same as the Logistic mapping.
[0042] If the selected chaotic map is the Henon map, the corresponding mapping algorithm is:
[0043]
[0044] Among them, a∈[1.07, 1.4], b∈[0.2, 0.3], x n and y n The value range of is related to the values of a and b. The chaotic parameters include the initial values x0, y0 and the control parameters a and b. When a = 1.4 and b = 0.3, x n ∈[-1.5, 1.5], y n ∈[-0.4, 0.4], and the subsequent process is the same as the Logistic mapping.
[0045] S20: Acquire an image file and an audio / video file, and preprocess the image file and the audio / video file respectively to obtain a plurality of image data blocks and a plurality of audio / video data blocks, wherein the audio / video data blocks include audio data blocks and video data blocks;
[0046] In this step, the image files can be obtained from local storage (such as hard disk, embedded device storage), or through real-time acquisition (such as hardware devices such as cameras and scanners). The obtained image files have different formats, such as JPEG, PNG, BMP, etc. Audio and video files can be obtained from the local media library (such as video folders, audio databases), or through real-time acquisition (such as microphones, cameras, screen recordings). The obtained audio and video file format is MP4. The obtained image files and audio and video files are then preprocessed to facilitate the division of image files and audio and video files to obtain multiple uniform image data blocks and multiple audio and video data blocks, providing standardized input for subsequent processes.
[0047] In one embodiment, S20 includes:
[0048] Performing format analysis on the acquired image file to obtain image data, extracting the resolution and color mode of the image data, and dividing the image data into a plurality of image data blocks according to the resolution and color mode;
[0049] Decoding the acquired audio and video files to obtain audio and video data, and separating the audio and video data to obtain audio data and video data;
[0050] The time segments of the audio data and the video frames of the video data are extracted, the audio data is divided into a plurality of audio data blocks according to the time segments, and the video data is divided into a plurality of video data blocks according to the video frames.
[0051] In this embodiment, for image files, all acquired image files are received. An image decoding library (e.g., libjpeg or stb_image) is used to parse the image file headers to obtain pixel data as image data. The width and height are extracted from the file header to obtain the resolution (e.g., 1920×1080). The color space of the image data is then identified to obtain the color mode (e.g., RGB). The image data is then divided according to the resolution and color mode. The specific division process is as follows: a dynamic calculation based on the resolution (e.g., each block occupies 1 / 4 of the entire image area) is performed to obtain multiple image data blocks, each of which has the same color mode. Alternatively, the desired block size is directly defined, i.e., divided into 256×256 pixels / block. The number of blocks in the row direction and the number of blocks in the column direction are then calculated. Each pixel block is traversed, and edge pixels that are less than the block size are cropped or padded. If padding is required, it is padded with zeros or a mirror image to the full block size. The resulting data blocks are the multiple image data blocks.
[0052] For audio and video files, all acquired audio and video files are received and decoded using a multimedia framework (such as FFmpeg or GStreamer). The audio and video streams are separated to obtain audio and video data. The audio data is a PCM array with a timestamp, and the video data consists of a frame sequence, each with a timestamp. The audio data blocks are then divided into time segments, defining a fixed duration (such as 1 second). The entire timestamp is cut into the audio data according to the fixed duration, generating continuous audio blocks as audio data blocks. Each audio data block is accompanied by a start timestamp. The video data blocks are also divided into video frames, defining the size of each frame, such as 256×256 pixels / block. This results in multiple video data blocks, each with a frame number and spatial coordinates.
[0053] S30. For each picture data block, adjust the number of encryption rounds of the AES key according to the picture index position and data amount of each picture data block, and encrypt all picture data blocks using the AES key to obtain encrypted picture data.
[0054] In this step, for each image data block, the number of AES encryption rounds and key offset are dynamically adjusted according to its data characteristics, so as to improve the encryption strength or encryption efficiency of different image data blocks using the AES key.
[0055] In one embodiment, S30 includes:
[0056] Obtaining the image index position and data volume of each image data block, and determining whether the current image data block is a key area data block based on the data volume;
[0057] If it is a key area data block, increase the number of encryption rounds of the AES key and generate a first key offset according to the index position;
[0058] If it is a non-critical area data block, reducing the number of encryption rounds of the AES key, and generating a second key offset according to the index position, wherein the first key offset is greater than the second key offset;
[0059] The AES key, the number of encryption rounds, and the key offset are combined, and all image data blocks are encrypted to obtain encrypted image data.
[0060] In this embodiment, the index and data volume of each divided image data block are obtained. The data volume is used to determine whether the image data block contains key content. If it does, it is considered a key region data block; if it does not, it is considered a non-key region data block. Key content includes sensitive information such as faces, text, and high-contrast details, while non-key content includes solid backgrounds, gradient areas, and areas with low information density. The number of encryption rounds and key offset are adjusted based on the importance of the image data block. Specifically, if the current image data block is a key region data block, the number of encryption rounds is increased (e.g., from the standard 10 to 12) to increase cracking difficulty and encryption strength, and a larger offset value is generated based on the index position as the first key offset to make the key change more significant. Alternatively, if the current image data block is a non-key region data block, the number of encryption rounds is reduced (e.g., from the standard 10 to 8) to reduce computational overhead, and a smaller offset value is generated based on the index position as the second offset value to improve encryption efficiency while ensuring security.
[0061] The AES key generated by S10 is then used as the base key. This base key is combined with the key offset to generate a unique key for each image data block, and encryption is performed using the adjusted number of rounds. All encrypted image data blocks are reassembled according to the image index position to find the original order, forming the final encrypted image.
[0062] S40, assigning an encryption priority to each audio and video data block according to the frequency, energy, or regional location of each audio and video data block, and encrypting all audio and video data blocks using the AES key to obtain encrypted audio and video data;
[0063] In this step, for each audio and video data block, a different encryption priority is assigned to each audio and video data block according to its frequency characteristics, energy distribution or regional location, so that different audio and video data blocks can be encrypted using AES keys, thereby improving encryption strength or improving encryption efficiency.
[0064] In one embodiment, S40 includes:
[0065] Obtaining the frequency and energy of each audio data block, and determining whether the current audio data block is a high-frequency and high-energy audio data block according to the frequency and energy;
[0066] If the audio data block is high-frequency and high-energy, the first encryption parameter is adopted, and the encryption priority is set to the first priority;
[0067] If the audio data block is low-frequency and low-energy, a second encryption parameter is used, and the encryption priority is set to the second priority, wherein the encryption strength of the first encryption parameter is greater than the encryption strength of the second encryption parameter, and the first priority is greater than the second priority;
[0068] The AES key, the corresponding encryption parameters, and the encryption priority are combined, and all audio data blocks are encrypted to obtain encrypted audio data.
[0069] In this embodiment, the frequency distribution of each audio data block may be analyzed by a Fourier transform method to obtain the frequency of each audio data block, and the energy of each audio data block may be calculated by an energy calculation formula. The energy calculation formula may be:
[0070]
[0071] Where E(t) represents the short-time energy with time t as the center, describing the energy of the audio signal within a local time window. n represents the nth sampling point of the audio signal. n=t represents the sampling point index corresponding to the center time t, which serves as the center position of the short-time energy calculation window. w is the half-length of the window. x(n) represents the audio signal amplitude at the nth sampling point.
[0072] Frequency and energy thresholds are pre-set, and the frequency and energy of each acquired audio data block are compared with the frequency and energy thresholds to determine whether the current audio data block is a high-frequency, high-energy audio data block. High-frequency, high-energy audio data blocks correspond to key information such as consonants in speech and percussion instruments in music, while low-frequency, low-energy audio data blocks correspond to secondary information such as background noise and ambient sound. Based on the judgment results, different encryption parameters and priorities are assigned to different audio data blocks. For example, if the current audio data block is a high-frequency, high-energy data block, the first encryption parameter is used. The first encryption parameter includes an AES key with a key length of AES-256 and an increased number of encryption rounds for the AES key, which can be increased to 16 rounds. The encryption priority is also set to the first priority, meaning that such audio data blocks are processed first, ensuring the real-time and security of key information. If the current audio data block is a low-frequency and low-energy data block, the second encryption parameter is used. The second encryption parameter includes an AES key with a key length of AES-128 and a reduced number of encryption rounds of the AES key, which can be reduced to 12 rounds. The encryption priority is set to the second priority, which has a lower processing priority and allows a slight delay in encryption to optimize overall performance.
[0073] The AES key generated by S10 is then used as the base key. This base key is combined with the encryption parameters to generate a unique key for each audio data block. The encryption operation scheduling order is adjusted according to the encryption priority to ensure that high-priority audio data blocks are processed first. All encrypted audio data blocks are reassembled according to the audio index position to find the original order, forming a complete encrypted audio stream.
[0074] In one embodiment, S40 further includes:
[0075] Obtaining a region position of each video data block, and determining whether the current video data block is a foreground region according to the region position;
[0076] If it is a foreground area, the full data encryption mode is adopted, and the encryption priority is set to the third priority;
[0077] If it is a background area, a selective encryption mode is adopted, and the encryption priority is set to the fourth priority, and the third priority is greater than the fourth priority;
[0078] The AES key, the corresponding encryption mode and the encryption priority are combined, and all video data blocks are encrypted to obtain encrypted video data.
[0079] In this embodiment, the regional position information of each video data block in the video picture is identified, and it is confirmed whether each video data block is the main part (foreground area) or the background part (background area) in the picture, wherein the foreground area includes pedestrians and objects in the surveillance video, and the background area includes the sky and walls. The foreground area and the background area can be distinguished by means of an image processing algorithm. According to the judgment result, different video data blocks adopt different encryption modes and priorities. That is, if the current video data block is the foreground area, the full data encryption mode is adopted to encrypt all data in the foreground area to ensure the security of key content, and the encryption priority is set to the third priority, that is, the audio data block in the foreground area is given priority during encryption to ensure that key content is encrypted first, adapt to real-time scenarios (such as live broadcast encryption), and reduce the risk of core information exposure. If the current video data block is the background area, the selective encryption mode is adopted to encrypt only some key data (such as image edge features and color mean) in the background area data block to reduce the amount of calculation. Because the background area has little impact on content integrity, data can be appropriately selectively encrypted to balance security and efficiency. The encryption priority is set to the fourth priority, and the encryption order is later, so as to give priority to the processing of the data blocks in the foreground area, and the data blocks in the background area are processed later.
[0080] It should be noted that the first priority and the second priority in the aforementioned embodiment have no associated priority relationship with the third priority and the fourth priority in this embodiment, that is, the priority of the first priority is only earlier than the priority of the second priority, and has nothing to do with the priority of the third priority or the fourth priority. Similarly, the priority of the third priority is only earlier than the priority of the fourth priority, and has nothing to do with the priority of the first priority or the second priority. There is no situation where the priority of the first priority is earlier than the priority of the third priority, nor is there a situation where the priority of the third priority is earlier than the priority of the first priority.
[0081] The AES key generated by S10 is then used as the base key. This base key is combined with the encryption mode to generate a unique key adapted to each video data block. The data blocks in the foreground area and the background area are encrypted in order of priority. All encrypted video data blocks are reassembled according to the video index position to find the original order, forming a complete encrypted video stream.
[0082] S50: Receive the encrypted image data or encrypted audio and video data, decrypt the encrypted image data or encrypted audio and video data using the AES key to obtain decrypted data, and reassemble the decrypted data to obtain the image file or audio and video file.
[0083] In this step, the encrypted encrypted image data or encrypted audio and video data is obtained from the transmission channel, and the AES key used in the previous encryption process is called for decryption. This is because encryption and decryption are symmetric processes and must be restored correctly with the same key. Using the AES key, a decryption operation is performed on the encrypted data. Decryption corresponds to reverse parsing. Relying on the reversibility of the AES algorithm, the encrypted data is restored to the original data block before encryption through key calculation. After decryption, independent data blocks are obtained. These data blocks are re-spliced according to the index position recorded before encryption. The spliced data blocks are sorted according to the format standard of the image file / audio and video file (such as JPEG structure, MP4 container specification) to obtain a complete image file or audio and video file to restore it to a form that can be used / played normally.
[0084] In one embodiment, S50 includes:
[0085] Obtaining the number of encryption rounds and the key offset of each encrypted picture data block in the encrypted picture data, decrypting each encrypted picture data block using the AES key to obtain a decrypted picture data block, and reorganizing each decrypted picture data block according to a picture index position to obtain the picture file;
[0086] Alternatively, the encryption parameters and encryption priority or the corresponding encryption mode and encryption priority corresponding to each encrypted audio and video data block in the encrypted audio and video data are obtained, each encrypted audio and video data block is decrypted using the AES key to obtain a decrypted audio and video data block, and each decrypted audio and video data block is reorganized according to the audio and video index position to obtain the audio and video file.
[0087] In this embodiment, two decryption processes are included, one is the decryption of encrypted image data, and the other is the decryption of encrypted audio and video data. For the encrypted image data, the specific decryption process is as follows: after receiving the encrypted image data, the number of encryption rounds and key offset corresponding to each encrypted image data block are first parsed, and a unified AES key is used, combined with the number of encryption rounds + key offset of each encrypted image data block, to perform a reverse operation on the encrypted image data block. That is, during encryption, "increasing the number of rounds and adding the offset" changes the data form, and decryption "rolls back according to the same number of rounds and offsets the offset" to restore the encrypted image data block to the decrypted image data block (that is, the form of the original data block before encryption).
[0088] Each decrypted image data block carries the image index position (the location information recorded before encryption). By splicing the data back into the original order according to the image index position, the complete image file is restored, thus recovering the image content before encryption. Testing shows that the decrypted image file is visually indistinguishable from the image file obtained by S20, and the PSNR value, an image quality evaluation indicator, remains at a high level.
[0089] As can be seen from the aforementioned embodiments, encrypted audio and video data includes encrypted audio data and encrypted video data, so the specific decryption process is also different. For encrypted audio data, the decryption process is as follows: after receiving the encrypted audio data, the encryption parameters and encryption priority corresponding to each encrypted audio data block are parsed. Using a unified AES key, combined with the encryption parameters + encryption priority of each encrypted audio data block, the encrypted audio data block is reversed: the encrypted audio data block is restored to a decrypted audio data block (that is, the form of the original data block before encryption). Each decrypted audio data block has an audio index position, and these decrypted audio data blocks are spliced back to the original order according to the index to finally obtain the audio data block.
[0090] For encrypted video data, the decryption process is as follows: after receiving the encrypted video data, the encryption mode and encryption priority corresponding to each encrypted video data block are parsed. Using a unified AES key, combined with the encryption mode and encryption priority of each encrypted video data block, the encrypted video data block is reversed. If the encryption mode is full data encryption, decryption completely restores all data; if the encryption mode is selective encryption, decryption specifically recovers and completes key data to obtain a decrypted video data block (that is, the form of the original data block before encryption). Each decrypted video data block has a video index position. According to the index, these decrypted video data blocks are spliced back to the original order to finally obtain the video data block.
[0091] The audio and video data blocks obtained after decryption and splicing are reassembled and encoded to obtain audio and video files. During the playback of the decrypted audio and video files, the audio is clear and smooth, the video picture is clear, there is no lag or audio and video asynchrony, and the user experience is good.
[0092] The embodiment of the present invention also provides a device for encrypting and decrypting images and audio and video, which is used to execute any embodiment of the above-mentioned method for encrypting and decrypting images and audio and video. Figure 2 , Figure 2 This is a schematic block diagram of an apparatus for encrypting and decrypting images, audio, and video provided by an embodiment of the present invention. The encryption and decryption 600 of images, audio, and video includes:
[0093] A key generation unit 610 is used to generate an AES key based on a combination of a chaotic map and a hash function;
[0094] A preprocessing unit 620 is configured to obtain an image file and an audio / video file, and preprocess the image file and the audio / video file respectively to obtain a plurality of image data blocks and a plurality of audio / video data blocks, wherein the audio / video data blocks include audio data blocks and video data blocks;
[0095] The picture encryption unit 630 is configured to adjust the number of encryption rounds of the AES key according to the picture index position and data amount of each picture data block, and encrypt all picture data blocks using the AES key to obtain encrypted picture data;
[0096] an audio and video encryption unit 640 for assigning an encryption priority to each audio and video data block according to its frequency, energy, or regional location, and encrypting all audio and video data blocks using the AES key to obtain encrypted audio and video data;
[0097] The decryption unit 650 is used to receive the encrypted image data or encrypted audio and video data, decrypt the encrypted image data or encrypted audio and video data using the AES key to obtain decrypted data, and reassemble the decrypted data to obtain the image file or audio and video file.
[0098] An embodiment of the present invention provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the method for encrypting and decrypting images, audio, and video as described in the foregoing embodiment is implemented.
[0099] An embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the method for encrypting and decrypting images, audio, and video as described in the aforementioned embodiment is implemented.
[0100] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described equipment, devices and units can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0101] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, or units with the same function may be combined into one unit. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interfaces, devices or units, or may be an electrical, mechanical or other form of connection.
[0102] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected according to actual needs to achieve the objectives of the embodiments of the present invention.
[0103] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0104] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the existing technology, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a magnetic disk, or an optical disk.
[0105] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and such modifications or substitutions are intended to be within the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be subject to the scope of protection of the claims.
Claims
1. A method for encrypting and decrypting pictures, audio and video, characterized in that: include: Generate AES keys based on a combination of chaotic mapping and hash functions; Acquire an image file and an audio and video file, and pre-process the image file and the audio and video file respectively to obtain a plurality of image data blocks and a plurality of audio and video data blocks, wherein the audio and video data blocks include audio data blocks and video data blocks; For the picture data blocks, adjusting the number of encryption rounds of the AES key according to the picture index position and data amount of each picture data block, and encrypting all picture data blocks using the AES key to obtain encrypted picture data; For the audio and video data blocks, assign an encryption priority according to the frequency, energy or regional position of each audio and video data block, and encrypt all the audio and video data blocks using the AES key to obtain encrypted audio and video data; The encrypted image data or the encrypted audio and video data is received, the encrypted image data or the encrypted audio and video data is decrypted using the AES key to obtain decrypted data, and the decrypted data is reassembled to obtain the image file or the audio and video file.
2. The encryption and decryption method according to claim 1, wherein: The method of generating an AES key based on a combination of chaotic mapping and hash function includes: Preselecting a mapping algorithm for the chaotic mapping and setting chaotic parameters; Receiving a key seed input by a user and generating a chaotic sequence through the mapping algorithm; Inputting the chaotic sequence into the hash function and outputting a hash value with a predetermined length; Bytes of corresponding length are intercepted from the hash value as the AES key.
3. The encryption and decryption method according to claim 1, wherein: The obtaining of the picture file and the audio and video file, and preprocessing the picture file and the audio and video file respectively to obtain a plurality of picture data blocks and a plurality of audio and video data blocks, wherein the audio and video data blocks include audio data blocks and video data blocks, include: Performing format analysis on the acquired image file to obtain image data, extracting the resolution and color mode of the image data, and dividing the image data into a plurality of image data blocks according to the resolution and color mode; Decoding the acquired audio and video files to obtain audio and video data, and separating the audio and video data to obtain audio data and video data; The time segments of the audio data and the video frames of the video data are extracted, the audio data is divided into a plurality of audio data blocks according to the time segments, and the video data is divided into a plurality of video data blocks according to the video frames.
4. The encryption and decryption method according to claim 3, wherein: The method further comprises adjusting the number of encryption rounds and the key offset of the AES key according to the image index position and the data amount of each image data block, and encrypting all image data blocks using the AES key to obtain encrypted image data, including: Obtaining the image index position and data volume of each image data block, and determining whether the current image data block is a key area data block based on the data volume; If it is a key area data block, increase the number of encryption rounds of the AES key and generate a first key offset according to the index position; If it is a non-critical area data block, reducing the number of encryption rounds of the AES key, and generating a second key offset according to the index position, wherein the first key offset is greater than the second key offset; The AES key, the number of encryption rounds, and the key offset are combined, and all image data blocks are encrypted to obtain encrypted image data.
5. The encryption and decryption method according to claim 4, characterized in that: The method further comprises: allocating an encryption priority to the audio and video data blocks according to the frequency, energy or regional position of each audio and video data block, and encrypting all audio and video data blocks using the AES key to obtain encrypted audio and video data, including: Obtaining the frequency and energy of each audio data block, and determining whether the current audio data block is a high-frequency and high-energy audio data block according to the frequency and energy; If the audio data block is high-frequency and high-energy, the first encryption parameter is adopted, and the encryption priority is set to the first priority; If the audio data block is low-frequency and low-energy, a second encryption parameter is used, and the encryption priority is set to the second priority, wherein the encryption strength of the first encryption parameter is greater than the encryption strength of the second encryption parameter, and the first priority is greater than the second priority; The AES key, the corresponding encryption parameters, and the encryption priority are combined, and all audio data blocks are encrypted to obtain encrypted audio data.
6. The encryption and decryption method according to claim 5, characterized in that: The method further comprises: allocating an encryption priority to the audio and video data blocks according to the frequency, energy or regional position of each audio and video data block, and encrypting all audio and video data blocks using the AES key to obtain encrypted audio and video data. Obtaining a region position of each video data block, and determining whether the current video data block is a foreground region according to the region position; If it is a foreground area, the full data encryption mode is adopted, and the encryption priority is set to the third priority; If it is a background area, a selective encryption mode is adopted, and the encryption priority is set to the fourth priority, and the third priority is greater than the fourth priority; The AES key, the corresponding encryption mode and the encryption priority are combined, and all video data blocks are encrypted to obtain encrypted video data.
7. The encryption and decryption method according to claim 6, characterized in that: The receiving the encrypted image data or the encrypted audio and video data, decrypting the encrypted image data or the encrypted audio and video data using the AES key to obtain decrypted data, and reassembling the decrypted data to obtain the image file or the audio and video file includes: Obtaining the number of encryption rounds and the key offset of each encrypted picture data block in the encrypted picture data, decrypting each encrypted picture data block using the AES key to obtain a decrypted picture data block, and reorganizing each decrypted picture data block according to a picture index position to obtain the picture file; Alternatively, the encryption parameters and encryption priority or the corresponding encryption mode and encryption priority corresponding to each encrypted audio and video data block in the encrypted audio and video data are obtained, each encrypted audio and video data block is decrypted using the AES key to obtain a decrypted audio and video data block, and each decrypted audio and video data block is reorganized according to the audio and video index position to obtain the audio and video file.
8. A device for encrypting and decrypting pictures, audio and video, characterized in that: include: A key generation unit, used to generate AES keys based on a combination of chaotic mapping and hash function; a preprocessing unit, configured to obtain an image file and an audio and video file, and preprocess the image file and the audio and video file respectively to obtain a plurality of image data blocks and a plurality of audio and video data blocks, wherein the audio and video data blocks include audio data blocks and video data blocks; an image encryption unit, configured to adjust the number of encryption rounds of the AES key according to the image index position and data amount of each image data block, and encrypt all image data blocks using the AES key to obtain encrypted image data; an audio and video encryption unit, configured to assign an encryption priority to each audio and video data block according to the frequency, energy, or regional location of each audio and video data block, and encrypt all audio and video data blocks using the AES key to obtain encrypted audio and video data; The decryption unit is used to receive the encrypted picture data or the encrypted audio and video data, decrypt the encrypted picture data or the encrypted audio and video data using the AES key to obtain decrypted data, and reassemble the decrypted data to obtain the picture file or the audio and video file.
9. A computer device, characterized in that: The method comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the encryption and decryption method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the encryption and decryption method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Encryption method and decryption method of Internet of Vehicles data
CN121462701A