A file transmission method, file downloading method, server and client

By using the key exchange algorithm and signature generation algorithm during file transfer, dynamically generate shared keys and server signatures, the security problem of traditional symmetric encryption algorithms during key leakage is solved, and more efficient file transfer security is achieved.

CN119696933BActive Publication Date: 2025-05-09BEIJING SOHU NEW MOMENTUM INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510201973.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-02-24
Publication Date
2025-05-09
Estimated Expiration
2045-02-24

AI Technical Summary

Technical Problem

Traditional symmetric encryption algorithms threaten file security when key leaks, making it difficult to effectively protect the security of sensitive data during transmission and storage.

Method used

The preset key exchange algorithm and asymmetric encryption algorithm are used to ensure the security during file transfer by generating dynamic shared keys and server signatures. The specific steps include receiving client requests, generating random numbers, generating shared keys using key exchange algorithms, generating server signatures using signature generation algorithms, and sending relevant information to the client.

Benefits of technology

Through dynamically generated shared secrets and signatures, the security during file transfer is improved, and files are prevented from being intercepted or tampered during transmission, ensuring the integrity and authenticity of the data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119696933B_ABST
    Figure CN119696933B_ABST
Patent Text Reader

Abstract

The present application discloses a file transmission method, a file download method, a server and a client, and relates to the field of computer technology. After receiving a file request sent by a client, the server generates a random number, generates a shared key based on the random number, a server private key and a client public key using a preset key exchange algorithm, generates a server signature based on parameters such as the random number and the shared key using a preset signature generation algorithm, and sends the server public key, the random number, the server signature and the file parameters and download link of the target file to the client, so that the client downloads the target file from the download link and uses it after verifying the server signature. Since a dynamic shared key and a dynamic server signature are generated according to a random number during the file transmission and file download process, the shared key and the server signature are difficult to be cracked, preventing the file from being intercepted or tampered with during the transmission process, thereby improving the security of file transmission.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a file transmission method, a file downloading method, a server and a client. Background Art

[0002] With the rapid development of information technology, more and more sensitive data is transmitted over the Internet and stored locally and in the cloud. The secure transmission and storage of data has become particularly important.

[0003] In the file storage solution based on the traditional symmetric encryption algorithm, the files are encrypted by using the symmetric encryption algorithm (such as AES). However, the symmetric encryption algorithm relies on a key to encrypt and decrypt the files. The key leakage may cause the security of the encrypted files to be seriously threatened. Summary of the invention

[0004] In view of the above problems, the present application provides a file transmission method, a file downloading method, a server and a client to achieve the purpose of improving the security of file transmission and downloading. The specific scheme is as follows:

[0005] A first aspect of the present application provides a file transmission method, which is applied to a server. The file transmission method includes:

[0006] Receive a file request sent by a client and carrying a file identifier and a client public key, and determine a target file requested by the client according to the file identifier;

[0007] generating a first random number;

[0008] Generate a first shared key based on the first random number, the server private key and the client public key using a preset key exchange algorithm;

[0009] Encrypt the first random number using a preset asymmetric encryption algorithm and the client public key to generate a first encrypted random number;

[0010] Generate a server signature based on the file parameters of the target file, the first random number, the first encrypted random number, and the first shared key using a preset signature generation algorithm;

[0011] The server public key, the first encrypted random number, the server signature, and the file parameters and download link of the target file are sent to the client, so that the client downloads the target file according to the download link.

[0012] In a possible implementation, the using a preset key exchange algorithm to generate a first shared key based on the first random number, a server private key, and the client public key includes:

[0013] Selecting a first elliptic curve from a preset elliptic curve list according to the first random number;

[0014] The server private key and the client public key are encrypted using the ECDH algorithm based on the first elliptic curve to generate the first shared key.

[0015] In a possible implementation, the using a preset signature generation algorithm to generate a server signature based on the file parameters of the target file, the first random number, the first encrypted random number, and the first shared key includes:

[0016] Selecting a first hash algorithm from a preset hash algorithm list according to the first random number;

[0017] The server signature is generated based on the file parameters of the target file, the first random number, the first encrypted random number, the first hash algorithm and the first shared key using a hash-based message authentication code algorithm.

[0018] In a possible implementation, the file transmission method further includes:

[0019] Receiving the target file, the first verification signature and the first encrypted random number sent by the client;

[0020] Determining whether the server signature is consistent with the first verification signature;

[0021] If they are consistent, decrypt the first encrypted random number using the preset asymmetric encryption algorithm and the server private key to obtain a verification random number;

[0022] Generate a verification shared key based on the verification random number, the server private key and the client public key using the preset key exchange algorithm;

[0023] Generate a verification server signature based on the file parameters of the target file, the verification random number, the first encrypted random number and the verification shared key using the preset signature generation algorithm;

[0024] The verification server signature is sent to the client.

[0025] In a possible implementation, before receiving the file request sent by the client and carrying the file identifier and the client public key, the file transmission method further includes:

[0026] Receiving the original compressed package of the target file uploaded by the client, and generating a file identifier and creation time of the target file;

[0027] generating a second random number;

[0028] Generate a second shared key based on the second random number, the server private key and the client public key using the preset key exchange algorithm;

[0029] Generate a compressed package password based on the file identifier and creation time of the target file, the second random number and the second shared key using the preset signature generation algorithm;

[0030] Decompressing the original compressed package, and encrypting and compressing the decompressed file using the compressed package password to obtain the target file;

