File encryption method and decryption method based on aes encryption and related device

CN115580477BActive Publication Date: 2026-08-21SHENZHEN SHANJIAN INTELLIGENT SCI & TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202211305356.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-24
Publication Date
2026-08-21
Estimated Expiration
2042-10-24

AI Technical Summary

Technical Problem

现有技术对文件加密基本都是简单的利用秘钥直接加密,而并不会对文件进行验证信息封装,这样在给定一个加密文件时,用户无法判断文件是不是加密文件,解密时也无法判断秘钥是否正确,更不能判断解密后的文件是否完整

Benefits of technology

[0050]有益效果:本发明提供了一种基于AES加密的文件加密方法、解密方法及相关设备,其中方法包括:通过数组索引的方式从预设的秘钥来源数组中获取AES加密秘钥;基于所述AES加密秘钥并利用AES加密函数对待加密的文件进行加密,获得初步加密文件;利用MD5摘要信息算法获取所述AES加密秘钥的第一MD5值;利用MD5摘要信息算法获取所述初步加密文件的第二MD5值;构建包含文件加密验证信息的文件头;按顺序将所述文件头、所述第一MD5值和所述第二MD5值封装到所述初步加密文件的头部,获得最终加密文件。本发明的文件加密方法除了对文件进行加密之外还将与加密相关的文件验证信息与加密后的文件进行一起封装,实现了后续对秘钥正确性以及加密文件完整性的验证,加密流程更完善。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115580477B_ABST
    Figure CN115580477B_ABST
Patent Text Reader

Abstract

The application provides a file encryption method and decryption method based on AES encryption and related equipment, wherein the method comprises: obtaining an AES encryption key from a preset key source array through an array index mode; encrypting a file to be encrypted based on the AES encryption key and using an AES encryption function to obtain a preliminary encrypted file; obtaining a first MD5 value of the AES encryption key using an MD5 digest information algorithm; obtaining a second MD5 value of the preliminary encrypted file using the MD5 digest information algorithm; constructing a file header containing file encryption verification information; and sequentially packaging the file header, the first MD5 value and the second MD5 value into the head of the preliminary encrypted file to obtain a final encrypted file. The file encryption method of the application not only encrypts the file, but also packages the file verification information related to encryption together with the encrypted file, realizes the verification of the correctness of the key and the integrity of the encrypted file, and the encryption process is more perfect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of light-emitting special effects production technology, and in particular to a file encryption method, decryption method and related equipment based on AES encryption. Background Technology

[0002] With societal development and the continuous advancement of informatization, the application of "Internet+" is deepening. Informatization permeates all aspects of people's learning, work, and life, providing convenient services while also posing significant challenges to information security. The protection of sensitive data has become a hot topic of concern. Intruders can directly steal from storage devices or use network technology to intrude and steal file data. In many cases, due to certain needs, sensitive data files need to be shared online by multiple people, which increases the possibility of information leakage. Personal information security is a crucial component of information security, and creating a tool to protect users' personal information is of great significance.

[0003] Information leakage is something that owners of sensitive data do not want to face and find unacceptable. Therefore, minimizing the possibility of information leakage becomes an urgent problem to solve. Current file encryption technology basically uses a simple key to encrypt directly without encapsulating verification information. Thus, given an encrypted file, the user cannot determine whether the file is encrypted, nor can they verify the correctness of the key or the integrity of the decrypted file.

[0004] Therefore, existing technologies still need to be improved and developed. Summary of the Invention

[0005] The main objective of this invention is to provide a file encryption method, system, device, and storage medium based on AES encryption to solve the aforementioned problems in the prior art.

[0006] The first aspect of this invention provides a file encryption method based on AES encryption, comprising the following steps:

[0007] The AES encryption key is obtained from a preset key source array using array indexing.

[0008] Based on the AES encryption key and using the AES encryption function, the file to be encrypted is encrypted to obtain a preliminary encrypted file;

[0009] The first MD5 value of the AES encryption key is obtained using the MD5 digest information algorithm.

