File encryption and decryption method and system

By splitting and mixing files with SM4 and AES encryption algorithms, combined with file secret key processing, the problem of insufficient security of a single symmetric encryption algorithm is solved, and higher encryption security and data protection effects are achieved.

CN119598477APending Publication Date: 2025-03-11SUNSHINE DIGITAL INTELLIGENCE TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411414447.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-11
Publication Date
2025-03-11

AI Technical Summary

Technical Problem

File encryption with existing single symmetric encryption algorithms has the problem of limited security and is easily cracked by attackers.

Method used

By dividing the file into multiple segments and encrypting it using SM4 and AES encryption algorithms respectively, combining the processing and appending of the file keys, the final encrypted file is formed.

Benefits of technology

While maintaining encryption speed and efficiency, it significantly improves encryption security and enhances the protection ability of user data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119598477A_ABST
    Figure CN119598477A_ABST
Patent Text Reader

Abstract

The invention provides a file encryption and decryption method and system, and the method comprises the following steps: segmenting a to-be-encrypted file, and obtaining a plurality of segmented files; encrypting the even-numbered segmented file and the odd-numbered segmented file by adopting different encryption algorithms to obtain a final encrypted file; and decrypting the final encrypted file to obtain a final decrypted file. According to the technical scheme, the file is segmented and encrypted by using the SM4 and AES encryption algorithms in a mixed manner, so that the encryption speed and efficiency are ensured, the encryption security is improved, and more effective guarantee is provided for user data security.
Need to check novelty before this filing date? Find Prior Art

Description

Background Art

[0002] In modern society, people are increasingly relying on digital information and data, which contain a lot of sensitive and confidential information, such as bank account information, personal identity information, business secrets, etc. If this information and data is accessed or stolen by unauthorized persons, it will cause serious losses and impacts to individuals and organizations. Therefore, by encrypting files, you can protect the confidentiality and integrity of the files and prevent unauthorized persons from accessing or stealing sensitive information in the files.

[0003] There are currently two main ways to encrypt files: symmetric key encryption and asymmetric key encryption.

[0004] Symmetric key encryption is a commonly used encryption method that uses the same key to encrypt and decrypt data. The main steps of encryption and decryption are:

[0005] 1. Select a symmetric encryption algorithm, such as AES, DES, or Blowfish, and generate a key.

[0006] 2. Use the key to encrypt the file to be encrypted.

[0007] 3. Save the encrypted file to a disk or other storage medium.

[0008] 4. If the file needs to be decrypted, the same key is used to decrypt the encrypted file.

[0009] 5. The decrypted file is the same as the original file and can be viewed and edited.

[0010] Asymmetric key encryption uses a pair of keys, a public key and a private key, to encrypt and decrypt data. The public key can be made public and anyone can use it to encrypt data, but only the corresponding private key can decrypt the data.

[0011] Symmetric algorithm encryption has the advantages of fast encryption speed and high encryption efficiency. However, using a single symmetric algorithm also has certain problems, such as limited security. If an attacker can obtain the encrypted file and key, the file encrypted by a single symmetric algorithm can be easily cracked. Summary of the invention

[0012] The present application provides a file encryption and decryption method and system, which is used to encrypt files by dividing them into segments and using a mixture of SM4 and AES encryption algorithms, thereby improving the security of encryption while ensuring encryption speed and efficiency, and providing more effective protection for user data security.

[0013] In a first aspect, a method for encrypting and decrypting a file is provided, comprising the following steps:

[0014] Segment the encrypted file to obtain multiple segmented files;

[0015] Encrypting the split files of the even-numbered segments and the split files of the odd-numbered segments using different encryption algorithms to obtain final encrypted files;

[0016] The final encrypted file is decrypted to obtain a final decrypted file.