[0031] The target file is stored in a preset location, and a download link for the target file is generated.

[0032] A second aspect of the present application provides a file downloading method, which is applied to a client, and the file downloading method includes:

[0033] Send a file request with the file identifier and the client public key to the server;

[0034] Receiving a server public key, a first encrypted random number, a server signature, and file parameters and a download link of a target file sent by the server;

[0035] Download the target file from the download link;

[0036] Decrypting the first encrypted random number using a preset asymmetric encryption algorithm and a client private key to obtain a first random number;

[0037] Generate a first shared key based on the first random number, the server public key and the client private key using a preset key exchange algorithm;

[0038] Generate a first verification signature based on the file parameters of the target file, the first random number, the first encrypted random number, and the first shared key using a preset signature generation algorithm;

[0039] If the first verification signature is consistent with the server signature, the target file is determined to be safe.

[0040] In a possible implementation, if the first verification signature is consistent with the server signature, the file download method further includes:

[0041] Sending the target file, the first verification signature, and the first encrypted random number to the server;

[0042] Receiving a verification server signature sent by the server;

[0043] Determining whether the verification server signature is consistent with the first verification signature;

[0044] If they are consistent, it is determined that the target file is safe;

[0045] If they are inconsistent, the target file is downloaded again from the download link.

[0046] In a possible implementation, after determining that the target file is safe, the file downloading method further includes:

[0047] Receiving a second encrypted random number sent by the server;

[0048] Decrypt the second encrypted random number using the preset asymmetric encryption algorithm and the client private key to obtain a second random number;

[0049] Generate a second shared key based on the second random number, the server public key and the client private key using the preset key exchange algorithm;

[0050] Generate a compressed package password using the preset signature generation algorithm based on the file identifier and creation time in the file parameters of the target file, the second random number and the second shared key;

[0051] The target file is decrypted and decompressed using the compressed package password.

[0052] In a possible implementation, after decrypting and decompressing the target file using the compressed package password, the file downloading method further includes:

[0053] The target file and the decompressed file of the target file are stored locally to obtain the compressed package file path and the file path of the target file;

[0054] The file parameters of the target file, the first encrypted random number, and the server signature are stored locally.

[0055] In a possible implementation, the file downloading method further includes:

[0056] Querying the file parameters of the target file, the first encrypted random number, the server signature, the file path and the compressed package file path in local storage according to the file identifier of the target file;

[0057] Acquire the locally stored target file from the compressed package file path;

[0058] Decrypting the first encrypted random number using the preset asymmetric encryption algorithm and the server public key to obtain the first random number;

[0059] Generate the first shared key based on the first random number, the server public key and the client private key using the preset key exchange algorithm;

[0060] Generate a second verification signature based on the file parameters of the target file, the first random number, the first encrypted random number, and the first shared key using the preset signature generation algorithm;

[0061] Determining whether the second verification signature is consistent with the locally stored server signature;

[0062] If they are consistent, the decompressed file of the target file is obtained from the file path.

[0063] A third aspect of the present application provides a server, comprising at least one processor and a memory connected to the processor, wherein:

[0064] The memory is used to store computer programs;

[0065] The processor is used to execute the computer program so that the server can implement the file transmission method of the first aspect or any implementation manner of the first aspect.

[0066] A fourth aspect of the present application provides a client, comprising at least one processor and a memory connected to the processor, wherein:

[0067] The memory is used to store computer programs;

[0068] The processor is used to execute the computer program so that the client can implement the file downloading method of the first aspect or any implementation manner of the first aspect.

[0069] By means of the above technical scheme, the present application provides a file transmission method, a file download method, a server and a client. After receiving a file request sent by a client, the server generates a random number, generates a shared key based on the random number, the server private key and the client public key using a preset key exchange algorithm, generates a server signature based on parameters such as the random number and the shared key using a preset signature generation algorithm, and sends the server public key, the random number, the server signature and the file parameters and download link of the target file to the client, so that the client downloads the target file from the download link and uses it after verifying the server signature. Since a dynamic shared key and a dynamic server signature are generated according to a random number during the file transmission and file download process, the shared key and the server signature are difficult to be cracked, preventing the file from being intercepted or tampered with during the transmission process, thereby improving the security of file transmission. BRIEF DESCRIPTION OF THE DRAWINGS

[0070] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.

[0071] Figure 1 A flowchart of a file transmission method provided in an embodiment of the present application;

[0072] Figure 2 A flowchart of a file downloading method provided in an embodiment of the present application;

[0073] Figure 3 A flowchart of a file uploading method provided in an embodiment of the present application;

[0074] Figure 4 A flowchart of a file decryption method provided in an embodiment of the present application;

[0075] Figure 5 A flowchart of a file local application method provided in an embodiment of the present application. DETAILED DESCRIPTION

[0076] The following describes the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation method section of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.

[0077] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0078] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.

[0079] The present application embodiment provides a file transmission method, which is applied to a server. The file transmission method of the present application embodiment is described in detail below with reference to the accompanying drawings.

[0080] Reference Figure 1 , Figure 1 A flowchart of a file transmission method provided in an embodiment of the present application is shown as follows: Figure 1 As shown, a file transmission method provided in an embodiment of the present application is applied to a server and may include steps 101 to 106, and these steps are described in detail below.

[0081] 101: receiving a file request sent by a client and carrying a file identifier and a client public key, and determining a target file requested by the client according to the file identifier;

