Encryption and decryption method and device
By generating random values and key derivation technology, combined with blockchain storage, the security problem of password library files caused by the loss of master passwords is solved, and multiple encryption and security guarantees of password management software are realized.
Patent Information
- Application Number
- CN202211649323.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-21
- Publication Date
- 2025-09-05
- Estimated Expiration
- 2042-12-21
AI Technical Summary
In existing password management software, after the master password is lost, the security of the password library file cannot be guaranteed, which becomes a security bottleneck.
The master key is used to generate the first random value, the first key is generated through the key derivation, the encrypted file is encrypted, and the encrypted file is uploaded to the storage server and blockchain node, and the security of the blockchain is used to enhance the security of the password library file.
Through multiple encryption and blockchain storage, we can prevent security risks caused by the loss of the master password, ensure the security of password library files, and resist conspiracy attacks.
Smart Images

Figure CN115859329B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network security, and in particular to an encryption and decryption method and device. Background Art
[0002] Password managers have come a long way in recent years. A password manager is a specialized system for creating, storing, and managing passwords. It can generate passwords for users to log into various websites and automatically enter their usernames and passwords into website login forms. Therefore, if you want to set secure passwords for multiple online accounts but have trouble remembering multiple passwords, a password manager is the best choice.
[0003] Typically, password management software is associated with a master password, which can be used to decrypt the password vault file. The password vault file stores passwords for multiple online accounts. Typically, the password vault file is encrypted and stored on a third-party server. While the plaintext password vault file cannot be accessed on the cloud, losing the user's master password directly impacts the numerous password vault files stored within the vault. The passwords stored in the password vault file serve as the sole authentication credentials for many applications.
[0004] Since the password vault file relies solely on the master password for encryption, once the master password is lost, it becomes the security bottleneck of the password management software. Therefore, how to ensure the security of the password vault file is of great economic and social significance. Summary of the Invention
[0005] In view of this, an embodiment of the present invention provides an encryption and decryption method and device, which solves the problem that existing password library files rely solely on a master password for encryption operations. Once the master password is lost, the master password becomes a security bottleneck of the password management software.
[0006] In a first aspect, an embodiment of the present invention provides an encryption method for obtaining a master key, encrypting a file to be encrypted, and generating an encrypted file;
[0007] When encrypting the file to be encrypted using the master key, generating a first random value;
[0008] Performing key derivation on the master key according to the first random value to generate a first key;
[0009] The file to be encrypted is encrypted using the first key to obtain an encrypted file.
[0010] Optionally, recording the first random value includes: generating a second random value;
[0011] Performing key derivation on the master key according to the second random value to generate a second key;
[0012] The first random value is encrypted using the second key to obtain a first ciphertext.
[0013] Optionally, the method further includes: using a public key to encrypt the second random value to obtain a second ciphertext.
[0014] Optionally, the method further includes: uploading the encrypted file to a storage server, and storing the first ciphertext and the second ciphertext in a blockchain node.
[0015] Optionally, performing key derivation on the master key according to the first random value to generate a first key includes:
[0016] Performing key derivation on the master key according to the first random value and a preset number of first algorithm iterations to generate a first key;
[0017] The step of performing key derivation on the master key according to the second random value to generate a second key includes:
[0018] According to the second random value and a preset number of iterations of the second algorithm, a key derivation is performed on the master key to generate a second key.
[0019] Optionally, encrypting the first random value using the second key to obtain a first ciphertext includes:
[0020] Using the second key, encrypt the first random value and the number of first algorithm iterations to obtain a first ciphertext;
[0021] The step of encrypting the second random value using the public key to obtain a second ciphertext includes:
[0022] Encrypting the second random value and the second algorithm iteration number using the public key to obtain a second ciphertext;
[0023] The storing the first ciphertext and the second ciphertext in a blockchain node includes:
[0024] Encrypting the first ciphertext, the second ciphertext, and the current timestamp using a private key to obtain a third ciphertext;
[0025] The third ciphertext and the user's UID are uploaded to the blockchain, so that the blockchain uses the public key corresponding to the user's UID to store the first ciphertext and the second ciphertext in the blockchain node corresponding to the user's UID.
[0026] In a second aspect, an embodiment of the present invention provides a decryption method for obtaining a master key, decrypting the obtained file to be decrypted, and obtaining a plaintext file;
[0027] When decrypting the file to be decrypted using the master key, obtaining a first random value;
[0028] Performing key derivation on the master key according to the first random value to generate a first key;
[0029] The file to be decrypted is decrypted using the first key to obtain a plaintext file.
[0030] Optionally, obtaining the first random value includes: obtaining a first ciphertext and a second ciphertext; the first ciphertext is obtained by encrypting the first random value using the second random value and a master key, and the second ciphertext is obtained by encrypting the second random value using a public key;
[0031] Decrypt the second ciphertext using the private key to obtain a second random value;
[0032] Performing key derivation on the master key according to the second random value to obtain a second key;
[0033] The first ciphertext is decrypted using the second key to obtain a first random value.
[0034] In a third aspect, an embodiment of the present invention provides an encryption device that obtains a master key, encrypts a file to be encrypted, and generates an encrypted file; the device includes:
[0035] A first generating unit, configured to generate a first random value when encrypting the file to be encrypted using the master key;
[0036] a second generating unit, configured to perform key derivation on the master key according to the first random value to generate a first key;
[0037] The encryption unit is configured to encrypt the file to be encrypted using the first key to obtain the encrypted file.
[0038] In a fourth aspect, an embodiment of the present invention provides a decryption device for obtaining a master key and decrypting the obtained file to be decrypted to obtain a plaintext file; the device includes:
[0039] an acquiring unit, configured to obtain a first random value when decrypting the file to be decrypted using the master key;
[0040] a first generating unit, configured to perform key derivation on the master key according to the first random value to generate a first key;
[0041] The decryption unit is used to decrypt the file to be decrypted using the first key to obtain a plaintext file.
[0042] In a fifth aspect, an embodiment of the present invention provides an electronic device, comprising: a housing, a processor, a memory, a circuit board, and a power supply circuit, wherein the circuit board is placed inside the space enclosed by the housing, and the processor and the memory are arranged on the circuit board; the power supply circuit is used to supply power to various circuits or devices of the above-mentioned network device; the memory is used to store executable program code; the processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, and is used to execute an encryption and decryption method described in the first and second aspects above.
[0043] In the sixth aspect, an embodiment of the present invention provides a computer-readable storage medium, which stores one or more programs, and the one or more programs can be executed by one or more processors to implement an encryption and decryption method described in the first or second aspect above.
[0044] In the seventh aspect, an embodiment of the present invention provides a computer program product, including a computer program, which can be executed by one or more processors to implement an encryption and decryption method described in the first or second aspect above.
[0045] An embodiment of the present invention provides an encryption and decryption method and device. An electronic device obtains a master key, encrypts a file to be encrypted, and generates an encrypted file. When the master key is used to encrypt the file to be encrypted, a first random value is generated. Based on the first random value, the electronic device derives the master key to generate a first key. The file to be encrypted is encrypted using the first key, and the electronic device obtains the encrypted file.
[0046] Using the master key, the electronic device generates a new key, which is then used to encrypt the password file. This solution addresses the problem of existing password vault files relying solely on the master password for encryption. Once the master password is lost, it becomes a security bottleneck for the password management software, thus ensuring the security of the password vault files. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0048] Figure 1 A flowchart of an encryption method provided by an embodiment of the present invention;
[0049] Figure 2 A flow chart of a decryption method provided by an embodiment of the present invention;
[0050] Figure 3 A timing diagram of system initialization provided by an embodiment of the present invention;
[0051] Figure 4 A timing diagram of encryption and decryption of a password library file provided by an embodiment of the present invention;
[0052] Figure 5 An update sequence diagram of a password library file provided by an embodiment of the present invention;
[0053] Figure 6 A schematic diagram of an encryption device provided by an embodiment of the present invention;
[0054] Figure 7 A schematic diagram of a decryption device provided by an embodiment of the present invention;
[0055] Figure 8 A schematic diagram of the hardware structure of a device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0056] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0057] It should be understood that the embodiments described are only a portion of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without creative work are within the scope of protection of the present invention.
[0058] The following is combined with Figure 1 , the solution provided by the embodiment of the present invention is described in detail, Figure 1 The present invention provides an encryption method flow chart, in which the implementation subject is an electronic device. The electronic device can be a terminal. For example, a PC, a desktop, a PAD, etc. Figure 1 As shown, the method of this embodiment specifically includes the following steps:
[0059] Step 110: When encrypting the file to be encrypted using the master key, generate a first random value.
[0060] In this step, in one implementation, multiple keys have been generated in the electronic device according to an existing key generation method. The electronic device receives a selection operation instruction input by the user and selects one key from the multiple keys as a master key (masterKey) according to the selection operation instruction.
[0061] In another implementation, the electronic device receives a key generation instruction input by a user and generates a master key according to the content input by the user.
[0062] According to the existing random value generation method, multiple random values have been generated in the electronic device, and the electronic device randomly selects a random value from the multiple random values. The first random value can also be called a first salt value (salt1).
[0063] Step 120: Perform key derivation on the master key according to the first random value to generate a first key.
[0064] In this step, the electronic device locally calls a key derivation algorithm in a cryptographic function library to generate a first key based on the master key and the first random value.
[0065] The key derivation algorithm is K = KDF (masterKey, salt, iterations); where K is the final derived key, masterKey is the master key, salt is the salt value, and iterations is an integer representing the number of algorithm iterations.
[0066] The first key is specifically K1=KDF(masterKey, salt1, iterations1), where iterations1 can also be referred to as the first number of iterations.
[0067] Optionally, the above-mentioned key derivation is performed on the master key based on the first random value, and the electronic device generates the first key. The specific process is: based on the first random value and the preset number of first algorithm iterations, the master key is derivation is performed, and the electronic device generates the first key.
[0068] Step 130: Encrypt the file to be encrypted using the first key to obtain an encrypted file.
[0069] In this step, after the electronic device generates the first key, it uses the first key as the encryption key of the file to be encrypted, and encrypts the file to be encrypted to obtain an encrypted file.
[0070] It is understandable that the process of the electronic device using the key to encrypt the file is the same as the existing encryption process and will not be repeated here.
[0071] Therefore, the electronic device uses the master key to generate a new key, which is then used to encrypt the file. This solution can solve the problem that existing password vault files rely solely on the master password for encryption operations. Once the master password is lost, it becomes a security bottleneck for the password management software, thus ensuring the security of the password vault files.
[0072] Optionally, the embodiment of the present invention further includes a process in which the electronic device records the first random value.
[0073] Specifically, the electronic device generates a second random value; performs key derivation on the master key based on the second random value, and generates a second key; and uses the second key to encrypt the first random value to obtain a first ciphertext.
[0074] The second random value may also be referred to as a second salt value (salt2). The second key is specifically K2 = KDF (masterKey, salt2, iterations2). Here, iterations2 may also be referred to as the second number of iterations.
[0075] Optionally, the above-mentioned key derivation is performed on the master key based on the second random value, and the electronic device generates the second key. The specific process is: based on the second random value and the preset number of iterations of the second algorithm, the master key is derivation is performed on the electronic device to generate the second key.
[0076] Optionally, the electronic device encrypts the first random value using the second key to obtain the first ciphertext. The specific process is: the electronic device encrypts the first random value and the number of iterations of the first algorithm using the second key to obtain the first ciphertext.
[0077] Optionally, the embodiment of the present invention further includes using the public key, the electronic device encrypting the second random value to obtain a second ciphertext.
[0078] Optionally, the electronic device encrypts the second random value using the public key to obtain the second ciphertext. The specific process is: the electronic device encrypts the second random value and the number of iterations of the second algorithm using the public key to obtain the second ciphertext.
[0079] It should be noted that if the iteration value of the key derivation algorithm is 0 or a fixed value, the first ciphertext and the second ciphertext do not include the iteration value.
[0080] Optionally, an embodiment of the present invention further includes the electronic device uploading the encrypted file to a storage server, and storing the first ciphertext and the second ciphertext in a blockchain node.
[0081] Optionally, while storing the first and second ciphertexts in the blockchain node, the electronic device uses the private key to encrypt the first and second ciphertexts, as well as the current timestamp, to obtain a third ciphertext. The electronic device uploads the third ciphertext to the blockchain. The blockchain node uses the certificate to verify whether the third ciphertext can be decrypted. If the certificate determines that the third ciphertext can be decrypted, the blockchain node determines whether the timestamp included in the third ciphertext passes verification. If the timestamp included in the third ciphertext passes verification, the blockchain node stores the first and second ciphertexts in the user attributes.
[0082] The blockchain node determines whether the timestamp has passed verification. The specific process is as follows: the blockchain node determines whether the timestamp is earlier than the locally recorded time. If it is earlier, the timestamp is considered to have passed verification; if it is later, the timestamp is considered to have failed verification.
[0083] Optionally, the above-mentioned electronic device stores the first ciphertext and the second ciphertext in a blockchain node. The specific process is: using the private key, the electronic device encrypts the first ciphertext, the second ciphertext, and the current timestamp to obtain a third ciphertext; the electronic device uploads the third ciphertext and the user's UID to the blockchain, so that the blockchain uses the public key corresponding to the user's UID to store the first ciphertext and the second ciphertext in the blockchain node corresponding to the user's UID.
[0084] The following is combined with Figure 2 , the solution provided by the embodiment of the present invention is described in detail, Figure 2 This is a flow chart of a decryption method provided by an embodiment of the present invention. In this embodiment of the present invention, the implementation subject is an electronic device. For example, a PC, a desktop, a PAD, etc. Figure 2 As shown, the method of this embodiment specifically includes the following steps:
[0085] Step 210: When the file to be decrypted is decrypted using the master key, a first random value is obtained.
[0086] In this step, the electronic device decrypts the file to be decrypted using the master key. During the decryption process, the electronic device obtains a first random value.
[0087] Optionally, the specific process of the above-mentioned electronic device obtaining the first random value is: the electronic device obtains a first ciphertext and a second ciphertext; the first ciphertext is obtained by encrypting the first random value using the second random value and the master key, and the second ciphertext is obtained by encrypting the second random value using the public key; using the private key, the electronic device decrypts the second ciphertext to obtain the second random value; based on the second random value, the electronic device derives the master key to obtain the second key; using the second key, the electronic device decrypts the first ciphertext to obtain the first random value.
[0088] Step 220: Perform key derivation on the master key according to the first random value to generate a first key.
[0089] In this step, the electronic device locally calls a key derivation algorithm in a cryptographic function library to generate a first key based on the master key and the first random value.
[0090] Step 230: Decrypt the file to be decrypted using the first key to obtain a plaintext file.
[0091] In this step, the electronic device decrypts the file to be decrypted using the first key to obtain a plaintext file.
[0092] It is understandable that the process of the electronic device decrypting the file using the first key is the same as the existing decryption process, and will not be repeated here.
[0093] The following is combined with Figure 3 , the solution provided by the embodiment of the present invention is described in detail, Figure 3 This is a timing diagram of system initialization provided by an embodiment of the present invention. It specifically includes the following steps:
[0094] Step 300: The system administrator (which may also be a user) deploys two sets of smart contracts in the blockchain node, the certificate smart contract SM1 and the user smart contract SM2.
[0095] In this step, the system administrator (which can also be a user) sends a configuration operation instruction to the blockchain node. The configuration operation instruction includes the first information of the certificate smart contract and the second information of the user smart contract.
[0096] After receiving the configuration operation instruction, the blockchain node obtains the first information and the second information from it, and locally configures the certificate smart contract SM1 and the user smart contract SM2 based on the first information and the second information.
[0097] Step 301: The CA sends a trusted root certificate to the blockchain node, and the blockchain node stores the root certificate.
[0098] Step 302: The terminal generates a master key locally.
[0099] Step 303: The terminal generates a public-private key pair locally.
[0100] Step 304: The terminal sends a signature request to the CA. The signature request includes the user ID (UID) and public key of the user.
[0101] Step 305: CA calls the interfaces provided by the two sets of smart contracts respectively, and sends the user identification and certificate to the blockchain node through different interfaces.
[0102] In this step, after receiving the signature request, the CA obtains the user ID and public key from it. The CA first authenticates the user ID. Once the authentication is successful, the CA then signs the public key and generates a certificate. It is understood that after the CA signs the public key, the certificate includes the public key.
[0103] The CA calls the interfaces provided by the two sets of smart contracts and sends the user ID and certificate to the blockchain node through different interfaces.
[0104] Step 306: The blockchain node creates user attributes and stores the user attributes in a trustworthy manner.
[0105] In this step, the certificate smart contract SM1 receives the certificate from the CA, while the user smart contract SM2 receives the user ID from the CA. After receiving the certificate and user ID, each smart contract creates user attributes locally. Each smart contract writes the certificate and user ID as user attributes (UID, CertID) into the blockchain node's blockchain ledger. Blockchain nodes provide trusted storage for user attributes.
[0106] Step 307: The blockchain node sends an initialization result to the terminal, where the initialization result includes a user identifier.
[0107] Step 308: The terminal determines that the user initialization is successful.
[0108] The following is combined with Figure 4 , the solution provided by the embodiment of the present invention is described in detail, Figure 4 The encryption and decryption sequence diagram of the password library file provided in the embodiment of the present invention includes the following steps:
[0109] Step 400: The terminal generates a first key and a second key.
[0110] In this step, multiple random values are generated in the terminal according to existing random value generation methods. The terminal randomly selects two random values from the multiple random values. The first random value can also be referred to as the first salt value (salt1). The second random value can also be referred to as the second salt value (salt2).
[0111] The terminal locally calls a key derivation algorithm in a cryptographic function library to generate a first key based on the master key and the first random value, and generates a second key based on the master key and the second random value.
[0112] The first key is specifically K1 = KDF(masterKey, salt1, iterations1). Here, iterations1 is also referred to as the first number of iterations. The second key is specifically K2 = KDF(masterKey, salt2, iterations2). Here, iterations2 is also referred to as the second number of iterations.
[0113] Step 401: The terminal encrypts the first password library file using the first key to obtain the encrypted first password library file.
[0114] Step 402: The terminal sends the encrypted first password library file to the storage server, so that the storage server stores the encrypted first password library file locally.
[0115] Step 403: The terminal receives the storage result sent by the storage server.
[0116] Step 404: The terminal generates a first ciphertext, a second ciphertext, and a third ciphertext.
[0117] In this step, the terminal uses the second key as the encryption key for the first random value and the first number of iterations, and encrypts the first random value and the first number of iterations to obtain a first ciphertext.
[0118] The terminal uses the public key as an encryption key for the second random value and the second number of iterations, and encrypts the second random value and the second number of iterations to obtain a second ciphertext.
[0119] The terminal uses the private key as the encryption key of the first random value and the second random value, and encrypts the first random value and the second random value to obtain a third ciphertext.
[0120] The above ciphertexts all include a timestamp, which is the valid time when the terminal performs decryption processing.
[0121] Step 405: The terminal sends a certificate request to the blockchain node. The certificate request includes the user ID, the first ciphertext, the second ciphertext, and the third ciphertext.
[0122] Step 406: Based on the user identifier, the blockchain node calls the certificate smart contract SM1 to obtain the user attributes and obtains the certificate from the user attributes.
[0123] Step 407: If the certificate can decrypt the third ciphertext and the timestamp included in the third ciphertext passes verification, the user smart contract SM2 is called to store the first ciphertext and the second ciphertext in the user attributes.
[0124] In this step, the public key included in the certificate is used to verify whether the third ciphertext can be decrypted.
[0125] If it is determined that the public key included in the certificate can decrypt the third ciphertext, then the timestamp included in the third ciphertext is determined to be verified. If the timestamp included in the third ciphertext is verified, the blockchain node calls the user smart contract SM2 and stores the first and second ciphertexts in the user attributes.
[0126] Step 408: The blockchain node sends a proof response to the terminal.
[0127] Step 409: The terminal determines that the blockchain node has stored the first ciphertext and the second ciphertext.
[0128] Step 410: The terminal obtains the encrypted first password library file from the storage server.
[0129] In this step, the terminal may obtain the encrypted first password library file from the storage server by remotely pulling.
[0130] Step 411: The terminal locally caches the encrypted first password library file.
[0131] Step 412: The terminal sends an acquisition request to the blockchain node, where the acquisition request includes a user identifier.
[0132] Step 413: The blockchain node sends an acquisition response to the terminal, where the acquisition response includes the first ciphertext and the second ciphertext.
[0133] In this step, based on the user ID, the blockchain node calls the user smart contract SM2 and checks locally to see if the corresponding user attributes exist. If so, the user attributes are obtained and the first and second ciphertexts are obtained from the user attributes.
[0134] Step 414: The terminal decrypts the encrypted first password library file using the master key, the first ciphertext, and the second ciphertext.
[0135] In this step, the terminal receives the master key entered by the user and uses it to decrypt and obtain the private key. The terminal then uses the private key to decrypt the second ciphertext, obtaining a second random value and a second iteration count. Based on the master key, the second random value, and the second iteration count, the terminal invokes a key derivation algorithm to generate a second key. It is understood that the process for generating the second key by the terminal is identical to that described above and will not be repeated here.
[0136] The terminal decrypts the first ciphertext using the second key to obtain a first random value and a first iteration count. Based on the master key, the first random value, and the first iteration count, the terminal invokes a key derivation algorithm to generate a first key. It is understood that the process for generating the first key by the terminal is the same as that described above and is not repeated here.
[0137] The terminal decrypts the encrypted first password library file using the first key to obtain the first password library file.
[0138] The following is combined with Figure 5 , the solution provided by the embodiment of the present invention is described in detail, Figure 5 The update sequence diagram of the password library file provided in the embodiment of the present invention includes the following steps:
[0139] Step 500: The terminal receives a modification operation instruction input by the user, and updates the first password library file to obtain a second password library file.
[0140] In this step, the user pre-modifies the first password library file, and the terminal receives the modification operation instruction input by the user. According to the modification operation instruction, the terminal updates the first password library file to obtain a second password library file.
[0141] Step 501: The terminal generates a third key and a fourth key.
[0142] In this step, the terminal may randomly select two random values from the previously generated multiple random values. Alternatively, the terminal may generate multiple random values again using an existing random value generation method and randomly select two random values from the multiple random values. The third random value may also be referred to as the third salt value (salt3), and the fourth random value may also be referred to as the fourth salt value (salt4).
[0143] The terminal again locally calls the key derivation algorithm in the cryptographic function library to generate a third key based on the master key and the third random value. The terminal again locally calls the key derivation algorithm in the cryptographic function library to generate a fourth key based on the master key and the fourth random value.
[0144] The third key is specifically K3 = KDF(masterKey, salt3, iterations3). Here, iterations3 is also referred to as the third iteration count. The fourth key is specifically K4 = KDF(masterKey, salt4, iterations4). Here, iterations4 is also referred to as the fourth iteration count.
[0145] Step 502: The terminal encrypts the second password library file using the third key to obtain an encrypted second password library file.
[0146] Step 503: The terminal sends the encrypted second password library file to the storage server, so that the storage server stores the encrypted second password library file locally.
[0147] Step 504: The terminal receives the storage result sent by the storage server.
[0148] Step 505: The terminal generates a fourth ciphertext, a fifth ciphertext, and a sixth ciphertext.
[0149] In this step, the terminal uses the fourth key as the encryption key of the third random value and the third iteration number, and encrypts the third random value and the third iteration number to obtain a fourth ciphertext.
[0150] The terminal uses the public key as an encryption key for the fourth random value and the fourth iteration number, and encrypts the fourth random value and the fourth iteration number to obtain a fifth ciphertext.
[0151] The terminal uses the private key as the encryption key of the third random value and the fourth random value, and encrypts the third random value and the fourth random value to obtain a sixth ciphertext.
[0152] The above ciphertexts all include a timestamp, which is the valid time when the terminal performs decryption processing.
[0153] Step 506: The terminal sends an update request to the blockchain node, where the update request includes the user ID, the fourth ciphertext, the fifth ciphertext, and the sixth ciphertext.
[0154] Step 507: Based on the user identifier, the blockchain node calls the certificate smart contract SM1 to obtain the user attributes and obtains the certificate from the user attributes.
[0155] Step 508: If the certificate can decrypt the sixth ciphertext and the timestamp included in the sixth ciphertext passes verification, the user smart contract SM2 is called to update the ciphertext stored in the user attributes.
[0156] In this step, if the public key included in the certificate is determined to be capable of decrypting the third ciphertext, the blockchain node determines whether the timestamp included in the sixth ciphertext has been verified. If the timestamp included in the sixth ciphertext has been verified, the blockchain node invokes the user smart contract SM2, deletes the first and second ciphertexts originally included in the user attributes, and stores the fourth and fifth ciphertexts in the user attributes.
[0157] Step 509: The blockchain node sends an update response to the terminal.
[0158] The following is combined with Figure 6 , the solution provided by the embodiment of the present invention is described in detail, Figure 6 A schematic diagram of an encryption device provided in an embodiment of the present invention, wherein the device obtains a master key, encrypts a file to be encrypted, and generates an encrypted file, the device comprising:
[0159] A first generating unit 610 is configured to generate a first random value when encrypting the file to be encrypted using the master key;
[0160] A second generating unit 620 is configured to perform key derivation on the master key according to the first random value to generate a first key;
[0161] The encryption unit 630 is configured to encrypt the file to be encrypted using the first key to obtain an encrypted file.
[0162] Optionally, the apparatus records the first random value, further comprising:
[0163] A third generating unit (not shown in the figure), configured to generate a second random value;
[0164] a fourth generating unit (not shown in the figure), configured to perform key derivation on the master key based on the second random value to generate a second key;
[0165] The encryption unit 630 is further configured to encrypt the first random value using the second key to obtain a first ciphertext.
[0166] Optionally, the encryption unit 630 is further configured to encrypt the second random value using a public key to obtain a second ciphertext.
[0167] Optionally, the device further includes: a storage unit (not shown in the figure), used to upload the encrypted file to a storage server, and store the first ciphertext and the second ciphertext in a blockchain node.
[0168] Optionally, the second generating unit 620 is specifically configured to perform key derivation on the master key according to the first random value and a preset number of first algorithm iterations to generate a first key;
[0169] The fourth generating unit (not shown in the figure) is specifically used to derive a key from the master key according to the second random value and a preset number of iterations of the second algorithm to generate a second key.
[0170] Optionally, the encryption unit 630 is specifically configured to encrypt the first random value and the number of first algorithm iterations using the second key to obtain a first ciphertext;
[0171] The encryption unit 630 is specifically configured to encrypt the second random value and the second algorithm iteration number using a public key to obtain a second ciphertext;
[0172] The storage unit (not shown in the figure) is specifically used to encrypt the first ciphertext, the second ciphertext, and the current timestamp using a private key to obtain a third ciphertext;
[0173] The third ciphertext and the user's UID are uploaded to the blockchain, so that the blockchain uses the public key corresponding to the user's UID to store the first ciphertext and the second ciphertext in the blockchain node corresponding to the user's UID.
[0174] Therefore, the electronic device uses the master key to generate a new key, which is then used to encrypt the password vault file. This solution can solve the problem that existing password vault files rely solely on the master password for encryption operations. Once the master password is lost, it becomes a security bottleneck for the password management software, thus ensuring the security of the password vault file.
[0175] The following is combined with Figure 7 , the solution provided by the embodiment of the present invention is described in detail, Figure 7 A schematic diagram of a decryption device provided in an embodiment of the present invention, wherein the device obtains a master key and decrypts the obtained file to be decrypted to obtain a plaintext file, wherein the device includes:
[0176] An acquiring unit 710 is configured to obtain a first random value when decrypting the file to be decrypted using the master key;
[0177] A first generating unit 720 is configured to perform key derivation on the master key according to the first random value to generate a first key;
[0178] The decryption unit 730 is configured to decrypt the file to be decrypted using the first key to obtain a plaintext file.
[0179] Optionally, the acquiring unit 710 is specifically configured to obtain a first ciphertext and a second ciphertext; the first ciphertext is obtained by encrypting the first random value using the second random value and a master key, and the second ciphertext is obtained by encrypting the second random value using a public key;
[0180] Decrypt the second ciphertext using the private key to obtain a second random value;
[0181] Performing key derivation on the master key according to the second random value to obtain a second key;
[0182] The first ciphertext is decrypted using the second key to obtain a first random value.
[0183] In this way, even if an attacker obtains the master key from the electronic device, they will not be able to decrypt the password vault file. Blockchain nodes provide ciphertext management functionality, but they have no access to any plaintext or encrypted files. The truly encrypted password vault file is stored separately on the storage server, without any access to any plaintext or keys. This multi-party joint encryption and storage method effectively resists collusion attacks. This solution addresses the problem of existing password vault files relying solely on the master password for encryption. Once the master password is lost, it becomes a security bottleneck for password management software, thus ensuring the security of the password vault file.
[0184] Accordingly, Figure 8 A schematic diagram of the hardware structure of a device provided by the present invention can realize the present invention Figure 1-Figure 2 The process of the embodiment shown is as follows: Figure 8 As shown, the electronic device described above can be implemented using the hardware shown in the device hardware structure diagram. The device hardware structure includes: a housing 81, a processor 82, a memory 83, a circuit board 84, and a power supply circuit 85. The circuit board 84 is housed within the space enclosed by the housing 81, and the processor 82 and memory 83 are disposed on the circuit board 84. The power supply circuit 85 is used to supply power to the various circuits or components of the device described above. The memory 83 is used to store executable program code. The processor 82 reads the executable program code stored in the memory 83 to run the program corresponding to the executable program code, thereby executing the encryption and decryption methods described in the aforementioned embodiments.
[0185] For details on the specific execution process of the above steps by the processor 82 and the steps further executed by the processor 82 by running the executable program code, please refer to the present invention. Figure 1-Figure 2 The description of the illustrated embodiment will not be repeated here.
[0186] It should be noted that, in this document, terms such as "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.
[0187] Each embodiment in this specification is described in a related manner. The same or similar parts between the embodiments can be referred to each other. Each embodiment focuses on the differences from other embodiments.
[0188] In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0189] The logic and / or steps represented in the flowcharts or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing the logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (e.g., a computer-based system, a system including a processor, or other system that can fetch and execute instructions from an instruction execution system, apparatus, or device). For purposes of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate, or transport a program for use by, or in conjunction with, an instruction execution system, apparatus, or device.
[0190] More specific examples (a non-exhaustive list) of computer-readable media include the following: an electrical connection with one or more wires (electronic devices), a portable computer disk cartridge (magnetic devices), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disc read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, deciphering, or processing in another suitable manner as necessary, and then stored in a computer memory.
[0191] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware or a combination thereof.
[0192] In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented using hardware, as in another embodiment, any one of the following technologies known in the art or a combination thereof can be used: a discrete logic circuit having logic gate circuits for implementing logic functions on data signals, an application-specific integrated circuit having suitable combinational logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0193] Those skilled in the art will understand that all or part of the steps in the method of the above embodiment can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium. When the program is executed, it includes one or a combination of the steps of the method embodiment.
[0194] For the convenience of description, the above device is described as being divided into various units / modules based on their functions. Of course, when implementing the present invention, the functions of each unit / module can be implemented in the same or multiple software and / or hardware.
[0195] From the above description of the embodiments, it can be seen that those skilled in the art can clearly understand that the present invention can be implemented by means of software plus the necessary general hardware platform. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a storage medium such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in various embodiments of the present invention or certain parts of the embodiments.
Claims
1. An encryption method, which obtains a master key, encrypts a file to be encrypted, and generates an encrypted file; characterized in that: When encrypting the file to be encrypted using the master key, generating a first random value; Performing key derivation on the master key according to the first random value to generate a first key; Encrypting the file to be encrypted using the first key to obtain an encrypted file; Recording the first random value includes: generating a second random value; Performing key derivation on the master key according to the second random value to generate a second key; Encrypting the first random value using the second key to obtain a first ciphertext; The method further comprises: Encrypting the second random value using the public key to obtain a second ciphertext; The method further comprises: Uploading the encrypted file to a storage server, and storing the first ciphertext and the second ciphertext in a blockchain node; The storing the first ciphertext and the second ciphertext in a blockchain node includes: Encrypting the first ciphertext, the second ciphertext, and the current timestamp using a private key to obtain a third ciphertext; The third ciphertext and the user's UID are uploaded to the blockchain, so that the blockchain uses the public key corresponding to the user's UID to store the first ciphertext and the second ciphertext in the blockchain node corresponding to the user's UID.
2. The method according to claim 1, characterized in that Performing a key derivation on the master key according to the first random value to generate a first key includes: Performing key derivation on the master key according to the first random value and a preset number of first algorithm iterations to generate a first key; The step of performing key derivation on the master key according to the second random value to generate a second key includes: According to the second random value and a preset number of iterations of the second algorithm, a key derivation is performed on the master key to generate a second key.
3. The method according to claim 2, characterized in that The step of encrypting the first random value using the second key to obtain a first ciphertext includes: Using the second key, encrypt the first random value and the number of first algorithm iterations to obtain a first ciphertext; The step of encrypting the second random value using the public key to obtain a second ciphertext includes: The second random value and the second algorithm iteration number are encrypted using the public key to obtain a second ciphertext.
4. A decryption method, which obtains a master key and decrypts the obtained file to be decrypted to obtain a plaintext file; characterized in that: When decrypting the file to be decrypted using the master key, obtaining a first random value; Performing key derivation on the master key according to the first random value to generate a first key; Decrypting the file to be decrypted using the first key to obtain a plaintext file; The obtaining of the first random value comprises: Obtaining a first ciphertext and a second ciphertext; the first ciphertext is obtained by encrypting the first random value using the second random value and the master key, and the second ciphertext is obtained by encrypting the second random value using the public key; Decrypt the second ciphertext using the private key to obtain a second random value; Performing key derivation on the master key according to the second random value to obtain a second key; The first ciphertext is decrypted using the second key to obtain a first random value.
5. An encryption device that obtains a master key, encrypts a file to be encrypted, and generates an encrypted file; characterized in that: The device comprises: A first generating unit, configured to generate a first random value when encrypting the file to be encrypted using the master key; a second generating unit, configured to perform key derivation on the master key according to the first random value to generate a first key; an encryption unit, configured to encrypt the file to be encrypted using the first key to obtain an encrypted file; A third generating unit, configured to generate a second random value; a fourth generating unit, configured to perform key derivation on the master key according to the second random value to generate a second key; The encryption unit is further configured to encrypt the first random value using the second key to obtain a first ciphertext; The encryption unit is further configured to encrypt the second random value using a public key to obtain a second ciphertext; A storage unit, configured to upload the encrypted file to a storage server and store the first ciphertext and the second ciphertext in a blockchain node; The storage unit is specifically configured to encrypt the first ciphertext, the second ciphertext, and the current timestamp using a private key to obtain a third ciphertext; The third ciphertext and the user's UID are uploaded to the blockchain, so that the blockchain uses the public key corresponding to the user's UID to store the first ciphertext and the second ciphertext in the blockchain node corresponding to the user's UID.
6. A decryption device, which obtains a master key and decrypts the obtained file to be decrypted to obtain a plaintext file; characterized in that: The device comprises: an acquiring unit, configured to obtain a first random value when decrypting the file to be decrypted using the master key; a first generating unit, configured to perform key derivation on the master key according to the first random value to generate a first key; a decryption unit, configured to decrypt the file to be decrypted using the first key to obtain a plaintext file; The acquisition unit is further configured to obtain a first ciphertext and a second ciphertext; the first ciphertext is obtained by encrypting the first random value using the second random value and the master key, and the second ciphertext is obtained by encrypting the second random value using the public key; Decrypt the second ciphertext using the private key to obtain a second random value; Performing key derivation on the master key according to the second random value to obtain a second key; The first ciphertext is decrypted using the second key to obtain a first random value.
Citation Information
Patent Citations
Script encryption method, script decryption operation method and related device
CN109284585A
File data password management method and device, computer equipment and storage medium
CN113014380A