[0017] In the above technical scheme, the encrypted file is segmented to obtain multiple segmented files; the segmented files of the even-numbered segments and the segmented files of the odd-numbered segments are encrypted using different encryption algorithms to obtain a final encrypted file; the final encrypted file is decrypted to obtain a final decrypted file; by segmenting the file and encrypting it using a mixture of SM4 and AES encryption algorithms, the encryption security is improved while ensuring the encryption speed and efficiency, providing more effective protection for user data security.

[0018] In a specific implementation scheme, the steps of segmenting the file to be encrypted to obtain multiple segmented files are as follows:

[0019] The file to be encrypted is segmented according to fixed sizes to obtain multiple segments of the segmented files.

[0020] In a specific implementation scheme, the steps of encrypting the even-numbered segmented files and the odd-numbered segmented files using different encryption algorithms to obtain the final encrypted files specifically include:

[0021] Generate a file key, wherein the file key includes an SM4 file key and an AES file key;

[0022] The odd-numbered segment files are encrypted using the national SM4 algorithm, and the even-numbered segment files are encrypted using the international AES algorithm to obtain encryption results;

[0023] Writing the encryption result into the initial encrypted file to obtain an intermediate encrypted file;

[0024] The file key is processed and appended to the end of the intermediate encrypted file to obtain the final encrypted file.

[0025] In a specific implementation scheme, the step of processing the file key and appending it to the end of the intermediate encrypted file to obtain the final encrypted file is specifically as follows:

[0026] The file key is calculated using the national encryption SM3 algorithm, and the calculation result is appended to the end of the intermediate encrypted file to obtain the final encrypted file.

[0027] In a specific implementation scheme, the step of decrypting the final encrypted file to obtain the decrypted file specifically includes:

[0028] Verifying the file key;

[0029] Use the national secret SM4 algorithm to decrypt the segmented files of the odd-numbered segments, and use the international AES algorithm to decrypt the segmented files of the even-numbered segments to obtain the decryption results;

[0030] The decryption result is written into the initial decryption file to obtain the final decryption file.

[0031] In a specific implementation scheme, the total length of the final encrypted file read is: the total length of the result of the calculation using the national encryption SM3 algorithm intercepted from the end of the final encrypted file.

[0032] In a specific implementation method, the step of generating the SM4 file key is: randomly generating a 16-bit string as the SM4 file key;

[0033] The steps for generating the AES file key are: converting the SM4 file key into uppercase and lowercase letters, and reversing the order, and then concatenating the SM4 file key with the SM4 file key to form a 32-bit key as the AES file key.

[0034] In a second aspect, a file encryption and decryption system is provided, comprising:

[0035] A segmentation module is used to segment the encrypted file into multiple segmented files;

[0036] An encryption module, used for encrypting the even-numbered segmented files and the odd-numbered segmented files using different encryption algorithms to obtain final encrypted files;

[0037] The decryption module is used to decrypt the final encrypted file to obtain a final decrypted file.

[0038] In the above technical scheme, the encrypted file is segmented to obtain multiple segmented files; the segmented files of the even-numbered segments and the segmented files of the odd-numbered segments are encrypted using different encryption algorithms to obtain a final encrypted file; the final encrypted file is decrypted to obtain a final decrypted file; by segmenting the file and encrypting it using a mixture of SM4 and AES encryption algorithms, the encryption security is improved while ensuring the encryption speed and efficiency, providing more effective protection for user data security.

[0039] In a specific implementation scheme, the encryption module includes:

[0040] A file key generation unit, used to generate a file key, wherein the file key includes an SM4 file key and an AES file key;

[0041] A file encryption unit, used to encrypt the odd-numbered segmented files using the national secret SM4 algorithm, and to encrypt the even-numbered segmented files using the international AES algorithm, to obtain an encryption result;

[0042] An encryption writing unit, used for writing the encryption result into the initial encrypted file to obtain an intermediate encrypted file;

[0043] The key processing unit is used to process the file key and append it to the end of the intermediate encrypted file to obtain the final encrypted file.