[0082] If the client wants to download the target file in the server, it needs to send a file request carrying a file identifier and a client public key to the server, where the file identifier is the unique identifier of the file stored in the server and the client public key represents the identity of the client.

[0083] 102: Generate a first random number;

[0084] Exemplarily, the first random number is generated using a strong random number generator, and the strong random number generator may be a hardware random number generator.

[0085] Exemplarily, the first random number is generated using a pseudo-random number generator, and the pseudo-random number generator may be a software random number generator.

[0086] 103: Generate a first shared key based on the first random number, the server private key and the client public key using a preset key exchange algorithm;

[0087] The preset key exchange algorithm may be a DH (Diffie-Hellman) algorithm, an ECDH (Elliptic Curve Diffie-Hellman Key Exchange) algorithm, or the like.

[0088] The preset key exchange algorithm allows the server and client to each use their own private key and the other party's public key to generate the same shared key, which cannot be derived through a man-in-the-middle attack, effectively ensuring communication security.

[0089] By using the first random number as a part for generating the shared key, the unpredictability and security of the first shared key are increased.

[0090] 104: Encrypt the first random number using a preset asymmetric encryption algorithm and a client public key to generate a first encrypted random number;

[0091] The preset asymmetric encryption algorithm may be an RSA (Rivest-Shamir-Adleman) algorithm, an ECC (Elliptic Curve Cryptography) algorithm, or the like.

[0092] Use an asymmetric encryption algorithm to encrypt data with a public key and decrypt data with a private key. In this way, even if the encrypted data is intercepted during transmission, only the corresponding private key can decrypt it, which improves the security of data transmission.

[0093] 105: Generate a server signature using a preset signature generation algorithm based on the file parameters of the target file, the first random number, the first encrypted random number, and the first shared key;

[0094] The preset signature generation algorithm can be an HMAC (Hash-based Message Authentication Code) algorithm, a random salt hash algorithm, etc.

[0095] The file parameters include at least: file identification, creation time, and file parameters may also include file length, file hash value, etc.

[0096] By generating a server signature, the server signature is the data identifier of the target file, which is used to verify the integrity of the target file and the identity of the server, ensuring the integrity and authenticity of the data during transmission and preventing data forgery and replay attacks.

[0097] 106: Send the server public key, the first encrypted random number, the server signature, and the file parameters and download link of the target file to the client, so that the client downloads the target file according to the download link.

[0098] The server sends the server public key, the first encrypted random number, the server signature and the file parameters of the target file to the client, so that the client verifies the authenticity of the data according to the information and downloads the target file according to the download link.

[0099] The present embodiment discloses a file transmission method, in which after receiving a file request sent by a client, the server generates a random number, generates a shared key based on the random number, the server private key and the client public key using a preset key exchange algorithm, generates a server signature based on parameters such as the random number and the shared key using a preset signature generation algorithm, and sends the server public key, the random number, the server signature, and the file parameters and download link of the target file to the client, so that the client downloads the target file from the download link and uses it after verifying the server signature. Since the dynamic shared key and the dynamic server signature are generated according to the random number during the file transmission and file download process, the shared key and the server signature are difficult to be cracked, which prevents the file from being intercepted or tampered with during the transmission process, thereby improving the security of file transmission.

[0100] In a possible implementation, the preset key exchange algorithm is the ECDH algorithm, and step 103 in the above embodiment specifically includes steps 1031-1032:

[0101] 1031: Select a first elliptic curve from a preset elliptic curve list according to the first random number;

[0102] Random represents the first random number, curveList.count represents the total number of elliptic curves in the preset elliptic curve list, and index1 represents the index number of the first elliptic curve in the preset elliptic curve list, then index1= random %curveList.count.

[0103] According to index1, the first elliptic curve curveName = curveList[index] can be determined.

[0104] 1032: Use the ECDH algorithm to encrypt the server private key and the client public key based on the first elliptic curve to generate a first shared key.

[0105] With ser.privateKey representing the server private key, cli.publishKey representing the client public key, and curveName representing the first elliptic curve, the calculation formula for the first shared key is as follows:

[0106] sharekey = ECDH(ser.privateKey, cli.publishKey, curveName).

[0107] A first elliptic curve is selected from a preset elliptic curve list according to a first random number, and then an ECDH algorithm is used to encrypt a server private key and a client public key based on the first elliptic curve to generate a first shared key, making the first shared key difficult to predict and improving the security of the first shared key.

[0108] In a possible implementation, the preset signature generation algorithm is a hash-based message authentication code algorithm, and step 105 in the above embodiment specifically includes steps 1051-1052:

[0109] 1051: Select a first hash algorithm from a preset hash algorithm list according to the first random number;

[0110] Let random represent the first random number, hashlist.count represent the total number of hash algorithms in the preset hash algorithm list, and index2 represent the index number of the first hash algorithm in the preset hash algorithm list, then index2 = random % hashlist.count.

[0111] According to index2, the first hash algorithm hashName = hashlist[index] can be determined.

[0112] 1052: Generate a server signature using a hash-based message authentication code algorithm based on file parameters of the target file, a first random number, a first encrypted random number, a first hash algorithm, and a first shared key.

[0113] Exemplarily, the calculation formula of the server signature is as follows:

[0114] sig1 = HMAC(id + createTime + fileLength + hash + enCodeRandom1 +random1, hashName, sharekey1)