[0010] The second MD5 value of the initially encrypted file is obtained using the MD5 digest information algorithm;

[0011] Construct a file header that includes file encryption verification information;

[0012] The file header, the first MD5 value, and the second MD5 value are sequentially encapsulated into the header of the initially encrypted file to obtain the final encrypted file.

[0013] In an optional embodiment of the first aspect of the present invention, obtaining the AES encryption key from a preset key source array via array indexing includes:

[0014] Get the system's current UTC time;

[0015] Convert the UTC time to an integer value in milliseconds;

[0016] The integer value is converted into a numeric string using a preset integer-to-string conversion algorithm;

[0017] Add an appropriate number of random numbers to the numeric string so that the numeric string can be equally split into 24 numeric elements;

[0018] Divide the 24 numerical elements by the preset value and take the remainder to obtain 24 integers;

[0019] Using the 24 integers as indices, 24 mapping characters are obtained from a preset key source array, and the string composed of the 24 mapping characters is used as the AES encryption key.

[0020] In an optional embodiment of the first aspect of the present invention, the step of obtaining the AES encryption key from a preset key source array via array indexing includes:

[0021] The 26 letters, the numbers 0-9, and several special symbols are stored as mapping characters in the key source array in sequence, and corresponding mapping integers are configured for the 26 letters, the numbers 0-9, and the several special symbols.

[0022] In an optional embodiment of the first aspect of the present invention, if the mapped character determined by the integer as an index is a letter, a random number is generated by a preset random number generator, and the letter is determined to be uppercase or lowercase by the parity attribute of the random number.

[0023] In an optional embodiment of the first aspect of the present invention, constructing a file header containing file encryption verification information includes:

[0024] The file header is 16 bytes long.

[0025] Bytes 4-7 of the 16 bytes are configured to store file type flag information;

[0026] Bytes 8-11 of the 16 bytes are configured to store file size information.

[0027] In an optional embodiment of the first aspect of the present invention, the step of encrypting the file to be encrypted based on the AES encryption key and using the AES encryption function to obtain the initially encrypted file includes:

[0028] Determine if the size of the file to be encrypted is a multiple of 16;

[0029] If the size of the file to be encrypted is not a multiple of 16, then a space is added to the end of the file to make the size of the file to be encrypted equal to a multiple of 16.

[0030] A second aspect of this invention provides a method for decrypting AES encrypted files, comprising the following steps:

[0031] Receive the final encrypted file sent by the encrypted terminal;

[0032] Parse the header of the final encrypted file, and determine whether the final encrypted file is an AES encrypted file based on the file encryption verification information in the header;

[0033] If the final encrypted file is an AES encrypted file, then the input AES decryption key is received;

[0034] The third MD5 value of the AES decryption key is obtained using the MD5 digest information algorithm;

[0035] Determine whether the third MD5 value is the same as the first MD5 value after the file header of the final encrypted file;

[0036] If the third MD5 value is the same as the first MD5 value, then the second MD5 value is extracted from the first MD5 value of the final encrypted file, and the preliminary encrypted file is extracted from the second MD5 value.

[0037] The fourth MD5 value of the initially encrypted file is obtained using the MD5 digest information algorithm;

[0038] Determine whether the fourth MD5 value is the same as the second MD5 value;

[0039] If the fourth MD5 value is the same as the second MD5 value, the original file is obtained based on the AES decryption key and through the AES decryption function.

[0040] A third aspect of the present invention provides a file encryption device based on AES encryption, the file encryption device based on AES encryption comprising:

[0041] The key generation module is used to obtain the AES encryption key from a preset key source array by array indexing;

[0042] The encryption module is used to encrypt the file to be encrypted based on the AES encryption key and using the AES encryption function to obtain a preliminary encrypted file;

[0043] The first MD5 value calculation module is used to obtain the first MD5 value of the AES encryption key using the MD5 digest information algorithm.

[0044] The second MD5 value calculation module is used to obtain the second MD5 value of the initially encrypted file using the MD5 digest information algorithm.