[0044] In a specific implementation scheme, the decryption module includes:

[0045] A file key verification unit, used to verify the file key;

[0046] A file decryption unit, used to decrypt the odd-numbered segmented files using the national secret SM4 algorithm, and to decrypt the even-numbered segmented files using the international AES algorithm, to obtain a decryption result;

[0047] The decryption writing unit is used to write the decryption result into the initial decryption file to obtain the final decryption file. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] Figure 1 A flowchart of a file encryption and decryption method provided in an embodiment of the present application;

[0049] Figure 2 This is a structural block diagram of the file encryption and decryption system provided in an embodiment of the present application. DETAILED DESCRIPTION

[0050] The present application is further described in detail below through the accompanying drawings and embodiments. Through these descriptions, the characteristics and advantages of the present application will become clearer and more specific.

[0051] The word "exemplary" is used exclusively herein to mean "serving as an example, embodiment, or illustration." Any embodiment described herein as "exemplary" is not necessarily to be construed as preferred or advantageous over other embodiments. Although various aspects of the embodiments are shown in the drawings, the drawings are not necessarily drawn to scale unless otherwise noted.

[0052] In addition, the technical features involved in different embodiments of the present application described below can be combined with each other as long as they do not conflict with each other.

[0053] To facilitate understanding of the file encryption and decryption method and system provided in the embodiment of the present application, its application scenario is first explained. The file encryption and decryption method and system provided in the embodiment of the present application are used to encrypt the file by segmenting and mixing the SM4 and AES encryption algorithms, while ensuring the encryption speed and efficiency, improving the security of encryption, and providing more effective protection for user data security. At present, there are two main ways to encrypt files: symmetric key encryption and asymmetric key encryption. Symmetric key encryption is a commonly used encryption method that uses the same key to encrypt and decrypt data. The main steps of encryption and decryption are: 1. Select a symmetric encryption algorithm, such as AES, DES or Blowfish, and generate a key. 2. Use the key to encrypt the file to be encrypted. 3. Save the encrypted file to a disk or other storage medium. 4. If you need to decrypt the file, use the same key to decrypt the encrypted file. 5. The decrypted file is the same as the original file and can be viewed and edited. Asymmetric key encryption uses a pair of keys, namely a public key and a private key, to encrypt and decrypt data. The public key can be made public and anyone can use it to encrypt data, but only the corresponding private key can decrypt the data. Symmetric algorithm encryption files have the advantages of fast encryption speed and high encryption efficiency, but there are also certain problems with using a single symmetric algorithm, such as limited security. If an attacker can obtain the encrypted file and key, the file encrypted by a single symmetric algorithm can be easily cracked. For this reason, the embodiment of the present application provides a file encryption and decryption method and system, which can improve the security of encryption while ensuring the encryption speed and efficiency by dividing the file into segments and encrypting it using a mixture of SM4 and AES encryption algorithms, thereby providing more effective protection for user data security. It is described in detail below with specific drawings and embodiments.

[0054] refer to Figure 1 and Figure 2 , Figure 1 A flowchart of a file encryption and decryption method provided in an embodiment of the present application; Figure 2 This is a structural block diagram of the file encryption and decryption system provided in an embodiment of the present application.

[0055] exist Figure 1 In the embodiment of the present application, a method for encrypting and decrypting a file is provided, comprising the following steps:

[0056] Segment the encrypted file to obtain multiple segmented files;

[0057] Encrypting the split files of the even-numbered segments and the split files of the odd-numbered segments using different encryption algorithms to obtain final encrypted files;

[0058] The final encrypted file is decrypted to obtain a final decrypted file.

[0059] In the above technical scheme, the encrypted file is segmented to obtain multiple segmented files; the segmented files of the even-numbered segments and the segmented files of the odd-numbered segments are encrypted using different encryption algorithms to obtain a final encrypted file; the final encrypted file is decrypted to obtain a final decrypted file; by segmenting the file and encrypting it using a mixture of SM4 and AES encryption algorithms, the encryption security is improved while ensuring the encryption speed and efficiency, providing more effective protection for user data security.