[0115] Among them, id, createTime, fileLength, and hash represent the file identifier, creation time, file length, and hash value of the target file, respectively; random1 represents the first random number; enCodeRandom1 represents the first encrypted random number; hashName represents the first hash algorithm; and sharekey1 represents the first shared key.

[0116] The present application also provides a method for downloading a file, which is applied to a client. Figure 2 , a file downloading method disclosed in this embodiment includes the following steps 201-207:

[0117] 201: Send a file request carrying the file identifier and the client public key to the server;

[0118] The client sends a file request carrying the file identifier and the client public key to the server to download the target file corresponding to the file identifier.

[0119] 202: receiving a server public key, a first encrypted random number, a server signature, and file parameters and a download link of a target file sent by a server;

[0120] When the server receives the file request sent by the client, it executes the following Figure 1 The file transmission method shown generates a first encrypted random number, a server signature and a download link.

[0121] 203: Download the target file from the download link;

[0122] 204: Decrypt the first encrypted random number using a preset asymmetric encryption algorithm and a client private key to obtain a first random number;

[0123] The server uses a preset asymmetric encryption algorithm and the client public key to encrypt the first random number to generate a first encrypted random number. Since the preset asymmetric encryption algorithm used by the client is consistent with the preset asymmetric encryption algorithm used by the server, the client can obtain the first random number by decrypting the first encrypted random number using the preset asymmetric encryption algorithm and the client private key.

[0124] 205: Generate a first shared key based on the first random number, the server public key and the client private key using a preset key exchange algorithm;

[0125] The preset key exchange algorithm used by the client is consistent with the preset key exchange algorithm used by the server. Therefore, if the information sent by the server has not been tampered with, the client uses the preset key exchange algorithm, and the first shared key generated based on the first random number, the server public key and the client private key should be consistent with the first shared key generated by the server.

[0126] 206: Generate a first verification signature based on the file parameters of the target file, the first random number, the first encrypted random number, and the first shared key using a preset signature generation algorithm;

[0127] The preset signature generation algorithm used by the client is consistent with the preset signature generation algorithm used by the server.

[0128] 207: If the first verification signature is consistent with the server signature, it is determined that the target file is safe.

[0129] If the information sent by the server has not been tampered with, the first shared key and the first verification signature generated by the client should be consistent with the first shared key and the server signature generated by the server. If the first verification signature is consistent with the server signature, the target file is determined to be safe.

[0130] In a possible implementation, the preset key exchange algorithms used by the server and the client are both ECDH algorithms. In the above embodiment, step 205 specifically includes the following steps 2051-2052:

[0131] 2051: Select a first elliptic curve from a preset elliptic curve list according to the first random number;

[0132] 2052: Use the ECDH algorithm to encrypt the server public key and the client private key based on the first elliptic curve to generate a first shared key.

[0133] The preset elliptic curve lists maintained by the server and the client are consistent, so the first elliptic curves selected from the preset elliptic curve list according to the same first random number are the same, and thus the first shared keys generated based on the first elliptic curve are also the same.

[0134] In a possible implementation, the preset signature generation algorithms used by the server and the client are both hash-based message authentication code algorithms. In the above embodiment, step 206 specifically includes the following steps 2061-2062:

[0135] 2061: Select a first hash algorithm from a preset hash algorithm list according to the first random number;

[0136] 2062: Generate a first verification signature based on the file parameters of the target file, a first random number, a first encrypted random number, a first hash algorithm and a first shared key using a hash-based message authentication code algorithm.

[0137] The preset hash algorithm lists maintained by the server and the client are consistent. Therefore, the first hash algorithm selected from the preset hash algorithm list according to the same first random number is the same, and thus the first verification signature generated based on parameters such as the first random number, the first hash algorithm and the first shared key is also consistent with the server signature.

[0138] Furthermore, in order to verify whether the target file has been tampered with during the transmission process, after downloading the target file from the download link, the following steps A1-A4 are also included:

[0139] A1: Calculate the hash value of the target file;

[0140] A2: Determine whether the hash value of the target file is consistent with the hash value in the file parameter of the target file;

[0141] A3: If they are consistent, go to step 204;

[0142] A4: If they are inconsistent, re-download the target file from the download link.

[0143] The hash algorithm used by the server to calculate the hash value of the target file is consistent with the hash algorithm used by the client to calculate the hash value of the target file (for example, both use the MD5 algorithm). Therefore, if the information sent by the server has not been tampered with, the hash value calculated by the client is consistent with the hash value in the file parameters of the target file. If the hash value calculated by the client is inconsistent with the hash value in the file parameters of the target file, it means that the information sent by the server may have been tampered with and the target file needs to be downloaded again.

[0144] In a possible implementation, if the first verification signature generated by the client is consistent with the server signature, the above file download method further includes the following steps B1-B5:

[0145] B1: Send the target file, the first verification signature and the first encrypted random number to the server;

[0146] B2: Receive the verification server signature sent by the server;

[0147] B3: Determine whether the verification server signature is consistent with the first verification signature;

[0148] B4: If they are consistent, it is determined that the target file is safe;

[0149] B5: If they are inconsistent, download the target file from the download link again.

[0150] The client sends the target file, the first verification signature and the first encrypted random number to the server, and the server verifies the first verification signature to verify whether the data has been tampered with during transmission. The client then verifies the verification server signature sent by the server again to further confirm the integrity of the data and the authenticity of the server.