[0045] The file header construction module is used to build a file header that contains file encryption and verification information.

[0046] The file encapsulation module is used to sequentially encapsulate the file header, the first MD5 value, and the second MD5 value into the header of the initially encrypted file to obtain the final encrypted file.

[0047] A fourth aspect of the present invention provides a file encryption device based on AES encryption, the file encryption device based on AES encryption includes: a memory and at least one processor, the memory storing instructions, and the memory and the at least one processor being interconnected via a line;

[0048] The at least one processor invokes the instructions in the memory to cause the AES-based file encryption device to perform the AES-based file encryption method as described in any of the preceding claims.

[0049] The fifth aspect of the present invention provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the file encryption method based on AES encryption as described in any of the preceding claims.

[0050] Beneficial Effects: This invention provides a file encryption method, decryption method, and related equipment based on AES encryption. The method includes: obtaining an AES encryption key from a preset key source array using array indexing; encrypting the file to be encrypted using the AES encryption key and an AES encryption function to obtain a preliminary encrypted file; obtaining a first MD5 value of the AES encryption key using an MD5 digest algorithm; obtaining a second MD5 value of the preliminary encrypted file using an MD5 digest algorithm; constructing a file header containing file encryption verification information; and sequentially encapsulating the file header, the first MD5 value, and the second MD5 value into the header of the preliminary encrypted file to obtain a final encrypted file. In addition to encrypting the file, this invention's file encryption method also encapsulates encryption-related file verification information along with the encrypted file, enabling subsequent verification of the key's correctness and the integrity of the encrypted file, resulting in a more complete encryption process. Attached Figure Description

[0051] Figure 1 This is a schematic diagram of an embodiment of a file encryption method based on AES encryption according to the present invention;

[0052] Figure 2 This is a schematic diagram of an embodiment of a method for decrypting AES encrypted files according to the present invention;

[0053] Figure 3 This is a schematic diagram of an embodiment of a file encryption device based on AES encryption according to the present invention;

[0054] Figure 4 This is a schematic diagram of an embodiment of a file encryption device based on AES encryption according to the present invention. Detailed Implementation

[0055] This invention provides a file encryption method, decryption method, and related equipment based on AES encryption. The terms "first," "second," "third," "fourth," etc. (if present)," in the specification, claims, and accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be understood in addition to those illustrated herein.

[0056] Or implemented in a sequence other than that described. Furthermore, the terms “comprising” or “having” and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product, or apparatus that includes a series of steps or units is not necessarily limited to those steps or units that are expressly listed, but may include other steps or units that are not expressly listed or that are inherent to such process, method, product, or apparatus.

[0057] See Figure 1 The first aspect of this invention provides a file encryption method based on AES encryption, comprising the following steps:

[0058] S100. Obtain the AES encryption key from the preset key source array by array indexing. In this invention, the AES encryption key is obtained by changing the traditional generation mode and instead using array indexing. In this way, different keys can be obtained by different arrays. Even if the user knows the index array, they cannot correctly obtain the real key if they do not know the relationship between the index array and the key source array, thereby improving the security of key generation.

[0059] S200. Based on the AES encryption key and using the AES encryption function, encrypt the file to be encrypted to obtain a preliminary encrypted file. In this invention, once the AES encryption key is obtained, the file can be directly encrypted using the AES encryption key. The AES encryption function used in the technical solution of this invention can be any existing AES encryption function. The AES encryption process can generally be summarized as byte substitution, row shifting, column obfuscation, and round key encryption.

[0060] S300. Obtain the first MD5 value of the AES encryption key using the MD5 digest information algorithm; in this invention, the first MD5 value is used to verify the correctness of the AES decryption key.

[0061] S400. Obtain the second MD5 value of the initially encrypted file using the MD5 digest information algorithm; In this invention, the second MD5 value is used to verify whether the initially encrypted file has been tampered with during transmission, ensuring the correctness and integrity of the initially encrypted file during decryption.