[0060] In a specific implementation scheme, the steps of segmenting the file to be encrypted to obtain multiple segmented files are as follows:

[0061] The file to be encrypted is segmented according to fixed sizes to obtain multiple segments of the segmented files.

[0062] In a specific implementation scheme, the steps of encrypting the even-numbered segmented files and the odd-numbered segmented files using different encryption algorithms to obtain the final encrypted files specifically include:

[0063] Generate a file key, wherein the file key includes an SM4 file key and an AES file key;

[0064] The odd-numbered segment files are encrypted using the national SM4 algorithm, and the even-numbered segment files are encrypted using the international AES algorithm to obtain encryption results;

[0065] Writing the encryption result into the initial encrypted file to obtain an intermediate encrypted file;

[0066] The file key is processed and appended to the end of the intermediate encrypted file to obtain the final encrypted file.

[0067] In a specific implementation scheme, the step of processing the file key and appending it to the end of the intermediate encrypted file to obtain the final encrypted file is specifically as follows:

[0068] The file key is calculated using the national encryption SM3 algorithm, and the calculation result is appended to the end of the intermediate encrypted file to obtain the final encrypted file.

[0069] Specifically, file encryption is mainly divided into the following steps:

[0070] 1. Generate file key

[0071] SM4 key generation: Generate a random 16-bit string as the SM4 key (file key);

[0072] AES key generation: convert the SM4 key to uppercase and lowercase, reverse the order, and then concatenate it with the SM4 key to form a 32-bit key as the AES key.

[0073] 2. Split files into fixed sizes and encrypt them using different encryption algorithms

[0074] Assuming the fixed size is 10K, the file bytes to be encrypted are read cyclically, and the size of the bytes read each time is 10K. When the number of reads is an odd number, the national encryption SM4 algorithm is used to encrypt the read bytes. When the number of reads is an even number, the international AES algorithm is used to encrypt the read bytes until the entire file is processed.

[0075] 3. The encryption result is written into the encrypted file

[0076] Write the result of the file circular encryption in the second step into the final encrypted file.

[0077] 4. Process the key and append it to the end of the encrypted file

[0078] Use the national encryption SM3 algorithm to calculate the file key and write the result to the end of the encrypted file.

[0079] In the above technical solution, based on the national SM3, SM4 algorithms and the international AES algorithm, the entire file stream is cut into segments according to a fixed size, and different fragments are encrypted using the SM4 or AES encryption algorithm respectively, which innovatively optimizes the security issues that exist when encrypting files using a single encryption algorithm; while ensuring the encryption speed and efficiency, the encryption security is improved, providing more effective protection for user data security.

[0080] In a specific implementation scheme, the step of decrypting the final encrypted file to obtain the decrypted file specifically includes:

[0081] Verifying the file key;

[0082] Use the national secret SM4 algorithm to decrypt the segmented files of the odd-numbered segments, and use the international AES algorithm to decrypt the segmented files of the even-numbered segments to obtain the decryption results;

[0083] The decryption result is written into the initial decryption file to obtain the final decryption file.

[0084] Specifically, file decryption is mainly divided into the following steps:

[0085] 1. Verify the file key

[0086] Use the national secret SM3 algorithm to calculate the file key to obtain the hash result, and then intercept a fixed length of bytes from the end of the encrypted file. The fixed length is the length of the result of the national secret SM3 algorithm. Compare the intercepted bytes with the hash result bytes of the file key. If they are consistent, the file key is considered correct.

[0087] 2. Split files into fixed sizes and decrypt using different encryption algorithms