[0151] Correspondingly, the file transmission method executed by the server also includes the following steps C1-C6:

[0152] C1: receiving the target file, the first verification signature and the first encrypted random number sent by the client;

[0153] C2: Determine whether the server signature is consistent with the first verification signature;

[0154] The server signature is Figure 1 The server signature generated by the file transfer method shown.

[0155] C3: If they are consistent, use the preset asymmetric encryption algorithm and the server private key to decrypt the first encrypted random number to obtain a verification random number;

[0156] If they are inconsistent, it means that the data sent by the client has been tampered with, and the server resends the server public key, the first encrypted random number, the server signature, and the file parameters and download link of the target file to the client.

[0157] If they are consistent, it means that the data sent by the client has not been tampered with. Since the preset asymmetric encryption algorithms used by the client and the server are consistent, the server uses the preset asymmetric encryption algorithm and the server private key to decrypt the first encrypted random number to obtain a verification random number consistent with the first random number.

[0158] C4: Use the preset key exchange algorithm to generate a verification shared key based on the verification random number, the server private key and the client public key;

[0159] Since the verification random number is consistent with the first random number, and the preset key exchange algorithms used by the client and the server are consistent, the verification shared key generated by the server is consistent with the first shared key.

[0160] C5: Generate a verification server signature based on the file parameters of the target file, the verification random number, the first encrypted random number and the verification shared key using a preset signature generation algorithm;

[0161] Since the preset signature algorithm used by the client and the server is consistent, the verification random number is consistent with the first random number, and other parameters used to generate the signature are also consistent, the verification server signature generated by the server is consistent with the server signature.

[0162] C6: Send the verification server signature to the client.

[0163] In a possible implementation, in order to ensure the security of target file transmission, the target file is an encrypted compressed package file, which is obtained by encrypting and compressing the file uploaded by the client by the server. The embodiment of the present application discloses a file uploading method, which is applied to the server. Figure 3 , the file upload method specifically includes the following steps 301-306:

[0164] 301: receiving the original compressed package of the target file uploaded by the client, and generating the file identifier and creation time of the target file;

[0165] Exemplarily, the administrator uploads the original compressed package of the target file to the server through the client interface.

[0166] The client uses the HTTPS protocol to ensure that the file will not be intercepted or tampered with during the upload process. The client that uploads the target file and the client that downloads the target file may be the same client or may not be the same client.

[0167] The file identifier represents the unique identifier of the target file. The creation time of the target file is the timestamp of the target file. The timestamp ensures that the upload time of the target file is recorded to facilitate subsequent verification.

[0168] 302: Generate a second random number;

[0169] The second random number is generated using a strong random number generator or a pseudo-random number generator.

[0170] 303: Generate a second shared key based on the second random number, the server private key and the client public key using a preset key exchange algorithm;

[0171] The preset key exchange algorithm allows the server and client to each use their own private key and the other party's public key to generate the same shared key, which cannot be derived through a man-in-the-middle attack, effectively ensuring communication security.

[0172] By using the second random number as a part for generating the shared key, the unpredictability and security of the second shared key are increased.

[0173] 304: Generate a compressed package password based on the file identifier and creation time of the target file, the second random number, and the second shared key using a preset signature generation algorithm;

[0174] By using the second random number as a part for generating the compressed package password, the unpredictability and security of the compressed package password are increased.

[0175] 305: decompress the original compressed package, and encrypt and compress the decompressed file using the compressed package password to obtain the target file;

[0176] Decompress the original compressed package uploaded by the client, and recompress the file using the generated compressed package password to ensure its security.

[0177] 306: Store the target file in a preset location and generate a download link for the target file.

[0178] The server generates a download link for the target file for use by the client.

[0179] In a possible implementation, the preset key exchange algorithm is the ECDH algorithm, and step 303 in the above embodiment specifically includes steps 3031-3032:

[0180] 3031: Select a second elliptic curve from a preset elliptic curve list according to a second random number;

[0181] 3032: Use the ECDH algorithm to encrypt the server private key and the client public key based on the second elliptic curve to generate a second shared key.

[0182] The method of selecting the second elliptic curve from the preset elliptic curve list according to the second random number is the same as the method of selecting the first elliptic curve from the preset elliptic curve list according to the first random number.

[0183] A second elliptic curve is selected from a preset elliptic curve list according to a second random number, and the server private key and the client public key are encrypted based on the second elliptic curve using the ECDH algorithm to generate a second shared key, making the second shared key difficult to predict and improving the security of the second shared key.

[0184] In a possible implementation, the preset signature generation algorithm is a hash-based message authentication code algorithm. Step 304 in the above embodiment specifically includes steps 3041-3042:

[0185] 3041: Select a second hash algorithm from a preset hash algorithm list according to a second random number;

[0186] The method of selecting the second hash algorithm from the preset hash algorithm list according to the second random number is the same as the method of selecting the first hash algorithm from the preset hash algorithm list according to the first random number.

[0187] 3042: Generate a compressed package password using a hash-based message authentication code algorithm based on the file identifier and creation time of the target file, a second random number, a second hash algorithm and a second shared key.

[0188] Exemplarily, the calculation formula of the compressed package password is as follows:

[0189] zippwd = HMAC(id + createTime + random2, hashName2, sharekey2)

[0190] Among them, id and createTime respectively represent the file identifier and creation time of the target file, random2 represents the second random number, hashName2 represents the second hash algorithm, and sharekey2 represents the second shared key.

