Electron data encryption storage method and system, decryption reading method and system

By configuring the data storage directory and generating encryption keys in Electron technology, encrypting and storing user data and obfuscating it, the problem of insecure data storage in Electron technology is solved, and the secure storage and tamper detection of data is realized.

CN114969771BActive Publication Date: 2025-02-18SANMENXIA WEIYUN INFORMATION SERVICE CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210188898.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-28
Publication Date
2025-02-18
Estimated Expiration
2042-02-28

AI Technical Summary

Technical Problem

Electron technology lacks a built-in method to persist user preferences and other data, resulting in unsafe data storage, easy loss, and inability to provide private key encryption, resulting in serious problems such as user data leakage.

Method used

Provide an Electron data encryption storage method, by configuring the root directory and intermediate directory of the data storage, generating storage file names and paths, encrypting and storing data using obfuscated data and encryption keys, and performing MD5 value comparisons during reading to detect Data tampering.

Benefits of technology

It effectively solves the problem of insecurity in data storage, prevents data tampering, ensures data security and integrity, and avoids user data leakage and loss.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114969771B_ABST
    Figure CN114969771B_ABST
Patent Text Reader

Abstract

The present invention belongs to the field of data security technology, and particularly relates to an Electron data encryption storage method and system, a decryption reading method and system, by configuring the data storage root directory and intermediate directory of the user's Electron application, and generating a corresponding storage file name and data storage path according to the data type and data source; calling a directory synchronization check function to check whether the generated data storage path exists, and writing a file according to the check result, wherein, during the file writing process, obfuscated data is inserted into the data to be stored, and the data insertion position is recorded at the end of the file; using an encryption key to encrypt and store the written file to the configured data storage path; reading file buffer class information by calling a synchronous reading function, encrypting the buffer class information using an MD5 encryption method, and storing the encrypted generated MD5 value, wherein the obfuscated data and the MD5 value are stored in a memory or a server. The present invention effectively avoids the security risks of data storage in the prior art and prevents tampering.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of data security technology, and in particular relates to an Electron data encryption storage method and system, and a decryption reading method and system. Background Art

[0002] Electron is a popular desktop client development technology. It develops cross-platform desktop GUI applications by using Node.js (as the backend) and Chromium's rendering engine (as the frontend). It allows developers to create desktop applications using HTML5, CSS, and JavaScript, and access native operating system features on Windows, Mac OS, and Linux through operating system-independent APIs.

[0003] However, since Electron technology is based on browser technology, there is no built-in way to persist user preferences and other data. Although Electron provides window.localStorage storage, window.localStorage only works in the browser process (rendering process) and cannot be used in the main thread. It is also not very fault-tolerant. If the application encounters an error and exits unexpectedly, data may be lost, which creates a serious data storage risk.

[0004] In addition, Electron has no other way to persist user preferences and other data, nor can it provide private keys to encrypt content that needs to be stored. This means that developers do not have the corresponding storage method when developing Electron applications, making it impossible to store data or using unsafe storage methods, leading to serious problems such as user data leakage. Summary of the invention

[0005] To this end, the present invention provides an Electron data encryption storage method and system, a decryption reading method and system, which can effectively solve the hidden danger of data not being able to be securely stored in the prior art, prevent data tampering, and facilitate application in actual scenarios.

[0006] According to the design scheme provided by the present invention, an Electron data encryption storage method includes the following contents:

[0007] Configure the data storage root directory and intermediate directory of the user's Electron application, and generate the corresponding storage file name and data storage path according to the data type and data source;

[0008] Call the directory synchronization check function to check whether the generated data storage path exists, and write the file based on the check result. In the process of writing the file, the obfuscated data is inserted into the data to be stored, and the data insertion position is recorded at the end of the file;

[0009] Generate an encryption key using a user key or a basic key, and use the encryption key to encrypt the written file and store it in the configured data storage path; read the file buffer class information by calling the synchronous read function, encrypt the buffer class information using the MD5 encryption method, and store the encrypted MD5 value for MD5 value comparison when reading file data, where the obfuscated data and MD5 value are stored in the memory or server.