[0088] The file bytes that need to be decrypted are read cyclically. When the number of reads is an odd number, the length of the encryption result of the national encryption SM4 algorithm is read and the read bytes are decrypted using the national encryption SM4 algorithm. When the number of reads is an even number, the length of the encryption result of the international AES algorithm is read and the read bytes are decrypted using the international AES algorithm. The total length of the read file is: the total length after intercepting the length of the national encryption SM3 algorithm calculation result from the end of the encrypted file.

[0089] 3. Write the decryption result to the file

[0090] Write the result of the file cyclic decryption in the second step into the final decrypted file.

[0091] In a specific implementation scheme, the total length of the final encrypted file read is: the total length of the result of the calculation using the national encryption SM3 algorithm intercepted from the end of the final encrypted file.

[0092] In a specific implementation method, the step of generating the SM4 file key is: randomly generating a 16-bit string as the SM4 file key;

[0093] The steps for generating the AES file key are: converting the SM4 file key into uppercase and lowercase letters, and reversing the order, and then concatenating the SM4 file key with the SM4 file key to form a 32-bit key as the AES file key.

[0094] exist Figure 2 In the embodiment of the present application, a file encryption and decryption system is provided, comprising:

[0095] A segmentation module is used to segment the encrypted file into multiple segmented files;

[0096] An encryption module, used for encrypting the even-numbered segmented files and the odd-numbered segmented files using different encryption algorithms to obtain final encrypted files;

[0097] The decryption module is used to decrypt the final encrypted file to obtain a final decrypted file.

[0098] In the above technical scheme, the encrypted file is segmented to obtain multiple segmented files; the segmented files of the even-numbered segments and the segmented files of the odd-numbered segments are encrypted using different encryption algorithms to obtain a final encrypted file; the final encrypted file is decrypted to obtain a final decrypted file; by segmenting the file and encrypting it using a mixture of SM4 and AES encryption algorithms, the encryption security is improved while ensuring the encryption speed and efficiency, providing more effective protection for user data security.

[0099] In a specific implementation scheme, the encryption module includes:

[0100] A file key generation unit, used to generate a file key, wherein the file key includes an SM4 file key and an AES file key;

[0101] A file encryption unit, used to encrypt the odd-numbered segmented files using the national secret SM4 algorithm, and to encrypt the even-numbered segmented files using the international AES algorithm, to obtain an encryption result;

[0102] An encryption writing unit, used for writing the encryption result into the initial encrypted file to obtain an intermediate encrypted file;

[0103] The key processing unit is used to process the file key and append it to the end of the intermediate encrypted file to obtain the final encrypted file.

[0104] In a specific implementation scheme, the decryption module includes:

[0105] A file key verification unit, used to verify the file key;

[0106] A file decryption unit, used to decrypt the odd-numbered segmented files using the national secret SM4 algorithm, and to decrypt the even-numbered segmented files using the international AES algorithm, to obtain a decryption result;

[0107] The decryption writing unit is used to write the decryption result into the initial decryption file to obtain the final decryption file.

[0108] Those skilled in the art will appreciate that the present application may be implemented as a system, method or computer program product.

[0109] Therefore, the present disclosure may be specifically implemented in the following forms, namely: it may be completely hardware, it may be completely software (including firmware, resident software, microcode, etc.), or it may be a combination of hardware and software, generally referred to herein as a "circuit", "module" or "system". In addition, in some embodiments, the present application may also be implemented in the form of a computer program product in one or more computer-readable media, and the computer-readable medium may contain computer-readable program code.

[0110] Any combination of one or more computer-readable media can be used. Computer-readable media can be computer-readable signal media or computer-readable storage media. Computer-readable storage media can be, for example, but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or devices, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: electrical connections with one or more wires, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In this document, computer-readable storage media can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.

[0111] Although the embodiments of the present application have been shown and described above, it is understood that the above embodiments are exemplary and cannot be understood as limiting the present application. A person of ordinary skill in the art can change, modify, replace and modify the above embodiments within the scope of the present application. On this basis, a variety of replacements and improvements can be made to the present application, all of which fall within the scope of protection of the present application.