[0062] S500. Construct a file header containing file encryption verification information; In this invention, the main function of the file header is to obtain some attribute information of the encrypted file and determine the encryption type used by the file, so as to use the corresponding decryption algorithm to decrypt it.

[0063] S600. Sequentially encapsulate the file header, the first MD5 value, and the second MD5 value into the header of the initially encrypted file to obtain the final encrypted file. In this invention, by encapsulating the file header, the first MD5 value, and the second MD5 value together with the initially encrypted file, a self-verification function for subsequent decryption of the AES encrypted file is achieved.

[0064] Specifically, to address the self-verification problem during file decryption, this invention primarily solves the following technical points: how to determine if a file is encrypted (i.e., the file's legitimacy); how to determine if the key is correct; and how to determine if the decrypted file is correct (i.e., whether the file was successfully decrypted and whether it is corrupted). In general, the technical content of this invention comprises three parts: how to generate a highly secure key; how to encapsulate the file during encryption; and how to determine during decryption: whether the file is encrypted, whether the key is correct, and whether the decrypted file is correct. The specific technical means are: setting a file header to verify the file's own legitimacy; storing the MD5 value of the key in the encrypted file to verify the key's correctness; and storing the file's MD5 value in the encrypted file to verify the file's correctness during decryption.

[0065] In an optional embodiment of the first aspect of the present invention, obtaining the AES encryption key from a preset key source array via array indexing includes:

[0066] Obtain the current UTC time of the system; in order to ensure that each generated key is different, the AES encryption key in this invention uses UTC time as the basis;

[0067] The UTC time is converted into an integer value in milliseconds. In this invention, after obtaining the UTC time, it is first necessary to convert the UTC time into a 64-bit integer value M in milliseconds.

[0068] The integer value is converted into a numeric string using a preset integer-to-string conversion algorithm. After obtaining the integer value in UTC time, the integer value M is then converted into a string, resulting in a string str with a length of no less than 12 characters. For example, the conversion algorithm between the integer value and the string can be implemented using the itoa() function. If the converted string contains numbers, the non-numbers are deleted.

[0069] A suitable number of random numbers are added to the number string so that the number string can be equally divided into 24 number elements. In this invention, the number of random numbers to be added is determined based on the number of digits in the number string. The random numbers can be added by inserting a random number between every two string numbers. In this invention, the 24 number elements obtained by splitting the string are preferably each composed of 2 digits.

[0070] Divide the 24 numerical elements by a preset value and take the remainder to obtain 24 integers; in this invention, after obtaining the 24 numerical elements, divide each of the 24 numerical elements by a preset value (e.g., 40) to obtain a remainder, and obtain an integer composed of 24 remainders.

[0071] Using the 24 integers as indices, 24 mapping characters are obtained from a preset key source array. The string composed of these 24 mapping characters serves as the AES encryption key. In this invention, each mapping character in the key source array corresponds to one or more different integers. When the integer formed by the remainders obtained above is the same as the integer corresponding to a certain mapping character, the mapping character replaces the integer formed by the remainders. Finally, the mapping characters corresponding to the 24 integers formed by the remainders are collected to obtain the AES encryption key.

[0072] In an optional embodiment of the first aspect of the present invention, obtaining the AES encryption key from a preset key source array via array indexing includes:

[0073] The 26 letters, the numbers 0-9, and several special symbols are stored sequentially as mapping characters in the key source array, and corresponding mapping integers are assigned to each of the 26 letters, the numbers 0-9, and the special symbols. In this invention, to ensure the diversity and integrity of the encryption key, the key uses a 24-character string, consisting of the numbers 0-9, the 26 letters, and four special characters: <, %, ?, and >.

[0074] In an optional embodiment of the first aspect of the present invention, if the mapped character determined by the integer as an index is a letter, a random number is generated by a preset random number generator, and the parity attribute of the random number is used to determine whether the letter is uppercase or lowercase. In this invention, to further expand the diversity of keys, the letters in the obtained AES encryption key can be further distinguished by case. The method of distinction is set by the parity attribute of the generated random number; for example, if a letter corresponds to an odd random number, then the letter is changed to uppercase; otherwise, it remains lowercase.

[0075] In an optional embodiment of the first aspect of the present invention, constructing a file header containing file encryption verification information includes:

[0076] The file header is 16 bytes long; the first three bytes of these 16 bytes contain the data to be transmitted.

[0077] The 4th to 7th bytes of the 16 bytes are configured to store file type marker information; in this invention, for example, the 4th to 7th bytes are AES1, used to verify whether the file is an AES encrypted file;

[0078] Bytes 8-11 of the 16 bytes are configured to store file size information. In this invention, bytes 8-11 are, for example, 2048 bytes. Subsequent decryption can use the information recorded in bytes 8-11 to determine the file size before encryption.

[0079] In an optional embodiment of the first aspect of the present invention, the step of encrypting the file to be encrypted based on the AES encryption key and using the AES encryption function to obtain the initially encrypted file includes:

[0080] Determine if the size of the file to be encrypted is a multiple of 16;

[0081] If the size of the file to be encrypted is not a multiple of 16, then a space is added to the end of the file to make the size of the file to be encrypted equal to a multiple of 16.

[0082] In this invention, because AES encryption requires the size of the encrypted data to be a multiple of 16, if not, a space needs to be added to the end of the file. Therefore, the size of the encrypted data is usually not equal to the size of the data before encryption.

[0083] To better understand the technical solution of this invention, the complete process of the key generation method is extracted and described separately:

[0084] How to generate a highly secure key: For completeness, the key uses a 24-character string, consisting of the numbers 0-9, 26 uppercase and lowercase letters, plus four special characters: <, %, ?, and >. The specific generation method is as follows:

[0085] Store the 26 uppercase letters, numbers 0-9, and special symbols <, %, ?, and > in an array Symbols in order.

[0086] To ensure that each generated key is unique, UTC time is used as the basis to obtain a 64-bit integer value M in milliseconds. Converting M into a string yields a string str with a length of at least 12 characters.

[0087] Add random numbers to reorganize str into a 24-element integer array. Alternatively, add a random number to the first 12 characters of the string str, and insert a random number every other character to obtain a 24-element integer array buffer.

[0088] Iterate through the array `buffer`, taking the remainder of each element modulo 40 to obtain an integer `idx`. Use `idx` as the index of the `Symbols` array, and retrieve the corresponding character from `Symbols` to form a 24-character string key. To ensure the key contains both uppercase and lowercase letters, the value of `idx` needs to be checked. When `idx` is less than 26, a letter is retrieved from `Symbols`. Additionally, a random number `N` can be generated, and its parity determines whether uppercase or lowercase letters are used.

[0089] The file is encapsulated during encryption, and the encrypted file consists of four parts:

[0090] 1. File header. First, set a file header, which is 16 bytes long, and initialize these 32 bytes to the ASCII value 0; set header[4] to header[7] as the file type flag, such as AES1, to verify whether the file is an encrypted file; header[8] to header

[11] are used to store the file size of the file to be decrypted; because AES encryption requires the size of the encrypted data to be a multiple of 16, if it is not, a blank needs to be added to the end of the file; therefore, the size of the encrypted data is usually not equal to the size of the data before encryption.

[0091] 2. The MD5 hash of the key, which is 16 bytes long, is used to verify the correctness of the password during decryption.

[0092] 3. The MD5 hash of the file to be encrypted, totaling 16 bytes. Used to verify the correctness of the decrypted file.

[0093] 4. The encrypted file. The key used for AES encryption is the SHA256 hash value of the key.

[0094] See Figure 2 The second aspect of this invention provides a method for decrypting AES encrypted files, comprising the following steps:

[0095] S001, Receive the final encrypted file sent by the encrypted terminal;

[0096] S002. Parse the file header of the final encrypted file, and determine whether the final encrypted file is an AES encrypted file based on the file encryption verification information in the file header;

[0097] S003. If the final encrypted file is an AES encrypted file, then receive the input AES decryption key;

[0098] S004. Obtain the third MD5 value of the AES decryption key using the MD5 digest information algorithm;

[0099] S005. Determine whether the third MD5 value is the same as the first MD5 value after the file header of the final encrypted file;

[0100] S006. If the third MD5 value is the same as the first MD5 value, then extract the second MD5 value from the first MD5 value of the final encrypted file, and extract the preliminary encrypted file from the second MD5 value.

[0101] S007. Obtain the fourth MD5 value of the initially encrypted file using the MD5 digest information algorithm;

[0102] S008. Determine whether the fourth MD5 value is the same as the second MD5 value;

[0103] S009. If the fourth MD5 value is the same as the second MD5 value, then the original file is obtained based on the AES decryption key and through the AES decryption function.

[0104] More specifically, the decryption process of the AES encrypted file of this invention is as follows:

[0105] Read the first 16 bytes of the file to get the header, and determine whether header[4] to header[7] are AES1. If not, the target file is not a valid encrypted file. If it is, proceed to the next step.

[0106] If the encrypted file is valid, continue reading the next 16 bytes of data to obtain the MD5 hash of the key, keymd5. Then, calculate the MD5 hash of the key passed in during decoding and compare it with keymd5. If they are different, the key is incorrect. If they are the same, proceed to the next step.

[0107] Continue reading the third 16 bytes of data to obtain the file's MD5 value, filemd5.

[0108] Read all remaining data, which is the encrypted data encData. Calculate the SHA256 of the key, perform decryption, and obtain the decrypted data data.

[0109] Extract the values ​​of header[8] to header

[11] (4 bytes) to obtain the file size filesize. Extract the first filesize bytes of data to obtain the original file file.

[0110] Verify the integrity of the decrypted file. Calculate the MD5 hash of file and compare it with the MD5 hash of file. If they are different, the file to be decrypted has been corrupted; if they are the same, decryption was successful.

[0111] See Figure 3 A third aspect of the present invention provides a file encryption device based on AES encryption, the file encryption device based on AES encryption comprising:

[0112] The key generation module 10 is used to obtain the AES encryption key from a preset key source array by array indexing;

[0113] Encryption module 20 is used to encrypt the file to be encrypted based on the AES encryption key and using the AES encryption function to obtain a preliminary encrypted file;

[0114] The first MD5 value calculation module 30 is used to obtain the first MD5 value of the AES encryption key using the MD5 digest information algorithm.

[0115] The second MD5 value calculation module 40 is used to obtain the second MD5 value of the initially encrypted file using the MD5 digest information algorithm.

[0116] File header construction module 50 is used to construct a file header containing file encryption verification information;

[0117] The file encapsulation module 60 is used to encapsulate the file header, the first MD5 value and the second MD5 value into the header of the initially encrypted file in sequence to obtain the final encrypted file.

[0118] In an optional embodiment of the third aspect of the present invention, the key generation module 10 includes:

[0119] The UTC time acquisition unit is used to acquire the current UTC time of the system.

[0120] UTC time integerization unit, used to convert the UTC time into an integer value in milliseconds;

[0121] A string conversion unit is used to convert the integer value into a numeric string using a preset integer string conversion algorithm;

[0122] A string element splitting unit is used to add an appropriate number of random numbers to the numeric string so that the numeric string can be equally split into 24 numeric elements;

[0123] The division and remainder unit is used to divide the 24 said digital elements by a preset value and take the remainder to obtain 24 integers;

[0124] The character mapping unit is used to obtain 24 mapping characters from a preset key source array using the 24 integers as indices, and to use the string composed of the 24 mapping characters as the AES encryption key.

[0125] In an optional embodiment of the third aspect of the present invention, the AES-based file encryption device further includes:

[0126] The key source array generation module is used to store 26 letters, numbers 0-9, and several special symbols as mapping characters in the key source array in sequence, and to configure corresponding mapping integers for the 26 letters, numbers 0-9, and several special symbols respectively.

[0127] In an optional embodiment of the third aspect of the present invention, if the mapped character determined by the integer as an index is a letter, a random number is generated by a preset random number generator, and the letter is determined to be uppercase or lowercase by the parity attribute of the random number.

[0128] In an optional embodiment of the third aspect of the present invention, the file header construction module 50 includes:

[0129] The file header length determination unit is used to determine the length of the file header as 16 bytes;

[0130] The file type flag information configuration unit is used to configure the 4th to 7th bytes of the 16 bytes to store file type flag information;

[0131] The file size information configuration unit is used to configure the 8th to 11th bytes of the 16 bytes to store file size information.

[0132] In an optional embodiment of the third aspect of the present invention, the AES-based file encryption device further includes:

[0133] The file size determination module is used to determine whether the size of the file to be encrypted is a multiple of 16;

[0134] The file size rounding module is used to pad the end of the file to be encrypted with spaces so that the size of the file to be encrypted is equal to an integer multiple of 16 if the size of the file to be encrypted is not an integer multiple of 16.

[0135] Figure 4This is a schematic diagram of a file encryption device based on AES encryption provided in an embodiment of the present invention. This AES-based file encryption device can vary significantly due to differences in configuration or performance, and may include one or more processors 90 (central processing units, CPUs) (e.g., one or more processors) and memory 100, and one or more storage media 110 (e.g., one or more mass storage devices) for storing applications or data. The memory and storage media can be temporary or persistent storage. The program stored on the storage media may include one or more modules (not shown in the diagram), each module including a series of instruction operations on the AES-based file encryption device. Furthermore, the processor may be configured to communicate with the storage media and execute a series of instruction operations on the storage media for AES-based file encryption.

[0136] The file encryption device based on AES encryption of the present invention may further include one or more power supplies 120, one or more wired or wireless network interfaces 130, one or more input / output interfaces 140, and / or one or more operating systems, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. Those skilled in the art will understand that... Figure 4 The illustrated AES-based file encryption device structure does not constitute a specific limitation on the AES-based file encryption device of the present invention. It may include more or fewer components than illustrated, or combine certain components, or have different component arrangements.

[0137] The present invention also provides a computer-readable storage medium, which can be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium, wherein the computer-readable storage medium stores instructions that, when executed on a computer, cause the computer to perform the steps of the file encryption method based on AES encryption.

[0138] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system, device, or unit described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0139] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0140] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A file encryption method based on AES encryption, characterized in that, Includes the following steps: The AES encryption key is obtained from a preset key source array using array indexing. Based on the AES encryption key and using the AES encryption function, the file to be encrypted is encrypted to obtain a preliminary encrypted file; The first MD5 value of the AES encryption key is obtained using the MD5 digest information algorithm. The second MD5 value of the initially encrypted file is obtained using the MD5 digest information algorithm; Construct a file header that includes file encryption verification information; The file header, the first MD5 value, and the second MD5 value are sequentially encapsulated into the header of the initially encrypted file to obtain the final encrypted file; The step of retrieving the AES encryption key from a preset key source array using array indexing includes: Get the system's current UTC time; Convert the UTC time to an integer value in milliseconds; The integer value is converted into a numeric string using a preset integer-to-string conversion algorithm; Add an appropriate number of random numbers to the numeric string so that the numeric string can be equally split into 24 numeric elements; Divide the 24 numerical elements by the preset value and take the remainder to obtain 24 integers; Using the 24 integers as indices, 24 mapping characters are obtained from a preset key source array, and the string composed of the 24 mapping characters is used as the AES encryption key.