[0010] As the Electron data encryption storage method of the present invention, further, the data is stored in an intermediate directory. If the user is logged in, the intermediate directory is generated according to the user identification. If the user is not logged in, a preset intermediate directory is generated.

[0011] As the Electron data encryption storage method of the present invention, further, during file writing, if the generated data storage path does not exist, the file synchronization write function is called to perform file replacement writing; if the generated data storage path exists, the file synchronization append function is called to append the file data content.

[0012] As the Electron data encryption storage method of the present invention, further, during file writing, obfuscated data is generated by calling a hash salting function, and the generated obfuscated data is inserted into the data to be stored.

[0013] As the Electron data encryption storage method of the present invention, further, in generating the encryption key, if the user is not logged in, the preset basic key is used as the encryption key; if the user is logged in, the current user ID is obtained, a hash value is generated based on the sha512 algorithm, and the built-in function of the hash class is used to update the hash value and generate an encryption key; and based on the encryption key, the file is encrypted and stored in the data storage path through the shell.

[0014] Furthermore, the present invention also provides an Electron data encryption storage system, which includes the following contents: a configuration module, a writing module and an encryption module, wherein:

[0015] Configuration module, used to configure the data storage root directory and intermediate directory of the user's Electron application, and generate the corresponding storage file name and data storage path according to the data type and data source;

[0016] A writing module is used to check whether the generated data storage path exists by calling the directory synchronization check function, and write the file according to the check result. In the process of file writing, the obfuscated data is inserted into the data to be stored, and the data insertion position is recorded at the end of the file;

[0017] The encryption module is used to generate an encryption key using a user key or a basic key, and use the encryption key to encrypt the written file and store it in the configured data storage path; read the file buffer class information by calling the synchronous read function, encrypt the buffer class information using the MD5 encryption method, and store the encrypted MD5 value for MD5 value comparison when reading file data, wherein the obfuscated data and MD5 value are stored in the memory or server.

[0018] Furthermore, the present invention also provides an Electron data decryption and reading method for decrypting and reading the above-mentioned encrypted storage data, and the decryption and reading process includes the following contents:

[0019] Get the data storage root directory and intermediate directory configured by the user's Electron application, and get the corresponding storage file name and data storage path according to the data type and data source;

[0020] Call the directory synchronization check function to check whether the generated data storage path exists. If the data storage path exists, use the user key or the basic key to decrypt the file under the data storage path and obtain the first MD5 value;

[0021] Read the file buffer information by calling the synchronous reading function, encrypt the buffer information using the MD5 encryption method, and obtain the second MD5 value of the encryption process;

[0022] The second MD5 value is compared with the first MD5 value. If the comparison results are consistent, the synchronous reading function is called to read the file information, and the obfuscated data in the file information is removed according to the obfuscated data insertion position to obtain the original stored data. If the comparison results are inconsistent, the file has been tampered with and the data is discarded.

[0023] Furthermore, the present invention also provides an Electron data decryption and reading system, comprising: a path acquisition module, a path detection module, an information reading module and a data recovery module, wherein:

[0024] The path acquisition module is used to obtain the data storage root directory and intermediate directory configured by the user's Electron application, and obtain the corresponding storage file name and data storage path according to the data type and data source;

[0025] A path detection module is used to check whether the generated data storage path exists by calling a directory synchronization check function. If the data storage path exists, the user key or the basic key is used to decrypt the file under the data storage path and obtain the first MD5 value;

[0026] The information reading module is used to read the file buffer information by calling the synchronous reading function, encrypt the buffer information by using the MD5 encryption method, and obtain the second MD5 value of the encryption process;

[0027] The data recovery module is used to compare the second MD5 value with the first MD5 value. If the comparison results are consistent, the synchronous reading function is called to read the file information, and the obfuscated data in the file information is removed according to the obfuscated data insertion position to obtain the original stored data. If the comparison results are inconsistent, the file has been tampered with and the data is discarded.