Claims

1. A file encryption and decryption method, characterized in that: The following steps are involved: Segment the encrypted file to obtain multiple segmented files; Encrypting the split files of the even-numbered segments and the split files of the odd-numbered segments using different encryption algorithms to obtain final encrypted files; The final encrypted file is decrypted to obtain a final decrypted file.

2. The file encryption and decryption method according to claim 1, characterized in that: The steps of segmenting the encrypted file to obtain multiple segmented files are as follows: The file to be encrypted is segmented according to fixed sizes to obtain multiple segments of the segmented files.

3. The file encryption and decryption method according to claim 2, characterized in that: The steps of encrypting the even-numbered segmented files and the odd-numbered segmented files using different encryption algorithms to obtain the final encrypted files specifically include: Generate a file key, wherein the file key includes an SM4 file key and an AES file key; The odd-numbered segment files are encrypted using the national SM4 algorithm, and the even-numbered segment files are encrypted using the international AES algorithm to obtain encryption results; Writing the encryption result into the initial encrypted file to obtain an intermediate encrypted file; The file key is processed and appended to the end of the intermediate encrypted file to obtain the final encrypted file.

4. The file encryption and decryption method according to claim 3, characterized in that: The steps of processing the file key and appending it to the end of the intermediate encrypted file to obtain the final encrypted file are specifically as follows: The file key is calculated using the national encryption SM3 algorithm, and the calculation result is appended to the end of the intermediate encrypted file to obtain the final encrypted file.

5. The file encryption and decryption method according to claim 4, characterized in that: The step of decrypting the final encrypted file to obtain a decrypted file specifically includes: Verifying the file key; Use the national secret SM4 algorithm to decrypt the segmented files of the odd-numbered segments, and use the international AES algorithm to decrypt the segmented files of the even-numbered segments to obtain the decryption results; The decryption result is written into the initial decryption file to obtain the final decryption file.

6. The file encryption and decryption method according to claim 5, characterized in that: The total length of the final encrypted file read is: the total length of the result of the calculation by the national encryption SM3 algorithm intercepted from the end of the final encrypted file.

7. The file encryption and decryption method according to claim 6, characterized in that: The steps of generating the SM4 file key are as follows: randomly generating a 16-bit string as the SM4 file key; The steps for generating the AES file key are: converting the SM4 file key into uppercase and lowercase letters, and reversing the order, and then concatenating the SM4 file key with the SM4 file key to form a 32-bit key as the AES file key.

8. A file encryption and decryption system, characterized in that: include: A segmentation module is used to segment the encrypted file into multiple segmented files; An encryption module, used for encrypting the even-numbered segmented files and the odd-numbered segmented files using different encryption algorithms to obtain final encrypted files; The decryption module is used to decrypt the final encrypted file to obtain a final decrypted file.

9. The file encryption and decryption system according to claim 8, characterized in that: The encryption module comprises: A file key generation unit, used to generate a file key, wherein the file key includes an SM4 file key and an AES file key; A file encryption unit, used to encrypt the odd-numbered segmented files using the national secret SM4 algorithm, and to encrypt the even-numbered segmented files using the international AES algorithm, to obtain an encryption result; An encryption writing unit, used for writing the encryption result into the initial encrypted file to obtain an intermediate encrypted file; The key processing unit is used to process the file key and append it to the end of the intermediate encrypted file to obtain the final encrypted file.

10. The file encryption and decryption system according to claim 9, characterized in that: The decryption module comprises: A file key verification unit, used to verify the file key; A file decryption unit, used to decrypt the odd-numbered segmented files using the national secret SM4 algorithm, and to decrypt the even-numbered segmented files using the international AES algorithm, to obtain a decryption result; The decryption writing unit is used to write the decryption result into the initial decryption file to obtain the final decryption file.