File uploading method and device, equipment and storage medium
By using a virtual instruction set module in the browser to encrypt and upload large files in chunks, the problems of browser main thread blocking and security risks are solved, and efficient and secure file chunk upload is achieved.
Patent Information
- Application Number
- CN202511745080.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-25
- Publication Date
- 2026-03-17
AI Technical Summary
In existing technologies, uploading large files in chunks results in low performance on the browser's main thread, causing other operations to be blocked. Furthermore, the browser cannot encrypt the files, posing a security risk.
The encryption algorithm in the virtual instruction set module is used to encrypt the file to be uploaded, generating an encrypted file. Then, a fragmentation algorithm is used to fragment the file and upload them sequentially. The high-performance encryption and fragmentation algorithms are run in the browser to ensure file security and efficiency.
It improves the browser's fragmentation efficiency, ensures the security of file uploads, avoids the leakage of original file information, and enhances the user experience.
Smart Images

Figure CN121691303A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the field of information technology, and particularly relates to a file uploading method and device, an electronic device and a storage medium. BACKGROUND
[0002] In the prior art, a large file chunk uploading scheme is usually to upload a file to a server of a browser for overall verification, obtain an overall verification result, then perform chunk processing and MD5 (Message-Digest Algorithm 5) calculation on the file to be uploaded according to the overall verification result, and finally receive file chunks by the server of the browser and combine the corresponding MD5 values to obtain the uploaded file.
[0003] Although this method can realize the function of large file chunk uploading, using js (JavaScript) code in the main thread of the browser for large file chunk processing will cause other operations to be blocked, and the processing performance is low, and the browser cannot encrypt the file to be uploaded, which has a security risk.
[0004] Therefore, how to efficiently and safely perform large file chunk uploading has become a problem to be solved. SUMMARY
[0005] The purpose of the embodiments of the present application is to provide a file uploading method, which can solve the problems of low efficiency and high risk of the browser when processing large file uploading.
[0006] Correspondingly, the embodiments of the present application also provide a file uploading device, an electronic device and a storage medium to ensure the implementation and application of the above method.
[0007] In order to solve the above technical problems, the present application is implemented as follows: In a first aspect, the embodiments of the present application provide a file uploading method applied to an electronic device, wherein the electronic device provides a browser loaded with a virtual instruction set module, and the method comprises the following steps: determining a file to be uploaded in response to a selection operation of a user; calling an encryption algorithm in the virtual instruction set module to encrypt the file to be uploaded to obtain an encrypted file; calling a chunk algorithm in the virtual instruction set module to chunk the encrypted file to obtain a plurality of chunk encrypted files; uploading the chunk encrypted files in sequence.
[0008] Optionally, the step of calling the encryption algorithm in the virtual instruction set module to encrypt the file to be uploaded to obtain an encrypted file comprises the following steps: obtaining a shared key; generating an encryption key according to the shared key; generating a plurality of round keys according to the encryption key, the number of the round keys being determined according to the length of the encryption key; encrypting the file to be uploaded using the round keys in sequence to obtain an encrypted file.
[0009] Optionally, the step of encrypting the file to be uploaded using the round keys in sequence to obtain an encrypted file comprises: generating a corresponding byte matrix according to the file to be uploaded; performing byte replacement on the byte matrix; performing row shifting on the byte matrix after byte replacement; performing column confusion on the byte matrix after row shifting; performing XOR operation on the byte matrix after column confusion and the round key of the current round to generate a round encryption matrix; judging the number of unused round keys; in the case where the number of unused round keys is not 1, updating the byte matrix according to the round encryption matrix and returning to the step of performing byte replacement on the byte matrix; in the case where the number of unused round keys is 1, performing byte replacement on the round encryption matrix, performing row shifting on the round encryption matrix after byte replacement, and performing XOR operation on the round encryption matrix after row shifting and the round key of the current round to generate an encrypted file.
[0010] Optionally, before the step of obtaining a shared key, the method comprises: obtaining a key parameter and a client private key; generating a client public key according to the key parameter and the client private key; sending the client public key to a server; receiving a server public key sent by the server; generating a shared key according to the server public key, the client private key and the key parameter.
[0011] Optionally, the step of calling a fragmentation algorithm in the virtual instruction set module to fragment the encrypted file to obtain a plurality of fragmented encrypted files comprises: obtaining a preset fragmentation size and a file size of the encrypted file; determining a corresponding number of fragments according to the fragmentation size and the file size of the encrypted file; generating corresponding fragmented encrypted files according to the number of fragments.
[0012] Optionally, generating the corresponding fragmented encrypted file based on the number of fragments includes: Create a corresponding number of fragment files based on the stated number of fragments; Assign a corresponding sequence number to each of the aforementioned file segments; Read byte data of the fragment size sequentially from the encrypted file, and write the read byte data into the fragment file according to the sequence number to generate a fragmented encrypted file.
[0013] Optionally, the method further includes: Obtain the source code for the encryption and sharding algorithms; Convert the source code into intermediate code; The intermediate code is subjected to instruction substitution, loop adjustment, and memory management to generate optimized intermediate code; Compile the optimized intermediate code to generate a virtual instruction set file; The virtual instruction set module is obtained from the virtual instruction set file.
[0014] Secondly, embodiments of this application provide a file upload device applied to an electronic device, wherein the electronic device provides a browser loaded with a virtual instruction set module, and the device includes: The "File to be uploaded" module is used to determine the file to be uploaded in response to the user's selection. The encryption module is used to call the encryption algorithm in the virtual instruction set module to encrypt the file to be uploaded, thereby obtaining an encrypted file; The fragmentation module is used to call the fragmentation algorithm in the virtual instruction set module to fragment the encrypted file, thereby obtaining multiple fragmented encrypted files; The upload module is used to upload the fragmented encrypted files sequentially.
[0015] Thirdly, embodiments of this application provide an electronic device including a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the method described in the first aspect.
[0016] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first aspect.
[0017] Compared with the prior art, the embodiments of this application have the following advantages: In this embodiment, the electronic device can provide a browser loaded with a virtual instruction set module. Responding to a user's selection, the browser determines the file to be uploaded, then calls the encryption algorithm in the virtual instruction set module to encrypt the file, obtaining an encrypted file. Next, it calls the fragmentation algorithm in the virtual instruction set module to fragment the encrypted file, obtaining multiple fragmented encrypted files, which are then uploaded sequentially. The virtual instruction set module can run high-performance fragmentation algorithms within the browser with good compatibility, improving the browser's fragmentation efficiency. Furthermore, the virtual instruction set module can also run high-performance encryption algorithms in other languages within the browser, solving the problem of browsers being unable to encrypt files to be uploaded and ensuring the security of file fragmented uploads. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 This is a flowchart illustrating the steps of an embodiment of a file upload method according to this application; Figure 2 This is a flowchart illustrating the steps of another embodiment of the file upload method of this application; Figure 3 This is a flowchart of the AES encryption algorithm steps in one embodiment of the file upload method of this application; Figure 4 This is a flowchart of the file fragmentation algorithm steps of one embodiment of the file upload method of this application; Figure 5 This is a flowchart of the WebAssembly compilation steps for another embodiment of the file upload method of this application; Figure 6 This is a flowchart illustrating the steps of another embodiment of the file upload method of this application; Figure 7 This is a structural block diagram of an embodiment of a file upload device according to this application. Detailed Implementation
[0020] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0021] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0022] In related technologies, the operation of uploading large files in chunks is usually achieved through the following steps: Calculate the MD5 hash of the file to be uploaded to obtain the overall MD5 value of the file. The upload process involves sending the file to the browser's server and verifying it based on the overall MD5 value to obtain the overall verification result. Based on the overall inspection results, the file to be uploaded is segmented to obtain the file segments to be uploaded. MD5 calculation is performed on the file fragments to be uploaded to obtain the MD5 value of the file fragments; Upload the file segments to be uploaded to the browser's server. The browser's server receives the file fragments to be uploaded, obtains the uploaded file fragments, and merges them with the MD5 values of the file fragments to obtain the uploaded file.
[0023] While the above process enables the uploading of large files in chunks, this method performs the chunking process on the browser's main thread, which can easily block other operations. Furthermore, the performance of using JavaScript to process file chunks is relatively low, impacting user experience. Additionally, related technologies cannot encrypt the uploaded files within the browser, potentially leading to data security issues during the upload process. To address, or at least partially address, these problems in related technologies, this application proposes a file upload method, apparatus, device, and storage medium.
[0024] The file upload method provided in this application will be described in detail below with reference to the accompanying drawings, through specific embodiments and application scenarios.
[0025] WASM (WebAssembly) is a virtual instruction set architecture that provides a binary instruction format designed for web browsers. It aims to be a compilation target for efficient programming languages, enabling the deployment of client and server applications on the network. It features speed, efficiency, portability, and security.
[0026] ReferenceFigure 1 This is a flowchart illustrating the steps of an embodiment of a file upload method according to this application. This method embodiment can be applied to an electronic device, which provides a browser loaded with a virtual instruction set module, and includes the following steps: Step 101: In response to the user's selection, determine the file to be uploaded; The file to be uploaded can be a local file that the user needs to upload.
[0027] Step 102: Invoke the encryption algorithm in the virtual instruction set module to encrypt the file to be uploaded, and obtain an encrypted file; The encryption algorithm may include at least the AES (Advanced Encryption Standard) encryption algorithm. AES is a symmetric encryption algorithm that uses the same key for encryption and decryption.
[0028] Step 103: Call the fragmentation algorithm in the virtual instruction set module to fragment the encrypted file, resulting in multiple fragmented encrypted files; Step 104: Upload the fragmented encrypted files sequentially.
[0029] The system can respond to user selections, determine the file to be uploaded, and then use a high-performance encryption algorithm provided by the virtual instruction set module to encrypt the file. This results in an encrypted file. Next, a high-performance fragmentation algorithm from the same module is used to fragment the encrypted file, resulting in multiple fragmented encrypted files. These fragmented encrypted files are then uploaded sequentially. Through this process, the virtual instruction set module can run high-performance fragmentation algorithms in the browser with good compatibility. It can also run high-performance encryption algorithms for other languages in the browser, resolving the issue of browsers being unable to encrypt uploaded files. Uploading files through a browser with the virtual instruction set module enabled allows for the use of its encryption and fragmentation algorithms, ensuring the security of fragmented file uploads, improving the efficiency of uploading large files, and enhancing the user experience. Furthermore, encrypting before fragmentation maximizes the security of the uploaded file, preventing the leakage of its original information.
[0030] For example, users can interact with the HTML DOM (Document Object Model) to select the file to upload, i.e., the file to be uploaded. This can be done using a format with type="file". <input>This element creates an input field that allows users to select a file. It can then listen for user selections within this field, responding to the selection to determine the file to be uploaded and retrieve its information. Alternatively, the uploader component from a UI (User Interface) library can be used to determine the file to be uploaded; this application does not impose specific restrictions on this approach.
[0031] In one embodiment of this application, the step of encrypting the file to be uploaded by calling the encryption algorithm in the virtual instruction set module to obtain an encrypted file includes: Obtain the shared key; Generate an encryption key based on the shared key; Multiple round keys are generated based on the encryption key, and the number of round keys is determined according to the length of the encryption key; The file to be uploaded is encrypted sequentially using the round key to obtain an encrypted file.
[0032] The shared key refers to the key held jointly by the client (local device) that holds the file to be uploaded and the server to which the file will be uploaded.
[0033] A shared key can be obtained locally on the client side. The AES encryption algorithm has key lengths of 128 bits, 192 bits, and 256 bits; the longer the key length, the higher the encryption strength. Since the shared key length may not meet the AES key length requirements, after obtaining the shared key, an algorithm such as a key derivation function (KDF) can be used to generate encryption keys of the corresponding length based on the user-selected key length. The invoked AES encryption algorithm can also expand the encryption key, generating multiple round keys. The number of round keys depends on the length of the encryption key. If the user selects a 128-bit key length, 11 round keys are typically generated, which can be used for 10 rounds of encryption; if the user selects a 192-bit key length, 13 round keys are typically generated, which can be used for 12 rounds of encryption; and if the user selects a 256-bit key length, 15 round keys are typically generated, which can be used for 14 rounds of encryption. After obtaining the round keys, the uploaded file can be encrypted sequentially using the round keys to obtain the encrypted file. Through the above implementation process, a round key for file encryption can be generated based on the shared key between the client and the server, which can simultaneously ensure the encryption effect of the file to be uploaded and the decryption requirements after the file is uploaded.
[0034] Reference Figure 2This is a flowchart illustrating the steps of another embodiment of the file upload method of this application. In one embodiment of this application, the step of sequentially encrypting the file to be uploaded using the round key to obtain an encrypted file includes: Step 201: Generate a corresponding byte matrix based on the file to be uploaded; The byte matrix is a state matrix obtained by grouping the plaintext of the file to be uploaded according to the key length selected by the user, and then organizing the plaintext of each group into a 4×4 byte matrix. For example, if the user selects a key length of 128 bits, the plaintext of the file to be uploaded will be grouped into groups of 16 bytes each, and then the 16 bytes of plaintext grouped into a 4×4 byte matrix will be organized. If the user selects a key length of other lengths, the byte matrix is generated in a similar way, which will not be described in detail in this application.
[0035] Step 202: Perform byte replacement on the byte matrix; Byte substitution can involve independently replacing each byte in the state matrix with another byte. For example, a lookup table of S-Boxes (substitution boxes) can be used to perform a non-linear transformation on each byte in the byte matrix. S-Boxes are carefully designed to provide the "obfuscation" properties necessary for encryption, making the relationship between input and output highly complex and difficult to derive mathematically.
[0036] Step 203: Perform row shifting on the byte matrix after byte replacement; Row shifting can be achieved by cyclically shifting each row of the byte matrix to the left. For example, the first row can be cyclically shifted left by 1 byte, the second row by 2 bytes, the third row by 3 bytes, and so on. Row shifting can provide a "diffusion" property, breaking the independence between columns and allowing a change in one byte to propagate across multiple columns.
[0037] Step 204: Perform column obfuscation on the row-shifted byte matrix; Column obfuscation involves multiplying each column of a byte matrix with a fixed matrix over a Galois field, resulting in a new column that replaces the original column. Column obfuscation offers a strong "diffusion" property.
[0038] Step 205: Perform an XOR operation between the column-obfuscated byte matrix and the round key of the current round to generate a round encryption matrix; The XOR operation can be a bitwise XOR operation or other XOR operations; this application does not impose specific restrictions on it. The XOR operation is reversible, which facilitates subsequent decryption of the file.
[0039] Step 206: Determine the number of unused round keys; Step 207: If the number of unused round keys is not 1, update the byte matrix according to the round encryption matrix, and return to perform byte replacement on the byte matrix; Step 208: If the number of unused round keys is 1, perform byte replacement on the round encryption matrix; perform row shift on the byte-replaced round encryption matrix; perform an XOR operation between the row-shifted round encryption matrix and the round key of the current round to generate an encrypted file.
[0040] The plaintext of the file to be uploaded can be grouped according to the key length selected by the user, and then each group is organized into a corresponding byte matrix. Before the first round of encryption, a round key is XORed with the byte matrix corresponding to the plaintext of the file to be uploaded, i.e., initial round key addition. Then, the first round of encryption can begin, byte substitution is performed on the byte matrix, then row shifting is performed on the byte matrix after byte substitution, column obfuscation is performed on the row shifted byte matrix, and then XORing is performed with the current round key to generate the round encryption matrix. Each round uses a different round key, and the progress of round encryption can be determined by checking the number of unused round keys. If the number of unused round keys is not 1, it means that the next round of encryption is not the last round. At this time, the byte matrix can be updated according to the round encryption matrix, and the byte substitution is returned to continue the next round of byte substitution, row shifting, column obfuscation, and round key addition operations. When there is only one unused round key, it indicates that the next round is the final round of encryption. Byte substitution can be performed on the round encryption matrix, followed by row shifting. The column obfuscation step is omitted, and the row-shifted round encryption matrix is directly XORed with the current round key to generate the final encrypted file. Through this process, the AES encryption algorithm in the virtual instruction set module can perform multiple rounds of encryption on the file without the user's knowledge. AES employs a highly complex algorithm, including byte substitution, row shifting, and column obfuscation, making it difficult for attackers to find an effective attack path. This effectively ensures that the file to be uploaded will not be intercepted and read during the upload process, thus significantly reducing the risk of data leakage during file upload.
[0041] In one embodiment of this application, before obtaining the shared key, the method includes: Obtain the key parameters and client private key; Generate a client public key based on the key parameters and the client private key; Send the client's public key to the server; Receive the server's public key sent by the server; A shared key is generated based on the server public key, the client private key, and the key parameters.
[0042] The key parameters can include a prime number p and a generator g. The prime number is used to define the space for modulo operations and must be large enough, such as 2048 bits or higher, to ensure key security. The generator can be an integer smaller than the prime number, typically 2 or 5. The generator g is a primitive root modulo p, ensuring the generation of a sufficiently large cyclic group. The key parameters are public and can be transmitted over insecure channels, ensuring that both the client and server share these parameters without compromising security.
[0043] The initial key parameters can be obtained. Additionally, the client-generated private key 'a' can be retrieved from the client; 'a' can be a random number satisfying 1. <a<p 1. Then, a client public key A can be generated based on the key parameters and the client's private key. For example, A = g^a mod p. The client public key can then be sent to the server, and the server's public key B can be received from the server. A shared key K can be generated based on the server's public key, the client's private key, and the key parameters. For example, K = B^a mod p.
[0044] Correspondingly, the server can also generate a server public key B based on the public key parameters, including the prime number p and the generator g, and the server private key b generated on the server. b can be a random number that satisfies... <b<p 1. For example, B = g^b mod p. The server can then send its public key to the client and receive the client's public key A. A shared key K can be generated based on the client's public key, the server's private key, and key parameters. For example, K = A^b mod p. B^a mod p is equivalent to A^b mod p. Through the above implementation process, a shared key can be generated between the client and the server without prior sharing of keys. This shared key is used for subsequent encryption of files to be uploaded by the client and decryption of received fragmented encrypted files by the server, thus ensuring data security.
[0045] For example, after generating a shared key, the shared key can be reversibly converted by symmetric or asymmetric encryption before being saved to the client's localStorage to avoid exposing the plaintext of the shared key. The shared key can also be changed periodically to ensure data security.
[0046] Reference Figure 3This is a flowchart of the AES encryption algorithm steps of an embodiment of a file upload method of this application, including the following steps; Step 301: Generate an AES key and expand the key to generate multiple round keys; Step 302: Process the data. If the plaintext data length is not a multiple of 128 bits, pad it using PKCS#7. Step 303: Perform multiple rounds of encryption, with each round involving byte substitution, row shifting, column obfuscation, and round key addition. Step 304: In the final round, the column obfuscation step is omitted. The final round key is XORed with the state matrix to obtain the final ciphertext.
[0047] An AES key (encryption key) can be generated using a shared key between the server and client. This key can then be expanded to generate multiple round keys. The uploaded file data can then be processed. The AES algorithm requires the plaintext data length to be a multiple of the block length, typically 128 bits (16 bytes). If the plaintext data length is not a multiple of 128 bits, it needs to be padded to meet the AES algorithm's length requirement. For example, PKCS#7 padding can be used, adding an appropriate number of bytes to the end of the plaintext data to make it an integer multiple of the block length. Then, multiple rounds of encryption can be performed on the plaintext data that meets the requirements. Each round involves byte substitution, row shifting, column obfuscation, and round key addition. Round key addition involves XORing the column-obfuscated byte matrix with the current round key. In the final round, the column obfuscation step is omitted; the final round key is directly XORed with the row-shifted state matrix to obtain the final ciphertext, i.e., the encrypted file.
[0048] In one embodiment of this application, the step of calling the fragmentation algorithm in the virtual instruction set module to fragment the encrypted file to obtain multiple fragmented encrypted files includes: Obtain the preset fragment size and the file size of the encrypted file; The corresponding number of fragments is determined based on the fragment size and the file size of the encrypted file; Generate a corresponding fragmented encrypted file based on the number of fragments.
[0049] The preset chunk size and the size of the encrypted file can be obtained. For example, the chunk size can be set to 5MB (megabytes), i.e., 5 * 1024 * 1024 bytes. The chunk size can be specifically set according to the network conditions of the electronic device, the size of the encrypted file, and the processing capacity of the server; this application does not impose specific limitations on this. Then, the corresponding number of chunks can be determined based on the chunk size and the size of the encrypted file. If the size of the last chunk does not meet the actual preset chunk size, then chunking is performed according to its actual size. The encrypted file can be chunked according to the number of chunks to generate the corresponding chunked encrypted file. Through the above implementation process, the number of chunks to be performed can be determined, and the encrypted file can be chunked according to the number of chunks to generate the corresponding chunked encrypted file, ensuring that large files to be uploaded can be effectively divided into multiple smaller fragments for uploading.
[0050] In one embodiment of this application, generating a corresponding fragmented encrypted file based on the number of fragments includes: Create a corresponding number of fragment files based on the stated number of fragments; Assign a corresponding sequence number to each of the aforementioned file segments; Read byte data of the fragment size sequentially from the encrypted file, and write the read byte data into the fragment file according to the sequence number to generate a fragmented encrypted file.
[0051] Based on the number of fragments, corresponding fragment files can be created, and each fragment file can be assigned a sequence number and name. Then, bytes of data equal to the size of each fragment can be read sequentially from the encrypted file, stored in a buffer, and the created fragment file can be opened according to its sequence number. The bytes in the buffer can then be written into the fragment file, generating a fragmented encrypted file. This process continues until the entire encrypted file has been read. Through this process, the encrypted file can be read sequentially and written sequentially into the corresponding created fragment files, achieving accurate, ordered, and efficient fragmentation of the encrypted file.
[0052] Reference Figure 4 This is a flowchart of the file fragmentation algorithm steps of an embodiment of the file upload method of this application, including the following steps: Step 401: Read the original file and determine the fragment size; the original file is the encrypted file obtained after encrypting the file to be uploaded. Step 402: Calculate the number of fragments, including: calculating the number of fragments to be performed based on the original file size and the fragment size; Step 403: Loop through the read and write buffer, including: reading bytes of a specified size from the original file into the buffer. The size of the bytes read is determined by the size of the fragment. A new fragment file can be opened or created. The bytes in the buffer are written into this fragment file to generate a fragmented encrypted file. This read and write process is repeated until the original file has been completely read. Step 404: Calculate and record the hash value, including: For each fragmented encrypted file, a hash algorithm can be used to calculate the hash value of its content, record the hash value of each fragmented encrypted file, and after recording the hash values corresponding to all fragmented encrypted files, this hash value record can be uploaded to the backend of the local device. The backend can perform integrity verification and fragmentation accuracy verification on the fragmented encrypted files according to the hash values corresponding to the fragmented encrypted files to ensure the accuracy and effectiveness of the fragmentation operation. Step 405: Close file streams, including: closing all open file streams at the end of the segment; Step 406: Return the fragment list, including: generating a fragment list based on the name, size, and sequence number of the fragmented encrypted file. The fragment list contains all file fragment information, and each element in the list corresponds to the file information of a fragmented encrypted file.
[0053] In one embodiment of this application, the method further includes: Obtain the source code for the encryption and sharding algorithms; Convert the source code into intermediate code; The intermediate code is subjected to instruction substitution, loop adjustment, and memory management to generate optimized intermediate code; Compile the optimized intermediate code to generate a virtual instruction set file; The virtual instruction set module is obtained from the virtual instruction set file.
[0054] The source code for the encryption and sharding algorithms can be written in Rust or C / C++, or in other optional languages; this application does not impose specific restrictions on this. Intermediate Representation (IR) is a code representation independent of a specific programming language, converting source code into an intermediate state to facilitate subsequent optimization and conversion by the compiler.
[0055] Instruction substitution in intermediate code refers to selecting more efficient machine instructions to implement operations in IR. For example, certain instruction sequences can be replaced by a single instruction, which then replaces the original instruction sequence. Alternatively, faster instructions can be selected to replace existing instructions in the intermediate code based on the characteristics of the target machine.
[0056] Adjusting intermediate code through loops can include: moving invariant calculations outside the loop; simplifying or eliminating inductive variables (loop counters) within the loop; copying the loop body multiple times to reduce loop control overhead; merging multiple adjacent loops into one to reduce loop overhead and improve locality; and splitting a single loop into multiple loops. Loops are the most frequently executed part of an algorithm, and optimizing loops can significantly improve algorithm performance.
[0057] Memory management of intermediate code refers to optimizing memory access, which can include: merging multiple memory accesses into one to reduce the number of memory operations; aligning data structures to natural boundaries as much as possible to improve memory access efficiency; preloading data to be used into the cache; and replacing array elements with scalar variables to reduce memory access.
[0058] The source code of encryption and sharding algorithms can be obtained and then converted into intermediate code using a compiler. After conversion, the intermediate code can be optimized through instruction substitution, loop adjustment, and memory management. The intermediate code can then be compiled, mapping the operations to the Wasm instruction set, converting it to Wasm binary format, and generating a virtual instruction set file (with the .wasm extension). This virtual instruction set file can contain all the Wasm binary instructions and necessary metadata for the application and can be loaded into a browser for execution. The virtual instruction set file can then be loaded and instantiated to obtain a virtual instruction set module. Through this process, algorithm source code written in a high-level language can be converted into Wasm binary format that can run efficiently in a browser. Converting source code to intermediate code facilitates subsequent optimization and conversion. Instruction substitution, loop adjustment, and memory management can optimize the intermediate code to improve execution efficiency. Mapping the operations to the Wasm instruction set yields a virtual instruction set module that provides high-performance encryption and sharding algorithms.
[0059] Figure 5 This is a flowchart of the WebAssembly compilation steps for another embodiment of the file upload method of this application, including the following steps: Step 501: The compiler converts the source code into IR; Step 502: The compiler optimizes the IR to improve code execution efficiency; Step 503: The compiler converts the optimized IR into Wasm binary format and maps the IR operations to the Wasm instruction set; Step 504: After compilation, the corresponding Wasm file will be generated.
[0060] The compiler can convert the source code of encryption and fragmentation algorithms into Intermediate Resource Definition (IR). The compiler can then optimize the IR to improve code execution efficiency. Optimization methods can include instruction selection, loop optimization, and memory management. The compiler can then convert the optimized IR into Wasm binary format, mapping IR operations to the Wasm instruction set. After compilation, a corresponding Wasm file (virtual instruction set file) is generated. This Wasm file is the core of the Wasm module (virtual instruction set module) and will be loaded into the browser for execution.
[0061] For example, when the Wasm module is loaded into a browser, the browser uses its built-in Wasm engine to parse and execute the Wasm code. The Wasm engine can compile (or just-in-time compile) the Wasm binary instructions into native machine code for the browser's platform and execute it within the browser's security sandbox. Compared to JavaScript's fragmentation algorithms in related technologies, the Wasm module offers better performance and efficiency, enabling more efficient file fragmentation for uploads. Furthermore, the Wasm module can run efficient algorithms directly within the browser, overcoming the browser's inability to encrypt files. The Wasm module boasts high compatibility, allowing for debugging to adapt to different browsers and user habits, thus increasing user convenience.
[0062] For example, the loading and instantiation process of the Wasm module may include the following steps: Obtain the Wasm file; the Wasm file can be a locally generated .wasm file or a .wasm file obtained from the network. After obtaining the Wasm file, you can use JavaScript's fetch API (Web Data Interaction Interface) or XMLHttpRequest (browser's request object) to load the Wasm module and read it as an Array Buffer (data buffer); Creating a WebAssembly.Module (virtual instruction set module) includes: directly instantiating the module and creating instances using WebAssembly.instantiate (the compilation and instantiation interface); After creating a WebAssembly.Instance object, you can access the functions and variables exported by the module through the instance.exports property.
[0063] During the loading and instantiation of the Wasm module, relevant error handling logic can be set to capture and handle potential errors. For example, if errors such as network request failures or module parsing errors are detected, retrying can be performed automatically, or a corresponding error message can be generated and sent to remind the user to manually retry.
[0064] Web Worker (browser worker thread interface) defines a set of APIs (Application Programming Interface) that allow new worker threads to be created outside the browser's main JavaScript thread and a piece of JavaScript script to be run in them, providing the ability to operate multi-threaded applications using JavaScript.
[0065] For example, after loading the Virtual Instruction Set Module into a browser, Worker scripts can be written using the browser's Virtual Instruction Set Module to perform file encryption and fragmentation. Worker scripts, or JavaScript scripts written for WebWorkers, can run in independent threads to process files in the background without blocking the main thread. Scripts written using the Virtual Instruction Set Module to encrypt and fragment the file to be uploaded can be processed in an independent thread, completing file encryption and fragmented upload without blocking the main thread. Web Workers can interact with the main thread through the `postMessage()` method and the `onmessage` event handler. The encryption Worker script can call the encryption algorithm in the Virtual Instruction Set Module to encrypt the file to be uploaded. After encryption, it can notify the main thread through the `postMessage()` method. The main thread can add fragmented upload Worker scripts and notify the Worker threads to perform work through the `onmessage` event. The Worker threads can then call the fragmentation algorithm in the Virtual Instruction Set Module to fragment and upload the encrypted file (encrypted file). Through the above implementation process, the efficient Wasm algorithm can be processed in a sub-thread of the browser, enabling seamless encryption and sliced uploads without blocking the main thread, thus meeting users' needs for uploading large files.
[0066] Reference Figure 6 This is a flowchart illustrating the steps of another embodiment of the file upload method of this application, including the following steps: Step 601: Compile the written file encryption and fragmentation algorithm files into a wasm module and import it into the browser; After the browser includes the wasm module, the browser's main thread can create a Worker script using new Worker(), which is used to handle encryption and chunked upload tasks using the high-performance algorithms in the wasm module.
[0067] Step 602: The browser obtains the file content through DOM elements; After obtaining the content of the file to be uploaded, the browser's main thread can use the postMessage() method to send the file data (or file fragments) to be uploaded to the Worker thread.
[0068] Step 603: Instantiate the module in the wasm file using JavaScript code, call the file encryption method, and output the encrypted file; Worker scripts can listen for messages from the main thread via the onmessage event. After receiving data for the file to be uploaded from the main thread, they can load and instantiate the wasm module.
[0069] Step 604: Create a web worker thread, use the sharding algorithm in the wasm file to shard the encrypted file, and upload the sharded file in parallel; Browsers can create web worker threads independent of the main thread. Then, the web worker thread uses the encryption and fragmentation algorithms in the wasm file to encrypt and fragment the file to be encrypted. After fragmentation, the worker can use postMessage() to return the encrypted and fragmented data to the browser's main thread. The main thread can receive the fragmented encrypted file returned by the worker through the onmessage event, and start multiple threads through the Web Worker to perform AJAX (Asynchronous JavaScript and XML) interactions, calling the upload interface to upload the data fragments to the server (server-side) in parallel.
[0070] Step 605: The server receives the fragmented files and merges them after the upload is complete. After merging, the files are decrypted according to the encryption rules.
[0071] After receiving the fragmented encrypted file, the server verifies it based on its hash value, filename, and sequence number. It then temporarily stores the received fragments in a designated server directory. The server records the upload progress of each fragment and monitors whether all fragments have been uploaded. If a missing fragment is detected, the server notifies the client to re-upload it. Once all fragments are uploaded, the server merges them according to their sequence numbers to generate a complete encrypted file and verifies its integrity. After successful integrity verification, the server uses a shared key equivalent to the client's to decrypt the file using the agreed-upon encryption scheme and saves the decrypted file to its final storage location. After successful file saving, the server deletes the temporary encrypted file and records its filename, size, storage path, and other metadata in the database, generating a download link. The server can also clear temporary fragments to free up storage space. Finally, it returns a successful upload response message to the client, which may include the file ID (identity document) and download address.
[0072] It should be noted that the file upload method provided in this application embodiment can be executed by a file upload device, or a control module within the file upload device for executing the file upload loading method. This application embodiment uses the execution of the file upload loading method by a file upload device as an example to illustrate the file upload method provided in this application embodiment.
[0073] Based on the above embodiments, this embodiment also provides a performance evaluation device that can be applied to electronic devices such as terminal devices and servers.
[0074] Reference Figure 7 This is a structural block diagram of an embodiment of a file upload device according to this application, applied to an electronic device. The electronic device provides a browser loaded with a virtual instruction set module, which may include the following modules: The "File to be uploaded" module is used to determine the file to be uploaded in response to the user's selection. The encryption module is used to call the encryption algorithm in the virtual instruction set module to encrypt the file to be uploaded, thereby obtaining an encrypted file; The fragmentation module is used to call the fragmentation algorithm in the virtual instruction set module to fragment the encrypted file, thereby obtaining multiple fragmented encrypted files; The upload module is used to upload the fragmented encrypted files sequentially.
[0075] The encryption module includes: The shared key acquisition submodule is used to acquire the shared key; An encryption key generation submodule is used to generate an encryption key based on the shared key; A round key generation submodule is used to generate multiple round keys based on the encryption key, wherein the number of round keys is determined according to the length of the encryption key; The encryption submodule is used to encrypt the file to be uploaded sequentially using the round key to obtain an encrypted file.
[0076] The encryption submodule is further used for: Generate a corresponding byte matrix based on the file to be uploaded; Perform byte substitution on the byte matrix; Perform row shifting on the byte matrix after byte replacement; Perform column obfuscation on the row-shifted byte matrix; The byte matrix after column obfuscation is XORed with the round key of the current round to generate a round encryption matrix; Determine the number of unused round keys; If the number of unused round keys is not 1, update the byte matrix according to the round encryption matrix, and return the byte replacement of the byte matrix; If there is only one unused round key, the round encryption matrix is byte-replaced; the byte-replaced round encryption matrix is row-shifted; the row-shifted round encryption matrix is XORed with the round key of the current round to generate an encrypted file.
[0077] The encryption module further includes: The key parameter and client private key acquisition submodule is used to obtain the key parameters and client private key; A client public key generation submodule is used to generate a client public key based on the key parameters and the client private key; The sending submodule is used to send the client's public key to the server. The receiving submodule is used to receive the server's public key sent by the server. The shared key generation submodule is used to generate a shared key based on the server public key, the client private key, and the key parameters.
[0078] The sharding module includes: The size information acquisition submodule is used to obtain the preset fragment size and the file size of the encrypted file; The fragment number determination submodule is used to determine the corresponding fragment number based on the fragment size and the file size of the encrypted file; The fragmented encrypted file generation submodule is used to generate corresponding fragmented encrypted files based on the number of fragments.
[0079] The segmented encrypted file generation submodule also includes: A creation unit is used to create a corresponding number of fragment files based on the number of fragments; An allocation unit is used to assign a corresponding sequence number to each of the fragment files; The writing unit is used to read byte data of the fragment size sequentially from the encrypted file, and write the read byte data into the fragment file according to the sequence number to generate a fragmented encrypted file.
[0080] The file upload device further includes: The source code acquisition module is used to acquire the source code of the encryption algorithm and the sharding algorithm; A conversion module is used to convert the source code into intermediate code; The optimization module is used to perform instruction replacement, loop adjustment, and memory management on the intermediate code to generate optimized intermediate code; The compilation module is used to compile the optimized intermediate code and generate a virtual instruction set file; A virtual instruction set module generation module is used to obtain the virtual instruction set module based on the virtual instruction set file.
[0081] The file upload device in this application embodiment can be a device, or a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. For example, mobile electronic devices can be mobile phones, tablets, laptops, PDAs, in-vehicle electronic devices, wearable devices, ultra-mobile personal computers (UMPCs), netbooks, or personal digital assistants (PDAs), etc., while non-mobile electronic devices can be servers, network attached storage (NAS), personal computers (PCs), televisions (TVs), ATMs, or self-service machines, etc. This application embodiment does not impose specific limitations.
[0082] The file upload device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit it.
[0083] The file upload device provided in this application embodiment can achieve...Figures 1 to 6 The various processes implemented by the file upload device in the method embodiment will not be described again here to avoid repetition.
[0084] This application provides a file upload device that, in response to a user's selection, determines the file to be uploaded, then calls a high-performance encryption algorithm provided in a virtual instruction set module to encrypt the file, resulting in an encrypted file. Next, it calls a high-performance fragmentation algorithm also provided in the virtual instruction set module to fragment the encrypted file, resulting in multiple fragmented encrypted files, which are then uploaded sequentially. Through this process, the virtual instruction set module can run high-performance fragmentation algorithms in a browser with good compatibility. It can also run high-performance encryption algorithms in other languages in the browser, solving the problem of browsers being unable to encrypt uploaded files. Uploading files through a browser with the virtual instruction set module allows the use of its encryption and fragmentation algorithms to encrypt and fragment the file, ensuring the security of fragmented file uploads, improving the efficiency of uploading large files, and enhancing the user experience. Furthermore, encrypting before fragmentation maximizes the security of the uploaded file and prevents the leakage of its original information.
[0085] Optionally, embodiments of this application also provide an electronic device, including a processor, a memory, and a program or instructions stored in the memory and executable on the processor. When the program or instructions are executed by the processor, they implement the various processes of the above-described file upload method embodiments and achieve the same technical effects. To avoid repetition, they will not be described again here.
[0086] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.
[0087] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described file upload method embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0088] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0089] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described file upload method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0090] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0091] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0092] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0093] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
Claims
1. A file uploading method characterized by, The method is applied to an electronic device providing a browser loaded with a virtual instruction set module, and the method comprises: In response to a selection operation of a user, a file to be uploaded is determined; An encryption algorithm in the virtual instruction set module is called to encrypt the file to be uploaded, to obtain an encrypted file; A fragmentation algorithm in the virtual instruction set module is called to fragment the encrypted file, to obtain a plurality of fragmented encrypted files; The fragmented encrypted files are sequentially uploaded.
2. The method of claim 1, wherein, The calling of the encryption algorithm in the virtual instruction set module to encrypt the file to be uploaded to obtain an encrypted file comprises: A shared key is obtained; An encryption key is generated according to the shared key; A plurality of round keys are generated according to the encryption key, the number of the round keys being determined according to the length of the encryption key; The file to be uploaded is sequentially encrypted using the round keys to obtain an encrypted file.
3. The method of claim 2, wherein, The sequential use of the round keys to encrypt the file to be uploaded to obtain an encrypted file comprises: A corresponding byte matrix is generated according to the file to be uploaded; The byte matrix is subjected to byte replacement; The byte-replaced byte matrix is subjected to row shifting; The row-shifted byte matrix is subjected to column confusion; The column-confused byte matrix is subjected to an exclusive or operation with the round key of the current round to generate a round-encrypted matrix; The number of unused round keys is determined; In a case where the number of unused round keys is not 1, the byte matrix is updated according to the round-encrypted matrix, and the byte matrix is subjected to byte replacement; In a case where the number of unused round keys is 1, the round-encrypted matrix is subjected to byte replacement, the byte-replaced round-encrypted matrix is subjected to row shifting, and the row-shifted round-encrypted matrix is subjected to an exclusive or operation with the round key of the current round to generate an encrypted file.
4. The method of claim 2, wherein, Before the shared key is obtained, the method comprises: A key parameter and a client private key are obtained; A client public key is generated according to the key parameter and the client private key; The client public key is sent to a server; A server public key sent by the server is received; A shared key is generated according to the server public key, the client private key and the key parameter.
5. The method of claim 1, wherein, The calling of the fragmentation algorithm in the virtual instruction set module to fragment the encrypted file to obtain a plurality of fragmented encrypted files comprises: A preset fragmentation size and a file size of the encrypted file are obtained; A corresponding number of fragments is determined according to the fragmentation size and the file size of the encrypted file; Corresponding fragmented encrypted files are generated according to the number of fragments.
6. The method of claim 5, wherein, The generation of the corresponding fragmented encrypted files according to the number of fragments comprises: A corresponding number of fragment files is created according to the number of fragments; Each of the fragment files is assigned a corresponding serial number; Byte data of the fragmentation size is sequentially read from the encrypted file, and the read byte data is written into the fragment file according to the serial number, to generate a fragmented encrypted file.
7. The method of claim 1, wherein, The method further comprises: Source code of the encryption algorithm and the fragmentation algorithm is obtained; The source code is converted into intermediate code; performing instruction replacement, loop adjustment and memory management on the intermediate code to generate optimized intermediate code; compiling the optimized intermediate code to generate a virtual instruction set file; obtaining the virtual instruction set module according to the virtual instruction set file.
8. A file uploading apparatus characterized by comprising: The application is applied to an electronic device which provides a browser loaded with a virtual instruction set module, and the device comprises: a to-be-uploaded file determination module configured to determine a to-be-uploaded file in response to a selection operation of a user; an encryption module configured to call an encryption algorithm in the virtual instruction set module to encrypt the to-be-uploaded file to obtain an encrypted file; a fragmentation module configured to call a fragmentation algorithm in the virtual instruction set module to fragment the encrypted file to obtain a plurality of fragmented encrypted files; an uploading module configured to sequentially upload the fragmented encrypted files.
9. An electronic device, comprising: The application further provides a computer readable storage medium, which stores a program or instruction, and the program or instruction is executed by a processor to implement the steps of the file uploading method.
10. A readable storage medium, characterized by, The application further provides a computer readable storage medium, which stores a program or instruction, and the program or instruction is executed by a processor to implement the steps of the file uploading method.