[0028] Beneficial effects of the present invention:

[0029] The present invention aims at the security issues in the development of Electron applications. It uses obfuscated data to confuse the data to be stored and writes files. The files are encrypting based on encryption algorithms. Abnormal users cannot read the stored information. If the data is modified, the stored user information can be directly discarded, avoiding security risks such as data leakage and tampering. The present invention has good application prospects. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 This is a schematic diagram of the Electron data encryption storage method process in the embodiment;

[0031] Figure 2 This is a schematic diagram of the encryption storage algorithm process in the embodiment;

[0032] Figure 3 The following is a flow chart of generating a user key according to a user identifier in an embodiment;

[0033] Figure 4 This is a schematic diagram of using openssl to encrypt files through shell in the embodiment;

[0034] Figure 5 This is a schematic diagram of the Electron data decryption and reading method process in the embodiment;

[0035] Figure 6 This is a schematic diagram of the decryption reading algorithm process in the embodiment;

[0036] Figure 7 The following is a flowchart of using openssl to decrypt a file through a shell in an embodiment. DETAILED DESCRIPTION

[0037] In order to make the purpose, technical solutions and advantages of the present invention clearer and more understandable, the present invention is further described in detail below in conjunction with the accompanying drawings and technical solutions.

[0038] The present invention provides an Electron data encryption storage method, see Figure 1 As shown, it contains the following contents:

[0039] S101, configure the data storage root directory and intermediate directory of the user's Electron application, and generate the corresponding storage file name and data storage path according to the data type and data source;

[0040] S102, calling a directory synchronization check function to check whether the generated data storage path exists, and writing a file according to the check result, wherein, during the file writing process, the obfuscated data is inserted into the data to be stored, and the data insertion position is recorded at the end of the file;

[0041] S103, using the user key or the basic key to generate an encryption key, using the encryption key to encrypt the written file and store it in the configured data storage path; reading the file buffer class information by calling the synchronous read function, encrypting the buffer class information using the MD5 encryption method, and storing the encrypted MD5 value for MD5 value comparison when reading the file data, wherein the obfuscated data and the MD5 value are stored in the memory or server.

[0042] In response to security issues in Electron application development, obfuscated data is used to confuse the data to be stored and write files. The files are encrypted based on encryption algorithms. Abnormal users cannot read the stored information. If the data is modified, the stored user information can be directly discarded to avoid security risks such as data leakage and tampering.

[0043] As an Electron data encryption storage method in an embodiment of the present invention, further, in the configuration data storage intermediate directory, if the user logs in, an intermediate directory is generated according to the user identification, if the user is not logged in, a preset intermediate directory is generated. Further, in the process of writing a file, if the generated data storage path does not exist, the file synchronization write function is called to replace the file, and if the generated data storage path exists, the file synchronization append function is called to append the file data content. Further, in the process of writing a file, obfuscated data is generated by calling a hash salting function, and the generated obfuscated data is inserted into the data to be stored. Further, in the generation of an encryption key, if the user is not logged in, a preset basic key is used as the encryption key, if the user is logged in, the current user identification is obtained, a hash value is generated based on the sha512 algorithm, and the built-in function of the hash class is used to update the hash value and generate an encryption key; and based on the encryption key, the file is encrypted and stored in the data storage path through the shell.