2. The file encryption method based on AES encryption according to claim 1, characterized in that, Before retrieving the AES encryption key from a preset key source array using array indexing, the following steps are included: The 26 letters, the numbers 0-9, and several special symbols are stored as mapping characters in the key source array in sequence, and corresponding mapping integers are configured for the 26 letters, the numbers 0-9, and the several special symbols.

3. The file encryption method based on AES encryption according to claim 2, characterized in that, If the mapped character determined by the integer as an index is a letter, a random number is generated by a preset random number generator, and the parity attribute of the random number is used to determine whether the letter is uppercase or lowercase.

4. The file encryption method based on AES encryption according to claim 1, characterized in that, The constructed file header containing file encryption verification information includes: The file header is 16 bytes long. Bytes 4-7 of the 16 bytes are configured to store file type flag information; Bytes 8-11 of the 16 bytes are configured to store file size information.

5. The file encryption method based on AES encryption according to claim 1, characterized in that, Before obtaining the initially encrypted file by encrypting the file to be encrypted using the AES encryption key and the AES encryption function, the following steps are included: Determine if the size of the file to be encrypted is a multiple of 16; If the size of the file to be encrypted is not a multiple of 16, then a space is added to the end of the file to make the size of the file to be encrypted equal to a multiple of 16.

6. A method for decrypting an AES-encrypted file generated based on the AES-based file encryption method according to any one of claims 1-5, characterized in that, Includes the following steps: Receive the final encrypted file sent by the encrypted terminal; Parse the header of the final encrypted file, and determine whether the final encrypted file is an AES encrypted file based on the file encryption verification information in the header; If the final encrypted file is an AES encrypted file, then the input AES decryption key is received; The third MD5 value of the AES decryption key is obtained using the MD5 digest information algorithm; Determine whether the third MD5 value is the same as the first MD5 value after the header of the final encrypted file; If the third MD5 value is the same as the first MD5 value, then the second MD5 value is extracted from the first MD5 value of the final encrypted file, and the preliminary encrypted file is extracted from the second MD5 value. The fourth MD5 value of the initially encrypted file is obtained using the MD5 digest information algorithm; Determine whether the fourth MD5 value is the same as the second MD5 value; If the fourth MD5 value is the same as the second MD5 value, the original file is obtained based on the AES decryption key and through the AES decryption function.