[0191] In a possible implementation, after the download link of the target file is generated, the file parameters of the target file, the second encrypted random number, the compressed package password and the download link are stored in a database for subsequent verification and audit. The file parameters of the target file include at least: file identification, creation time, and the file parameters may also include file length, file hash value, etc. The second encrypted random number is obtained by encrypting the second random number using a preset asymmetric encryption algorithm and a client public key.

[0192] Correspondingly, after the client downloads the target file, if it wants to use the target file, it needs to decrypt the target file. Figure 4 The present embodiment discloses a file decryption method, which is applied to a client and specifically includes the following steps 401-405:

[0193] 401: receiving a second encrypted random number sent by the server;

[0194] The second encrypted random number can be sent to the client together with the download link and other data of the target file when the client requests the target file from the server, or it can be sent to the client together with the first verification signature and other data when the client sends the first verification signature to the server to request the server to verify the signature. This application does not make specific limitations.

[0195] 402: Decrypt the second encrypted random number using a preset asymmetric encryption algorithm and a client private key to obtain a second random number;

[0196] Since the asymmetric encryption algorithm used by the client and the server is the same, if the second encrypted random number received by the client has not been tampered with, the second random number obtained by the client using the preset asymmetric encryption algorithm and the client private key to decrypt the second encrypted random number is consistent with the second random number generated by the server for the compressed package password.

[0197] 403: Generate a second shared key based on the second random number, the server public key and the client private key using a preset key exchange algorithm;

[0198] Since the preset key exchange algorithm used by the client and the server is consistent, if the second random number obtained by the above decryption has not been tampered with, the second shared key generated by the client is consistent with the second shared key generated by the server.

[0199] 404: Generate a compressed package password using a preset signature generation algorithm based on the file identifier and creation time in the file parameters of the target file, the second random number, and the second shared key;

[0200] Similarly, if the second encrypted random number is not tampered with during transmission, step 404 is the same as the compressed package password generated in step 304 in the above embodiment.

[0201] 405: Use the compressed package password to decrypt and decompress the target file.

[0202] Step 405 is the reverse process of step 305 in the above embodiment, and will not be described in detail here.

[0203] In one possible implementation, the target file and the decompressed file of the target file are stored locally to obtain the compressed package file path zippath and file path filePath of the target file, and then the file parameters, the first encrypted random number, and the server signature of the target file are stored locally to facilitate subsequent verification and auditing of the target file.

[0204] After the target file is stored locally, in order to ensure the integrity and security of the file when it is stored locally, this embodiment provides a file local application method, which is applied to the client. Figure 5 The local application method of the file specifically includes the following steps 501-508:

[0205] 501: storing locally the file parameters of the query target file, the first encrypted random number, the server signature, the file path and the compressed file path according to the file identifier of the target file;

[0206] The client queries the locally stored files and information such as file parameters through the file identifier.

[0207] It should be noted that if the target file cannot be found locally, the target file is downloaded again from the download link of the target file.

[0208] 502: Get the locally stored target file from the compressed file path;

[0209] Get the locally stored target file from the compressed file path, and prepare for verification and decompression.

[0210] 503: Decrypt the first encrypted random number using a preset asymmetric encryption algorithm and a server public key to obtain a first random number;

[0211] The preset asymmetric encryption algorithm used by the client and the server is consistent. If the locally stored first encrypted random number has not been tampered with, the first random number obtained by the client decrypting the first encrypted random number using the preset asymmetric encryption algorithm and the server public key has not been tampered with.

[0212] 504: Generate a first shared key based on the first random number, the server public key and the client private key using a preset key exchange algorithm;

[0213] The preset key exchange algorithm used by the client is consistent with the preset key exchange algorithm used by the server. Therefore, if the first encrypted random number stored locally has not been tampered with, the client uses the preset key exchange algorithm, and the first shared key generated based on the first random number, the server public key and the client private key should be consistent with the first shared key generated by the server.

[0214] 505: Generate a second verification signature based on the file parameters of the target file, the first random number, the first encrypted random number, and the first shared key using a preset signature generation algorithm;

[0215] 506: Determine whether the second verification signature is consistent with the locally stored server signature;

[0216] If they are consistent, execute 507: obtain the decompressed file of the target file from the file path;

[0217] If they are inconsistent, execute 508: download the target file from the download link again.

[0218] The preset signature generation algorithm used by the client is consistent with the preset signature generation algorithm used by the server. If the first encrypted random number stored locally has not been tampered with, the first encrypted random number is decrypted to obtain the first random number and the first shared key generated based on the first random number is the same as the first random number and the first shared key on the server. The client uses the preset signature generation algorithm to generate a second verification signature based on the file parameters of the target file, the first random number, the first encrypted random number and the first shared key, which is consistent with the server signature generated by the server. On this basis, if the second verification signature is consistent with the locally stored server signature, the integrity and authenticity of the target file are ensured, and the client can obtain the decompressed file of the target file from the file path. If the second verification signature is inconsistent with the locally stored server signature, the locally stored target file may have been tampered with, and the target file needs to be downloaded again from the download link.