[0044] In practical applications, see Figure 2As shown in the figure, after opening the Electron application, configure the storage directory, such as 'savepath', to get the storage directory savepath; the intermediate directory mpath, if the user is logged in, generate the directory intermediate value "userA" according to the user ID, mpath = "userA"; if the user is not logged in, generate the directory intermediate value "op", mpath = "op"; the data data to be stored, according to the data type and data source, distinguish the data type, which type it belongs to; according to the data type to be stored, generate the corresponding storage file name, such as .et, use savepath+mpath+dataname.et to get datapath; you can use node's fs.existsSync(path:Path hLike) method to check whether datapath exists. If datapath does not exist, use node's fs.writeFileSync(path:PathLike|number, data:string|NodeJS.ArrayBufferView, options?:WriteFileOptions) to write the file when storing below; if datapath exists, use node's fs.appendFileSync(file:PathLike|number, data:string|Uint8Array, options?:WriteFileOptions) to write the file when storing below. Generate obfuscated data according to node's crypto.randomBtytes(Math.ceil(obfuscated data length / 2)).toString('hex') and insert it into the data to be saved. Keep the insertion position of the obfuscated data and add it to the end of the file to be stored. Use the above datapath storage logic to write the file to datapath. After the data is written, if the user is not logged in, the basic key A must be used. If the user logs in, get the user ID uid, use node's crypto.createHamc('sha512', user ID uid) to generate hash, use hash.update(base key A) to update hash, and use hash.digest('hex') to generate key C. For details, see the attached Figure 3 . Use openssl to encrypt files through the shell, openssl enc -k the key generated above -e-aes256-in datapath file -out datapathtemp file. After completion, delete the datapath file and rename the datapathtemp file to the datapath file. For details, please refer to the attached Figure 4;

[0045] After the above operation is completed, use node's fs.readFileSync(path:PathLike|number, options?:{encoding?:null; flag?:string;}|null) to read the file as buffer information; after reading the buffer information, use node's crypto.createHash('md5') to create a Hash instance, use hash.update(buffer,'utf8') to generate the calculated hash for the binary of the file, and finally use hash.digest('hex') to generate the MD5 value; then, save the MD5 value generated above for MD5 value comparison when reading data to prevent data tampering. Optionally, the MD5 value and obfuscated data are placed in memory, not on disk, or stored in the server, and obtained when the Electron application is opened.

[0046] Furthermore, based on the above method, an embodiment of the present invention also provides an Electron data encryption storage system, which includes the following contents: a configuration module, a writing module and an encryption module, wherein:

[0047] Configuration module, used to configure the data storage root directory and intermediate directory of the user's Electron application, and generate the corresponding storage file name and data storage path according to the data type and data source;

[0048] A writing module is used to check whether the generated data storage path exists by calling the directory synchronization check function, and write the file according to the check result. In the process of file writing, the obfuscated data is inserted into the data to be stored, and the data insertion position is recorded at the end of the file;

[0049] The encryption module is used to generate an encryption key using a user key or a basic key, and use the encryption key to encrypt the written file and store it in the configured data storage path; read the file buffer class information by calling the synchronous read function, encrypt the buffer class information using the MD5 encryption method, and store the encrypted MD5 value for MD5 value comparison when reading file data, wherein the obfuscated data and MD5 value are stored in the memory or server.

[0050] Furthermore, the embodiment of the present invention also provides an Electron data decryption and reading method for decrypting and reading the above-mentioned encrypted storage data, see Figure 5 As shown, the decryption reading process includes the following:

[0051] S201. Obtain the data storage root directory and intermediate directory configured by the user's Electron application, and obtain the corresponding storage file name and data storage path according to the data type and data source;

[0052] S202, calling the directory synchronization check function to check whether the generated data storage path exists. If the data storage path exists, using the user key or the basic key to decrypt the file under the data storage path and obtain the first MD5 value;

[0053] S203, reading the file buffer information by calling the synchronous reading function, encrypting the buffer information by using the MD5 encryption method, and obtaining a second MD5 value of the encryption process;

[0054] S204. Compare the second MD5 value with the first MD5 value. If the comparison results are consistent, call the synchronous reading function to read the file information, and remove the obfuscated data in the file information according to the obfuscated data insertion position to obtain the original stored data. If the comparison results are inconsistent, the file is tampered with and the data is discarded.