7. A file encryption device based on AES encryption, characterized in that, The AES-based file encryption device includes: The key generation module is used to obtain the AES encryption key from a preset key source array by array indexing; The encryption module is used to encrypt the file to be encrypted based on the AES encryption key and using the AES encryption function to obtain a preliminary encrypted file; The first MD5 value calculation module is used to obtain the first MD5 value of the AES encryption key using the MD5 digest information algorithm. The second MD5 value calculation module is used to obtain the second MD5 value of the initially encrypted file using the MD5 digest information algorithm. The file header construction module is used to build a file header that contains file encryption and verification information. The file encapsulation module is used to sequentially encapsulate the file header, the first MD5 value, and the second MD5 value into the header of the initially encrypted file to obtain the final encrypted file. The key generation module includes: The UTC time acquisition unit is used to acquire the current UTC time of the system. UTC time integerization unit, used to convert the UTC time into an integer value in milliseconds; A string conversion unit is used to convert the integer value into a numeric string using a preset integer string conversion algorithm; A string element splitting unit is used to add an appropriate number of random numbers to the numeric string so that the numeric string can be equally split into 24 numeric elements; The division and remainder unit is used to divide the 24 said digital elements by a preset value and take the remainder to obtain 24 integers; The character mapping unit is used to obtain 24 mapping characters from a preset key source array using the 24 integers as indices, and to use the string composed of the 24 mapping characters as the AES encryption key.

8. A file encryption device based on AES encryption, characterized in that, The file encryption device based on AES encryption includes: a memory and at least one processor, wherein the memory stores instructions, and the memory and the at least one processor are interconnected via a line; The at least one processor invokes the instructions in the memory to cause the AES-based file encryption device to perform the AES-based file encryption method as described in any one of claims 1-5.

9. A computer-readable storage medium storing a computer program thereon, characterized in that, When the computer program is executed by the processor, it implements the file encryption method based on AES encryption as described in any one of claims 1-5.

Citation Information

Patent Citations

  • File protection method and device

    CN112532379A

  • Data decryption method and device, electronic equipment and storage medium

    CN114189394A

  • Cryptographic method for generating encrypting sequence of symbols in e.g. mobile communication field, involves associating elementary functions to t elements, and calculating elementary functions independently, where t is greater than two

    FR2925992A1