[0219] In a possible implementation, after obtaining the locally stored target file from the compressed file path in step 502 of the above embodiment, the hash value of the target file can also be calculated, and it can be determined whether the hash value of the target file is consistent with the hash value in the file parameters of the locally stored target file. The hash algorithm used by the client to calculate the hash value of the target file is consistent with the hash algorithm used by the server to calculate the hash value of the target file (for example, both use the MD5 algorithm). Therefore, if the locally stored target file has not been tampered with, the hash value calculated by the client is consistent with the hash value in the file parameters of the target file. If the hash value calculated by the client is inconsistent with the hash value in the file parameters of the target file, it means that the locally stored target file may have been tampered with and needs to be downloaded again.

[0220] In a possible implementation, after step 504 in the above embodiment: using a preset key exchange algorithm to generate a first shared key based on a first random number, a server public key, and a client private key, the following steps D1-D5 may be performed:

[0221] D1: Use the first shared key to decrypt the encrypted hash value in the file parameter of the target file to obtain the original hash value;

[0222] It should be noted that the encrypted hash value in the file parameters of the target file is obtained by the server using a preset symmetric encryption algorithm to encrypt the hash value of the target file based on the first shared key to ensure the security of the hash value of the target file. The preset symmetric encryption algorithm can be an AES (Advanced Encryption Standard) symmetric encryption algorithm.

[0223] The client uses a preset symmetric encryption algorithm to decrypt the encrypted hash value in the file parameters of the target file based on the first shared key to obtain the original hash value for verification

[0224] D2: Calculate the hash value of the target file;

[0225] The hash algorithm used by the client to calculate the hash value of the target file is consistent with the hash algorithm used by the server to calculate the hash value of the target file (for example, both use the MD5 algorithm).

[0226] D3: Determine whether the hash value of the target file is consistent with the original hash value;

[0227] If they are consistent, execute step 505;

[0228] If they are inconsistent, execute step D4: re-download the target file from the download link.

[0229] If the locally stored target file has not been tampered with, the hash value calculated by the client is consistent with the hash value in the file parameters of the target file. If the hash value calculated by the client is inconsistent with the hash value in the file parameters of the target file, it means that the locally stored target file may have been tampered with and needs to be downloaded again.

[0230] During the file transfer process, this application adopts a multi-level encryption mechanism. First, the server generates a random number and encrypts the random number using a preset asymmetric encryption algorithm and the client's public key to ensure the security of the random number during transmission. Subsequently, using a preset key exchange algorithm, the server and the client generate a shared key based on the first random number, their respective private keys, and the other party's public key, thereby ensuring that both parties can securely exchange encrypted information.

[0231] During the upload, download, and storage of files, this application uses a preset signature generation algorithm, such as the HMAC (Hash-based Message Authentication Code) algorithm, to generate and verify the signature of the target file. When the file is uploaded, the server generates a signature and stores it with the file. After downloading the file, the client calculates the hash value of the file and verifies the signature to ensure that the file has not been tampered with.

[0232] The present application also provides a method for dynamically generating a compressed package password based on a shared key and a random number. The compressed package password is generated by the server based on the unique identifier of the file, the creation time and the random number, through a preset signature generation algorithm, such as the HMAC algorithm. This method ensures that a different password is used for each file transfer, effectively preventing the risk of password leakage and reuse.

[0233] This application can also use TLS / SSL protocol to encrypt the transmission channel to ensure that the data is protected from middleman attacks during transmission. Through digital signature and HMAC verification technology, the server and client can mutually verify the integrity and authenticity of the data, further enhancing the security of transmission.

[0234] After the file is downloaded and stored on the client, it is strictly access-controlled and encrypted. The file hash value and signature storage and verification mechanism ensure that the file will not be tampered with when stored locally. If necessary, the file can also be encrypted to prevent unauthorized access.

[0235] To summarize, this application fundamentally solves the security issues of files during transmission and local storage by comprehensively applying advanced encryption technology, key exchange algorithm, digital signature and verification mechanism, and provides an efficient and secure solution to ensure the integrity and security of sensitive data.

[0236] The embodiment of the present application also provides a server, including at least one processor and a memory connected to the processor, wherein:

[0237] The memory is used to store computer programs;

[0238] The processor is used to execute a computer program so that the server can implement any file transfer method provided in the embodiments of the present application.

[0239] The embodiment of the present application also provides a client, including at least one processor and a memory connected to the processor, wherein:

[0240] The memory is used to store computer programs;

[0241] The processor is used to execute a computer program so that the client can implement any file downloading method provided in the embodiments of the present application.

[0242] An embodiment of the present application also provides a computer program product including computer-readable instructions. When the computer-readable instructions are executed on a server, the server implements any file transfer method provided in the embodiment of the present application.

[0243] An embodiment of the present application also provides a computer program product including computer-readable instructions. When the computer-readable instructions are executed on a client, the client implements any file downloading method provided in the embodiment of the present application.

[0244] A computer-readable storage medium is also provided in an embodiment of the present application. The storage medium carries one or more computer programs. When the one or more computer programs are executed by a server, the server can implement any file transfer method provided in an embodiment of the present application.

[0245] A computer-readable storage medium is also provided in an embodiment of the present application. The storage medium carries one or more computer programs. When the one or more computer programs are executed by a client, the client can implement any file downloading method provided in an embodiment of the present application.

[0246] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a magnetic disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0247] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0248] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.

Claims