[0055] Decryption is the reverse process of encryption. In actual use, see Figure 6 As shown, after opening the Electron application, get the configuration storage directory, such as 'savepath', to get the storage directory savepath; intermediate directory mpath, if the user is logged in, generate the directory intermediate value "userA" according to the user ID, mpath = "userA"; if the user is not logged in, generate the directory intermediate value "op", mpath = "op"; the data type data to be obtained, according to the data type and data source, distinguish the data type, which type it belongs to. According to the data type to be stored, get the corresponding storage file name, such as datafile.et, use savepath+mpath+dataname.et to get datapath; use node's fs.existsSync(path:PathLike) method to check whether datapath exists. If it does not exist, it means that no data storage has been performed before; if the file exists, if the user is not logged in, the basic key A needs to be used. If the user logs in, get the user ID uid, use node's crypto.createHamc('sha512', user ID uid) to generate hash, use hash.update(base key A) to update hash, and use hash.digest('hex') to generate key C. For details, see the attached Figure 3. Use openssl to decrypt the file through the shell, openssl enc -k the key generated above -d-aes256-indatapath file -out datapathet file, and delete the datapath file after completion. For details, please refer to the attached Figure 6 . Get the MD5 value of the file datapathet, for example, the MD5 value is md5value; use node's fs.readFileSync(path:PathLike|number, options?:{encoding?:null; flag?:string;}|null) to read the datapathet file as buffer information; after reading the buffer information, use node's crypto.createHash('md5') to create a Hash instance, use hash.update(buffer, 'utf8') to generate the calculated hash for the binary of the file, and finally use hash.digest('hex') to generate the MD5 value, for example, the MD5 value is md5calcvalue; The generated md5calcvalue is compared with the previously saved md5value. If the values ​​are inconsistent, it means that the file is considered to be tampered with, and the data is discarded; if the md5calcvalue is compared with the previously saved md5value, and the values ​​are consistent, it means that the stored data can be used. Use node's fs.readFileSync(path:PathLike|number, options?:{encoding?:null; flag?:string;}|null) to get the file information, such as filecontent; get the obfuscated data from the memory or server, and get the obfuscated data insertion position from the end of filecontent; remove the obfuscated data in filecontent according to the obfuscated data insertion position; and get the original stored data data.

[0056] Furthermore, based on the above method, an embodiment of the present invention also provides an Electron data decryption and reading system, comprising: a path acquisition module, a path detection module, an information reading module and a data recovery module, wherein:

[0057] The path acquisition module is used to obtain the data storage root directory and intermediate directory configured by the user's Electron application, and obtain the corresponding storage file name and data storage path according to the data type and data source;

[0058] A path detection module is used to check whether the generated data storage path exists by calling a directory synchronization check function. If the data storage path exists, the user key or the basic key is used to decrypt the file under the data storage path and obtain the first MD5 value;

[0059] The information reading module is used to read the file buffer information by calling the synchronous reading function, encrypt the buffer information by using the MD5 encryption method, and obtain the second MD5 value of the encryption process;

[0060] The data recovery module is used to compare the second MD5 value with the first MD5 value. If the comparison results are consistent, the synchronous reading function is called to read the file information, and the obfuscated data in the file information is removed according to the obfuscated data insertion position to obtain the original stored data. If the comparison results are inconsistent, the file has been tampered with and the data is discarded.

[0061] Unless otherwise specifically stated, the relative steps, numerical expressions and values ​​of the components and steps set forth in these embodiments do not limit the scope of the present invention.

[0062] Based on the above method and / or system, an embodiment of the present invention also provides a server, including: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the above method.

[0063] Based on the above method and / or system, an embodiment of the present invention further provides a computer-readable medium having a computer program stored thereon, wherein the above method is implemented when the program is executed by a processor.

[0064] In all examples shown and described herein, any specific values ​​should be interpreted as merely exemplary and not as limiting, and thus other examples of the exemplary embodiments may have different values.

[0065] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0066] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims

1. An Electron data decryption and reading method, characterized in that: It is used to decrypt and read the encrypted data stored in the user's Electron application. The decryption and reading process includes the following: Get the data storage root directory and intermediate directory configured by the user's Electron application, and get the corresponding storage file name and data storage path according to the data type and data source; Call the directory synchronization check function to check whether the generated data storage path exists. If the data storage path exists, use the user key or the basic key to decrypt the file under the data storage path and obtain the first MD5 value; Read the file buffer information by calling the synchronous reading function, encrypt the buffer information using the MD5 encryption method, and obtain the second MD5 value of the encryption process; The second MD5 value is compared with the first MD5 value. If the comparison results are consistent, the synchronous reading function is called to read the file information, and the obfuscated data in the file information is removed according to the obfuscated data insertion position to obtain the original stored data. If the comparison results are inconsistent, the file has been tampered with and the data is discarded; The encryption storage process of the user's Electron application encrypts and stores data, including: Configure the data storage root directory and intermediate directory of the user's Electron application, and generate the corresponding storage file name and data storage path according to the data type and data source; Call the directory synchronization check function to check whether the generated data storage path exists, and write the file based on the check result. In the process of writing the file, the obfuscated data is inserted into the data to be stored, and the data insertion position is recorded at the end of the file; Generate an encryption key using a user key or a basic key, and use the encryption key to encrypt the written file and store it in the configured data storage path; read the file buffer class information by calling the synchronous read function, encrypt the buffer class information using the MD5 encryption method, and store the encrypted MD5 value for MD5 value comparison when reading file data, where the obfuscated data and MD5 value are stored in the memory or server.

2. The method for decrypting and reading Electron data according to claim 1, characterized in that: Get the configured data storage intermediate directory. If the user is logged in, get the intermediate directory based on the user ID. If the user is not logged in, get the intermediate directory based on the preset characters.

3. The method for decrypting and reading Electron data according to claim 1, characterized in that: Obfuscated data is obtained from a memory or a server, and an obfuscated data insertion position is obtained from the read file information to remove the obfuscated data in the file information.

4. The method for decrypting and reading Electron data according to claim 1, characterized in that: In the configuration data storage intermediate directory, if the user is logged in, an intermediate directory is generated according to the user ID. If the user is not logged in, a preset intermediate directory is generated.

5. The method for decrypting and reading Electron data according to claim 1, characterized in that: During file writing, if the generated data storage path does not exist, the file synchronization write function is called to replace the file; if the generated data storage path exists, the file synchronization append function is called to append the file data content.

6. The method for decrypting and reading Electron data according to claim 1 or 5, characterized in that: When writing a file, the obfuscated data is generated by calling the hash salting function, and the generated obfuscated data is inserted into the data to be stored.

7. The method for decrypting and reading Electron data according to claim 1, characterized in that: In generating the encryption key, if the user is not logged in, the preset basic key is used as the encryption key. If the user is logged in, the current user ID is obtained, a hash value is generated based on the sha512 algorithm, and the built-in function of the hash class is used to update the hash value and generate the encryption key. Based on the encryption key, the file is encrypted and stored in the data storage path through the shell.

8. An Electron data decryption and reading system, characterized in that: The method according to claim 1 is implemented, comprising: a path acquisition module, a path detection module, an information reading module and a data recovery module, wherein: The path acquisition module is used to obtain the data storage root directory and intermediate directory configured by the user's Electron application, and obtain the corresponding storage file name and data storage path according to the data type and data source; A path detection module is used to check whether the generated data storage path exists by calling a directory synchronization check function. If the data storage path exists, the user key or the basic key is used to decrypt the file under the data storage path and obtain the first MD5 value; The information reading module is used to read the file buffer information by calling the synchronous reading function, encrypt the buffer information by using the MD5 encryption method, and obtain the second MD5 value of the encryption process; The data recovery module is used to compare the second MD5 value with the first MD5 value. If the comparison results are consistent, the synchronous reading function is called to read the file information, and the obfuscated data in the file information is removed according to the obfuscated data insertion position to obtain the original stored data. If the comparison results are inconsistent, the file has been tampered with and the data is discarded.

Citation Information

Patent Citations

  • Hybrid encrypted communication method for digital workshop information security

    CN109150789A

  • Data transmission method, system and device and computer readable storage medium

    CN111913817A