1. A file transmission method, characterized in that: Applied to a server, the file transmission method comprises: Receive a file request sent by a client and carrying a file identifier and a client public key, and determine a target file requested by the client according to the file identifier; generating a first random number; Generate a first shared key based on the first random number, the server private key and the client public key using a preset key exchange algorithm; Encrypt the first random number using a preset asymmetric encryption algorithm and the client public key to generate a first encrypted random number; Generate a server signature based on the file parameters of the target file, the first random number, the first encrypted random number, and the first shared key using a preset signature generation algorithm; The server public key, the first encrypted random number, the server signature, and the file parameters and download link of the target file are sent to the client, so that the client downloads the target file according to the download link.

2. The file transmission method according to claim 1, characterized in that: The using a preset key exchange algorithm to generate a first shared key based on the first random number, the server private key and the client public key includes: Selecting a first elliptic curve from a preset elliptic curve list according to the first random number; The server private key and the client public key are encrypted using the ECDH algorithm based on the first elliptic curve to generate the first shared key.

3. The file transmission method according to claim 1, characterized in that: The using a preset signature generation algorithm to generate a server signature based on the file parameters of the target file, the first random number, the first encrypted random number, and the first shared key includes: Selecting a first hash algorithm from a preset hash algorithm list according to the first random number; The server signature is generated based on the file parameters of the target file, the first random number, the first encrypted random number, the first hash algorithm and the first shared key using a hash-based message authentication code algorithm.

4. The file transmission method according to claim 1, characterized in that: The file transmission method further includes: Receiving the target file, the first verification signature and the first encrypted random number sent by the client; Determining whether the server signature is consistent with the first verification signature; If they are consistent, decrypt the first encrypted random number using the preset asymmetric encryption algorithm and the server private key to obtain a verification random number; Generate a verification shared key based on the verification random number, the server private key and the client public key using the preset key exchange algorithm; Generate a verification server signature based on the file parameters of the target file, the verification random number, the first encrypted random number and the verification shared key using the preset signature generation algorithm; The verification server signature is sent to the client.

5. The file transmission method according to claim 1, characterized in that: Before receiving the file request sent by the client and carrying the file identifier and the client public key, the file transmission method further includes: Receiving the original compressed package of the target file uploaded by the client, and generating a file identifier and creation time of the target file; generating a second random number; Generate a second shared key based on the second random number, the server private key and the client public key using the preset key exchange algorithm; Generate a compressed package password based on the file identifier and creation time of the target file, the second random number and the second shared key using the preset signature generation algorithm; Decompressing the original compressed package, and encrypting and compressing the decompressed file using the compressed package password to obtain the target file; The target file is stored in a preset location, and a download link for the target file is generated.

6. A file downloading method, characterized in that: Applied to the client, the file download method includes: Send a file request with the file identifier and the client public key to the server; Receiving a server public key, a first encrypted random number, a server signature, and file parameters and a download link of a target file sent by the server; Download the target file from the download link; Decrypting the first encrypted random number using a preset asymmetric encryption algorithm and a client private key to obtain a first random number; Generate a first shared key based on the first random number, the server public key and the client private key using a preset key exchange algorithm; Generate a first verification signature based on the file parameters of the target file, the first random number, the first encrypted random number, and the first shared key using a preset signature generation algorithm; If the first verification signature is consistent with the server signature, the target file is determined to be safe.

7. The file downloading method according to claim 6, characterized in that: If the first verification signature is consistent with the server signature, the file download method further includes: Sending the target file, the first verification signature, and the first encrypted random number to the server; Receiving a verification server signature sent by the server; Determining whether the verification server signature is consistent with the first verification signature; If they are consistent, it is determined that the target file is safe; If they are inconsistent, the target file is downloaded again from the download link.

8. The file downloading method according to claim 6 or 7, characterized in that: After determining that the target file is safe, the file downloading method further includes: Receiving a second encrypted random number sent by the server; Decrypt the second encrypted random number using the preset asymmetric encryption algorithm and the client private key to obtain a second random number; Generate a second shared key based on the second random number, the server public key and the client private key using the preset key exchange algorithm; Generate a compressed package password based on the file identifier and creation time in the file parameters of the target file, the second random number and the second shared key using the preset signature generation algorithm; The target file is decrypted and decompressed using the compressed package password.

9. The file downloading method according to claim 8, characterized in that: After decrypting and decompressing the target file using the compressed package password, the file downloading method further includes: The target file and the decompressed file of the target file are stored locally to obtain the compressed file path and the file path of the target file; The file parameters of the target file, the first encrypted random number, and the server signature are stored locally.

10. The file downloading method according to claim 9, characterized in that: The file downloading method further includes: Query the file parameters of the target file, the first encrypted random number, the server signature, the file path and the compressed package file path in the local storage according to the file identifier of the target file; Acquire the locally stored target file from the compressed package file path; Decrypting the first encrypted random number using the preset asymmetric encryption algorithm and the server public key to obtain the first random number; Generate the first shared key based on the first random number, the server public key and the client private key using the preset key exchange algorithm; Generate a second verification signature based on the file parameters of the target file, the first random number, the first encrypted random number, and the first shared key using the preset signature generation algorithm; Determining whether the second verification signature is consistent with the locally stored server signature; If they are consistent, the decompressed file of the target file is obtained from the file path.

11. A server, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the server can implement the file transmission method according to any one of claims 1 to 5.

12. A client, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the client can implement the file downloading method according to any one of claims 6 to 10.

Citation Information

Patent Citations

  • Encryption continuous transmission method with key negotiation function

    CN111447276A

  • System and method for authorization of access to a resource

    US20020194483A1