WO2022028289A1 - 数据加密方法、数据解密方法、装置、终端和存储介质 - Google Patents

数据加密方法、数据解密方法、装置、终端和存储介质 Download PDF

Info

Publication number
WO2022028289A1
WO2022028289A1 PCT/CN2021/108935 CN2021108935W WO2022028289A1 WO 2022028289 A1 WO2022028289 A1 WO 2022028289A1 CN 2021108935 W CN2021108935 W CN 2021108935W WO 2022028289 A1 WO2022028289 A1 WO 2022028289A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
execution environment
target
application
trusted execution
Prior art date
Application number
PCT/CN2021/108935
Other languages
English (en)
French (fr)
Inventor
李岩
Original Assignee
百果园技术(新加坡)有限公司
李岩
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 百果园技术(新加坡)有限公司, 李岩 filed Critical 百果园技术(新加坡)有限公司
Priority to US18/040,796 priority Critical patent/US20240031129A1/en
Priority to EP21852390.0A priority patent/EP4195583A4/en
Publication of WO2022028289A1 publication Critical patent/WO2022028289A1/zh

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/06Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols the encryption apparatus using shift registers or memories for block-wise or stream coding, e.g. DES systems or RC4; Hash functions; Pseudorandom sequence generators
    • H04L9/0618Block ciphers, i.e. encrypting groups of characters of a plain text message using fixed encryption transformation
    • H04L9/0631Substitution permutation network [SPN], i.e. cipher composed of a number of stages or rounds each involving linear and nonlinear transformations, e.g. AES algorithms
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/08Key distribution or management, e.g. generation, sharing or updating, of cryptographic keys or passwords
    • H04L9/0894Escrow, recovery or storing of secret information, e.g. secret key escrow or cryptographic key storage
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/08Key distribution or management, e.g. generation, sharing or updating, of cryptographic keys or passwords
    • H04L9/0861Generation of secret information including derivation or calculation of cryptographic keys or passwords
    • H04L9/0863Generation of secret information including derivation or calculation of cryptographic keys or passwords involving passwords or one-time passwords
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/50Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
    • G06F21/52Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems during program execution, e.g. stack integrity ; Preventing unwanted data erasure; Buffer overflow
    • G06F21/53Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems during program execution, e.g. stack integrity ; Preventing unwanted data erasure; Buffer overflow by executing in a restricted environment, e.g. sandbox or secure virtual machine
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/602Providing cryptographic facilities or services
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/08Key distribution or management, e.g. generation, sharing or updating, of cryptographic keys or passwords
    • H04L9/0861Generation of secret information including derivation or calculation of cryptographic keys or passwords
    • H04L9/0869Generation of secret information including derivation or calculation of cryptographic keys or passwords involving random numbers or seeds
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/08Key distribution or management, e.g. generation, sharing or updating, of cryptographic keys or passwords
    • H04L9/0861Generation of secret information including derivation or calculation of cryptographic keys or passwords
    • H04L9/0877Generation of secret information including derivation or calculation of cryptographic keys or passwords using additional device, e.g. trusted platform module [TPM], smartcard, USB or hardware security module [HSM]

Definitions

  • the embodiments of the present application relate to security technologies, for example, to a data encryption method, a data decryption method, an apparatus, a terminal, and a storage medium.
  • an algorithm such as a symmetric key algorithm and an asymmetric key algorithm is usually used to encrypt the data.
  • Embodiments of the present application provide a data encryption method, a data decryption method, an apparatus, a terminal, and a storage medium, so as to improve the security of data in a mobile terminal while maintaining the computing overhead and storage overhead.
  • an embodiment of the present application provides a data encryption method, including:
  • reference data corresponding to the source data, where the reference data is one-time-use data in the process of encrypting the source data
  • the source data is encrypted by using the secure data to obtain target data.
  • an embodiment of the present application also provides a data decryption method, including:
  • read reference data associated with the target data where the reference data is one-time use data in the process of decrypting the target data
  • the target data is decrypted using the secure data to obtain source data.
  • an embodiment of the present application also provides a data encryption device, including:
  • the source data determination module is set to determine the encrypted source data requested by the application in the untrusted execution environment
  • a reference data generation module configured to generate reference data corresponding to the source data in the untrusted execution environment, where the reference data is one-time use data in the process of encrypting the source data;
  • a master key reading module configured to read the master key generated for the application in a trusted execution environment
  • a secure data generation module configured to perform encryption processing on the reference data by using the master key in the trusted execution environment to obtain secure data
  • the source data encryption module is configured to encrypt the source data by using the secure data in the untrusted execution environment to obtain target data.
  • an embodiment of the present application also provides a data decryption device, including:
  • the target data determination module is set to determine the target data requested to be decrypted by the application in an untrusted execution environment
  • a reference data reading module configured to read reference data associated with the target data in the untrusted execution environment, where the reference data is one-time use data in the process of decrypting the target data;
  • a master key reading module configured to read the master key generated for the application in a trusted execution environment
  • a secure data generation module configured to perform encryption processing on the reference data by using the master key in the trusted execution environment to obtain secure data
  • the target data decryption module is configured to decrypt the target data by using the secure data in the untrusted execution environment to obtain source data.
  • an embodiment of the present application further provides a mobile terminal, where the mobile terminal includes:
  • processors one or more processors
  • memory arranged to store one or more programs
  • the one or more processors are configured to execute the one or more programs to implement the data encryption method as described in the first aspect or the data decryption method as described in the second aspect.
  • embodiments of the present application further provide a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the data described in the first aspect is implemented The encryption method or the data decryption method as described in the second aspect.
  • FIG. 1 is a flowchart of a data encryption method provided in Embodiment 1 of the present application.
  • FIG. 2 is a schematic diagram of the environment of a mobile terminal according to Embodiment 1 of the present application;
  • Embodiment 3 is a schematic flowchart of an encryption provided by Embodiment 1 of the present application.
  • FIG. 4 is an example diagram of a KGF algorithm provided in Embodiment 1 of the present application.
  • FIG. 5 is a schematic diagram of encryption of a kind of AES provided by Embodiment 1 of the present application.
  • FIG. 6 is a flowchart of a data encryption method provided in Embodiment 2 of the present application.
  • FIG. 7 is a flowchart of a data decryption method provided in Embodiment 3 of the present application.
  • FIG. 8 is a schematic flowchart of a decryption provided in Embodiment 3 of the present application.
  • FIG. 9 is a schematic diagram of decryption of a kind of AES provided by Embodiment 3 of the present application.
  • FIG. 10 is a schematic structural diagram of a data encryption device according to Embodiment 4 of the present application.
  • FIG. 11 is a schematic structural diagram of a data decryption apparatus according to Embodiment 5 of the present application.
  • FIG. 12 is a schematic structural diagram of a mobile terminal according to Embodiment 6 of the present application.
  • the key of the application is mainly pre-buried in the code of the application in a hard-coded manner, such as the Java layer and the Native layer of Android (Android).
  • code obfuscation mechanisms such as OLLVM (Obfuscator-LLVM)
  • OLLVM is an open source code obfuscation compiler that obfuscates the code logic to improve the difficulty of reverse reading the code. .
  • the key does not have any separate security protection, and only depends on the security reinforcement of the code. It is often easy to extract the key by static analysis of the attacker, and the attacker can easily obtain the authority through the vulnerability of the mobile terminal.
  • the pre-embedded keys of the same version of the application or all versions of the application are the same, and the attacker can export the data from one application and put it in another Data decryption is performed on a cracked application, that is, the data can still be decrypted after leaving the mobile terminal.
  • the embodiments of the present application disclose a data encryption method, a data decryption method, a device, a terminal, and a storage medium, which can better cope with such data security risks.
  • FIG. 1 is a flowchart of a data encryption method provided in Embodiment 1 of the present application.
  • a one-time key can be used to encrypt data
  • the method can be performed by a data encryption device
  • the data encryption device can be performed by
  • Software and/or hardware implementation can be configured in mobile terminals, such as mobile phones, tablet computers, smart wearable devices, etc., and smart wearable devices such as smart glasses, smart watches, and the like.
  • the mobile terminal includes the following two environments:
  • the untrusted execution environment is a common environment for mobile terminals, running a common operating system (Operating System, OS), such as Android (Android), iOS, Linux, etc., and the untrusted execution environment is the upper third-party application (application). , APP) to provide services.
  • OS Operating System
  • Android Android
  • iOS iOS
  • Linux Linux
  • APP third-party application
  • Untrusted execution environments have certain security risks. For example, application isolation based on OS can be easily bypassed. The OS code is huge and prone to bugs. The OS can see the data inside the application. The lack of isolation means that the application cannot be secured. Store keys, sensitive data.
  • the trusted execution environment is a security area on the processor in the mobile terminal, and the trusted execution environment provides an execution environment that is isolated from the untrusted execution environment and independently runs a trusted operating system (Trusted OS).
  • Trusted OS trusted operating system
  • Isolation is an essential attribute of a trusted execution environment. Isolation can be implemented through software or hardware. More software, hardware, Internet Protocol (IP), and bus integrated security mechanisms can be applied in an isolated environment. .
  • IP Internet Protocol
  • the untrusted execution environment cannot directly access the trusted execution environment, but it can be used as a client of the trusted execution environment through the Application Programming Interface (Application Programming Interface). , API) to request security services from the Trusted OS of the Trusted Execution Environment.
  • Application Programming Interface Application Programming Interface
  • the Trusted Execution Environment is standardized by Global Platform (GP) and can be transplanted on various platforms.
  • GP Global Platform
  • GP defines the Protection Profile of the Trusted Execution Environment and defines the required hardware protection strength.
  • the Trusted Execution Environment uses a secure storage mechanism for keys to ensure authentication, integrity and confidentiality.
  • the trusted execution environment can support secure loading and execution of multiple trusted applications (TAs) at the same time.
  • the TAs are isolated from each other to ensure the confidentiality and integrity of the code and data loaded into the trusted execution environment.
  • Trusted OS Provide the internal API (Internal API) in the trusted execution environment to provide services for the TA.
  • the trusted execution environment is also different.
  • the trusted execution environment is Secure Enclave
  • the trusted execution environment is TEE (Trusted Execution Environment)
  • the non-trusted execution environment is REE (Rich Execution Environment).
  • the method includes the following steps:
  • Install one or more applications (APP) in an untrusted execution environment such as REE
  • the application can be a general-purpose operating system application, or a third-party application, such as camera application, browser, email, note-taking Books, contacts, shopping applications, short video applications, etc.
  • the general operating system may also be recorded as an untrusted operating system, for example, Android, iOS, Linux, and the like.
  • data of different security levels will be generated. These data are usually plaintext, and some or all of the data to be generated and stored due to factors such as high security levels and business requirements can be used as source data. , waiting for encryption.
  • the form of the source data can be different.
  • a browser when a user logs in to a website with an account and password (also known as a password), the browser can record the account and password, and the website will return a cookie after the account and password are successfully verified.
  • the account, password and cookie can be used as source Data encrypted storage.
  • the user records some pending items, and these items can be encrypted and stored as source data.
  • the user For another example, for the address book, the user records contact information, such as name, mobile phone number, avatar, etc. Under normal circumstances, the user can browse the contact information after unlocking the mobile terminal, and other applications can read the contact information under authorization. For some relatively private contact information, it can be encrypted and stored as source data.
  • the above applications and the source data to be encrypted corresponding to the applications are only examples.
  • other applications and the source data to be encrypted corresponding to other applications may be set according to the actual situation, for example, user identity information, payment information, Audio and video data, etc.
  • those skilled in the art can also use other applications and source data to be encrypted according to actual needs.
  • the data valid in this encryption can be generated for the source data in the untrusted execution environment as reference data .
  • the so-called valid data in the current encryption refers to data that is unique to the operation of the encrypted source data this time, that is, the reference data is one-time data and is not reused.
  • a value Nonce may be randomly generated by means of a rand() function, etc., as reference data.
  • the length of the random value Nonce can be 32 bytes or greater.
  • the current timestamp Timestamp can be read from the general operating system through functions such as Calendar.getInstance() and new Time() as reference data.
  • the random value Nonce and timestamp Timestamp in the above two methods can be used alone or in combination. When used in combination, the overall collision resistance and forwardness of the encryption mechanism of this embodiment can be guaranteed.
  • references data for example, performing operations such as offset and XOR on randomly generated data, and mapping the current timestamp through a preset mapping function.
  • a key is set for applications in an untrusted execution environment (such as REE).
  • the master key SK can be used to generate secure data encrypted for the source data this time.
  • An application exists in the untrusted execution environment, and a master key SK corresponding to the application exists in the trusted execution environment.
  • the application identification and reference data can be sent to a trusted execution environment (such as TEE) through the API provided by the trusted execution environment (such as TEE) , request the TA in the trusted execution environment (such as TEE) to use the reference data to generate secure data, and use the secure data to encrypt the source data.
  • a trusted execution environment such as TEE
  • TEE trusted execution environment
  • the TA in the trusted execution environment can look up the master key SK to which the identifier of the application is mapped in the database.
  • the TA provides a key generation function KGF (Key Generation Function), which can be used to generate security data.
  • KGF Key Generation Function
  • data such as The random numerical value Nonce and the timestamp (Timestamp) are used as input
  • the reference data is encrypted with the master key SK
  • the output data after the encryption is set as secure data.
  • the security data is applied to the symmetric key algorithm, and the security data contains at least the key.
  • the key in the security data is called the secondary key.
  • the security data is based on the symmetric key algorithm. different, can also contain other data.
  • the encryption processing performed on the reference data may also include other operations to improve security, for example, adding data of other dimensions, performing XOR operations, performing offset operations, and so on.
  • S104 may include the following steps, step 1, step 2 and step 3.
  • the three steps are as follows:
  • Step 1 In a trusted execution environment, combine the reference data with a preset tag to obtain a target array.
  • a developer can customize a character string as a label and store it in a trusted execution environment (such as TEE) of the mobile terminal.
  • TEE trusted execution environment
  • the label Label is the artificial name of the one-time security data to be generated.
  • the label Label can be used to indicate the type of security data, increase the dimension of the input data to improve security, and also facilitate developers to memorize and reduce misoperation of security data. .
  • the secret indicates that the type of the security data is a key, and for the convenience of distinction, the key may be called a secondary key.
  • iv indicates that the type of security data is secondary key, vector.
  • TA is expressed in the form of encoder Encoder, and the reference data (such as random value Nonce, timestamp Timestamp), label Label are glued into a Hex array according to the established order, as the target array M.
  • reference data such as random value Nonce, timestamp Timestamp
  • M Nonce
  • Step 2 In the trusted execution environment, use the master key to encrypt the target array to obtain candidate data.
  • the secure cryptographic functions provided by TEE include HMAC (Hash-based Message Authentication Code, key-related hash operation) algorithm, AES (Advanced Encryption Standard, Advanced Encryption Standard) algorithm, RSA Encryption algorithm, ECDSA (Elliptic Curve Digital Signature Algorithm, Elliptic Curve Digital Signature Algorithm) signature algorithm, RSA signature algorithm, etc.
  • HMAC Hash-based Message Authentication Code, key-related hash operation
  • AES Advanced Encryption Standard
  • RSA Encryption algorithm RSA Encryption algorithm
  • ECDSA Elliptic Curve Digital Signature Algorithm, Elliptic Curve Digital Signature Algorithm
  • RSA signature algorithm etc.
  • the calculation speed of HMAC and AES is relatively fast, and these two security cryptographic functions can be selected.
  • Step 3 In the trusted execution environment, normalize the candidate data into data of a specified length, and use the data of the specified length as the security data matching the tag.
  • TA takes the form of a Regulator.
  • the regularizer Regulator takes the candidate data T as input, and calculates and outputs a character string with a specified length as a one-time Security data, the type of the security data is defined by the label Label.
  • the regularizer Regulator can use the one-way hash function to regularize the candidate data into secure data, that is, the output string is the digest data, the one-way hash function can be recorded as Hash(T), and the one-way hash function can calculate any arbitrary Length data, generate L-byte fixed-length digest information B 0 B 1 B 2 ...B L-2 B L-1 , L is a positive integer, for example, MD5 (Message Digest Algorithm, fifth edition of message digest algorithm) can be output 16B digest data, SHA (Secure Hash Algorithm, Secure Hash Algorithm) 1 output 20B digest data, SHA224 output 28B digest data, SHA256 output 32B digest data, SHA384 output 48B digest data, SHA512 output 64B digest data ,etc.
  • MD5 Message Digest Algorithm, fifth edition of message digest algorithm
  • secure data includes a secondary key (One-Time Key), or, a secondary key and a vector (One-Time IV).
  • a one-way hash function is used to calculate the digest data of the first specified length on the candidate data, and the digest data of the first specified length is used as a secondary Key (One-Time Key), vector (One-Time IV), the secondary key and vector are suitable for the AES algorithm in the symmetric key algorithm.
  • the trusted execution environment In response to the label being the second value (such as secret), in the trusted execution environment (such as TEE), use a one-way hash function to calculate the digest data of the second specified length on the candidate data, and the digest data of the second specified length is used as a secondary Key (One-Time Key), the secondary key is suitable for non-AES algorithms in this symmetric key algorithm, such as RC4, Chacha20, etc.
  • S105 in an untrusted execution environment, encrypt the source data by using the secure data to obtain the target data.
  • the security data is output to the untrusted execution environment (such as REE),
  • the source data is encrypted using a symmetric key algorithm, and the encrypted ciphertext is the target data.
  • source data 301 and target data 302 are shown.
  • secure data includes a secondary key (One-Time Key), or, a secondary key and a vector (One-Time IV).
  • the AES algorithm in the symmetric key algorithm is invoked, the vector is used as an initialization vector (Initialization Vector, IV), and the source data is encrypted into the target data together with the secondary key.
  • Initialization Vector IV
  • CBC Cipher Block Chaining
  • block encryption is implemented, and the source data is divided into multiple plaintext blocks, such as plaintext block 0, plaintext block 1... .
  • plaintext block After XOR processing the plaintext block and the encrypted vector, the encryptor uses the secondary key to encrypt, and outputs the ciphertext block.
  • the ciphertext block can be a binary array, such as ciphertext block 0, ciphertext block 1.
  • the target data is obtained.
  • the encryption vector belongs to the initialization vector IV, which is the vector in the secure data
  • the encryption vector is the nth -1 ciphertext block, n>1.
  • a non-AES algorithm in a symmetric key algorithm is invoked, and a secondary key is used to encrypt the source data into the target data.
  • non-AES algorithms such as RC4, Chacha20 and so on.
  • encryption algorithms and security parameters are only examples, and other encryption algorithms and their security parameters may be set according to actual conditions when implementing the embodiments of the present application.
  • the source data requested by the application to be encrypted is determined, and the reference data corresponding to the source data is generated, and the reference data is the one-time use data in the process of encrypting the source data;
  • the trusted execution environment read the master key generated for the application, and use the master key to encrypt the reference data to obtain secure data; in the untrusted execution environment, use the secure data to encrypt the source data to obtain the target data.
  • the trusted execution environment is implemented based on a hardware-level security chip, and it is difficult for an attacker to break through the security chip, so that the security strength of the trusted execution environment is high, and the security of the master key and security data can be guaranteed.
  • the master key is generated for the application, so that the master keys used by the same version of the application or all versions of the application are different, and the reference data is valid in this encryption and decryption, so that the security data generated based on the master key and the reference data is valid. It has a one-time feature.
  • the one-time security data is not stored directly, but is generated in a trusted execution environment, which satisfies the security of Chosen-Plaintext Attack (CPA), and cannot be reversely cracked.
  • CPA Chosen-Plaintext Attack
  • the trusted execution environment implements mandatory access control protection, and the trusted execution environment cannot be directly accessed by the non-trusted execution environment, the attacker cannot call the function that activates the master key to decrypt the data to prevent illegal call attacks. The goal.
  • the computational overhead in the trusted execution environment can be guaranteed to be low; in an untrusted execution environment, based on a processor with higher performance than a secure chip .
  • the trusted execution environment is an operating environment of an independent security chip
  • the untrusted execution environment is an operating environment on other hardware different from the security chip.
  • the security chip may be a separate hardware chip dedicated to the trusted execution environment.
  • the untrusted execution environment runs on mobile phone hardware other than the security chip, such as mobile phone memory, central processing unit, memory card, etc., but not a separate chip.
  • Trusted execution environments and untrusted execution environments are deployed in most mobile terminals, and the cryptographic algorithms provided by mobile terminals are reusable, so that the compatibility is within an acceptable level, and there is no need to deploy additional library files. Low storage overhead.
  • the application uses white-box cryptography to encrypt and store the key.
  • White-box cryptography refers to cryptographic technologies that can resist white-box attacks, while white-box attacks mean that attackers have complete control over the mobile terminal and can observe and change the internal data when the program is running. This attack environment is called white-box attack. Box attack environment.
  • White-box cryptography usually uses the AES algorithm, which can ensure the encryption and decryption of sensitive data without the keys appearing in plaintext, improving the security of key storage, and is suitable for mobile terminal scenarios.
  • white-box cryptography can solve the threat situation that the key is statically analyzed and extracted by reverse code, it still cannot solve the shortcomings of the hard-coded key in the code method, that is, using the upper-level function code to directly call the function that activates the key, The data is decrypted directly; the data can still be decrypted when it leaves the mobile terminal.
  • the library of white-box cryptography requires about 350KB of storage space, adding at least 350KB to the installation package storage of the application, which is unbearable for some applications that are sensitive to the size of the installation package.
  • the mobile terminal deployment uses the trusted execution environment based on the security chip.
  • the trusted execution environment is an area on the central processing unit (Central Processing Unit, CPU).
  • the function of the trusted execution environment is to provide a more efficient execution environment for data and code.
  • the Secure Enclave used by the iOS system is a trusted execution environment. After the Android system is 6.0+ and API Level 23+, the Android system also requires mobile terminals to deploy a trusted execution environment TEE and secure hardware chips.
  • Some encryption methods use the AES encryption service based on the trusted execution environment of the hardware security chip, and directly encrypt and store some sensitive personal data, such as face model parameters, bank card information, etc.
  • the security chip is an independent piece of hardware with high cost and limited computing power. Using the encryption service of the trusted execution environment to directly encrypt a large amount of data and files, the efficiency is low and the time overhead is high.
  • test results show that for 100KB data, the time overhead of using TEE's AES-128 encryption and decryption is 6.2 seconds, and the time overhead of TEE's RSA-2048 encryption and decryption is 45 seconds.
  • personal sensitive data may include large audio and video files, and the time overhead corresponding to large files or data encryption is too high to bear.
  • TEE's encryption and decryption services cannot directly support CPA security.
  • Supporting CPA security can be expressed as, two pieces of plaintext with the same content can be encrypted to obtain two pieces of ciphertext with different contents. Therefore, it is necessary to call the key generation and storage service of the TEE once before each encryption, which increases the time overhead.
  • the security strength of the security chip is higher than that of AES-128; Android 6.0 API 23+ and any supported cryptographic algorithms can be used, which makes the compatibility better and is acceptable to the product.
  • this embodiment has excellent performance in security strength, overall security, data leaving the device failure, computing overhead, and storage overhead.
  • Embodiment 6 is a flowchart of a data encryption method provided in Embodiment 2 of the present application. This embodiment is based on the foregoing embodiments. The method described in the embodiment comprises the following steps:
  • the first operation of installing an application in an untrusted execution environment can be monitored by calling a function of the general-purpose operating system, that is, the first operation is also called an installation operation.
  • the Android operating system when an application is installed, the Android operating system will send a broadcast. Based on the broadcast mechanism, a broadcast indicating that the application is installed can be defined. The broadcast information can be used for the application to be installed, and the application is represented by a package name. The broadcast indicating the installation of the application can be registered in the AndroidManifest, and if the broadcast indicating the installation of the application is received, it indicates that the operation of installing the application in an untrusted execution environment (such as REE) is detected.
  • an untrusted execution environment such as REE
  • this embodiment when the installation package of the application is executed, it can be considered as detecting the first operation of installing the application in an untrusted execution environment (eg, REE).
  • REE untrusted execution environment
  • the key generation and storage services in the trusted execution environment can be called through the API provided by the trusted execution environment (such as TEE), and a
  • the random key is used as the master key SK
  • the master key SK is stored for a long time in the trusted execution environment (such as TEE), that is, the identity of the application (such as the package) is established in the database of the trusted execution environment (such as TEE).
  • TEE trusted execution environment
  • the master key SK may use any one of HMAC, AES, RSA, ECDSA and other algorithms, and may also be selected according to the subsequent algorithm for encrypting the source data.
  • the key length of HMAC is generally greater than or equal to 16 bytes
  • the key length of AES is generally greater than or equal to 16 bytes
  • the key length of RSA is generally greater than or equal to 256 bytes, so as to ensure the minimum equivalent to the mainstream of AES-128.
  • the security strength of commercial ciphers is generally greater than or equal to 16 bytes.
  • an untrusted execution environment such as REE
  • REE untrusted execution environment
  • the reference data used in this encryption is also stored, and an association relationship between the target data and the reference data is established, and the association relationship indicates that the reference data is used to encrypt the target data.
  • the storage structure between the target data and the reference data can be defined independently.
  • the source data can be encrypted with a random value Nonce and timestamp Timestamp to obtain the target data C.
  • the fixed-length Nonce and Timestamp can be used as the file header and the target data C. Write them together, that is, Nonce
  • the user will actively request to delete part of the target data, or the application will automatically delete its own target data, or a third-party application (such as a cleaning application) will also request to delete the target data of the application.
  • a third-party application such as a cleaning application
  • the cookie in the browser is encrypted as the source data as the target data, and the browser is set up to automatically clear the expired cookie mechanism. After the browser detects that the cookie has expired, it deletes the cookie, that is, deletes the target data accordingly.
  • the item recorded in the notepad is encrypted as the source data as the target data. After the user finds that the item has been processed, he deletes the item in the notepad, that is, the target data is deleted accordingly.
  • the contact information in the address book is encrypted as the source data as the target data, and after detecting the existence of the same contact information, the cleaning application deletes one contact information in the same contact information, that is, deletes the target accordingly. data.
  • the corresponding target data can be searched in an untrusted execution environment (such as REE), and the target data can be deleted. After deleting the target data, the reference data becomes invalid. The reference data mapped by the target data is located, and the reference data is deleted along with the target data, so as to ensure that the invalid data is cleaned up in time and reduce the storage overhead.
  • REE untrusted execution environment
  • invalidation means that after the target data associated with the reference data is deleted, other target data cannot be decrypted using the master key and the reference data.
  • the third operation of uninstalling an application in an untrusted execution environment can be monitored by calling a function of the general-purpose operating system, that is, the third operation is also called an uninstall operation.
  • the Android operating system when an application is uninstalled, the Android operating system will send a broadcast. Based on the broadcast transmission mechanism, a broadcast indicating the installation of the application can be defined. If the broadcast is uninstalled, the application can be represented by the package name. The broadcast indicating uninstalling the application can be registered in the AndroidManifest. If the broadcast indicating uninstalling the application is received, it means that the operation of uninstalling the application in an untrusted execution environment (such as REE) is detected.
  • an untrusted execution environment such as REE
  • the master key, target data and reference data become invalid, and are not retained in the mobile terminal as configuration files, ensuring that invalid data is cleaned up in time and reducing storage overhead.
  • invalidation means that after uninstalling the application, if the same application is reinstalled, a new master key will be regenerated, new reference data and new target data will be regenerated for the same source data, and the new master key will be regenerated.
  • the key and the new reference data cannot decrypt the original target data.
  • target data and reference data corresponding to the uninstalled application may be deleted.
  • FIG. 7 is a flowchart of a data decryption method provided in Embodiment 3 of the present application.
  • a one-time key is used to decrypt data
  • the method can be executed by a data decryption device
  • the data decryption device can be executed by software and/or hardware implementation, which can be configured in mobile terminals, such as mobile phones, tablet computers, smart wearable devices (such as smart glasses, smart watches, etc.), etc.
  • the mobile terminal includes untrusted execution environment, trusted execution environment
  • the method includes the following steps:
  • One or more applications are installed in an untrusted execution environment (such as REE), and the applications will request to use corresponding data according to different business requirements during the running process.
  • REE untrusted execution environment
  • the data is stored in the untrusted execution environment (such as REE) in the form of ciphertext, which is called target data.
  • the data can be read from the untrusted execution environment (such as REE).
  • Target data waiting to be decrypted.
  • target data is obtained by encrypting the reference data, and the target data is stored in an untrusted execution environment (eg, REE) in association with the reference data.
  • REE untrusted execution environment
  • the reference data corresponding to the target data can be searched based on the association relationship from an untrusted execution environment (eg, REE).
  • an untrusted execution environment eg, REE
  • the reference data is valid for this decryption
  • the valid data for this decryption refers to data that is unique to the operation of the decrypted target data this time, that is, the reference data is one-time data and is not reused.
  • the reference data is a time stamp when a numerical Nonce is randomly generated and/or the target data is encrypted.
  • the storage structure between the target data and the reference data can be defined independently.
  • the reference data can be read according to the storage structure.
  • the fixed-length Nonce and Timestamp can be written as the file header and the target data C during storage.
  • C when decrypting, you can first read the fixed-length string of the file header as Nonce and Timstamp, and the remaining strings are C; or, when storing, you can use the fixed-length Nonce and Timestamp as the The end of the file is written together with the target data C, that is, C
  • the fixed-length string at the end of the file can be read first as Nonce and Timstamp, and the remaining string is C.
  • the API provided by the trusted execution environment can be used to send the identification of the application and the reference data to the trusted execution environment (such as TEE).
  • the TA in the trusted execution environment eg TEE
  • the TA in the trusted execution environment is requested to use the reference data to generate secure data, and use the secure data to decrypt the target data.
  • the TA in the trusted execution environment can look up the master key SK to which the identifier of the application is mapped in the database.
  • the TA provides a key generation function KGF, which can be used to generate secure data, for which reference data (such as random values Nonce, Timestamp) is used as input, the reference data is encrypted with the master key SK, and the data output after the encryption is set as secure data.
  • KGF key generation function
  • the reference data and a preset tag are combined into a target array, where the tag is used to represent the type of security data.
  • the target array is encrypted as candidate data using the master key.
  • the candidate data is normalized into data of a specified length as security data matching the tag.
  • the type of secure data includes a secondary key, or a secondary key and a vector
  • the tag is the first value, in the trusted execution environment
  • the first specified value is calculated for the candidate data
  • the digest data of the length is used as the secondary key and the vector; or, if the tag is the second value, in the trusted execution environment, the digest data of the second specified length is calculated for the candidate data as the secondary key.
  • the digest data of the first specified length is used as the secondary key and the vector, which means that the digest data of the first specified length contains both the secondary key and the vector
  • the digest data of the second specified length is used as the secondary key, which means that the second specified length of the digest data is used as the secondary key.
  • the secondary key is included in the digest data of the specified length.
  • S705 in an untrusted execution environment, decrypt the target data by using the secure data to obtain the source data.
  • the security data is output to the untrusted execution environment (such as REE).
  • REE untrusted execution environment
  • the target data 801 is decrypted using a symmetric key algorithm
  • the decrypted plaintext is the source data 802 .
  • secure data includes a secondary key (One-Time Key), or, a secondary key and a vector (One-Time IV).
  • the AES algorithm in the symmetric key algorithm is invoked, the vector is used as the initialization vector IV, and the vector and the secondary key are used to decrypt the target data into the source data.
  • block decryption is implemented, and the target data is divided into multiple ciphertext blocks, such as ciphertext block 0, ciphertext block 1..., for each ciphertext block,
  • the decryptor After decrypting using the secondary key, the decryptor performs XOR processing on the decryption result and the encrypted vector, and outputs plaintext blocks, such as plaintext block 0, plaintext block 1....
  • the combined result after the combination of plaintext blocks is the source data.
  • the encryption vector belongs to the initialization vector IV, which is the vector in the security data, and for the nth (n>1) plaintext block (that is, plaintext block n-1),
  • the encryption vector is the n-1th ciphertext block (ie, the ciphertext block n-2), for example, the ciphertext block 0....
  • the non-AES algorithm in the symmetric key algorithm is invoked, and the secondary key is used to decrypt the target data into the source data.
  • decryption algorithms and security parameters are only examples, and other decryption algorithms and security parameters may be set according to actual conditions when implementing the embodiments of the present application.
  • decryption algorithm and its security parameters those skilled in the art can also adopt other decryption algorithms and security parameters according to actual needs.
  • the target data requested to be decrypted by the application is determined; in the untrusted execution environment, the reference data associated with the target data is read, and the reference data is to decrypt the target data
  • the trusted execution environment read the master key generated for the application; in the trusted execution environment, use the master key to encrypt the reference data to obtain secure data;
  • secure data is used to decrypt target data to obtain source data.
  • the TEE is implemented based on hardware-level security chips, and it is difficult for attackers to break through the security chips, which makes the TEE with high security strength and can ensure the security of the master key and secure data.
  • the master key is generated for the application, so that the master keys used by the same version of the application or all versions of the application are different, and the reference data is valid in this encryption and decryption, so that the security data generated based on the master key and the reference data is valid. It has a one-time feature.
  • the one-time security data is not stored directly, but is generated in a trusted execution environment, which satisfies the security of CPA and cannot be reversely cracked.
  • the trusted execution environment implements mandatory access control protection, and the trusted execution environment cannot be directly accessed by the non-trusted execution environment, the attacker cannot call the function that activates the master key to decrypt the data to prevent illegal call attacks. The goal.
  • generating secure data in a trusted execution environment due to the small amount of secure data, can ensure low computational overhead in a trusted execution environment, and in an untrusted execution environment based on processors with higher performance than secure chips, Use secure data to encrypt and decrypt source data to ensure low computational overhead in a trusted execution environment and low overall computational overhead.
  • trusted execution environments and untrusted execution environments are deployed in most mobile terminals, and the cryptographic algorithms provided by mobile terminals can be reused, so that the compatibility is within an acceptable level, and there is no need to deploy additional library files and storage overhead. small.
  • the method further includes:
  • a master key is generated for the application in the trusted execution environment.
  • the method further includes:
  • target data and reference data are stored in association.
  • the method further includes:
  • the target data and the reference data are deleted in the untrusted execution environment.
  • the method further includes:
  • FIG. 10 is a schematic structural diagram of a data encryption device provided in Embodiment 4 of the present application, and the device may include the following modules:
  • the source data determination module 1001 is configured to determine the encrypted source data requested by the application in an untrusted execution environment
  • a reference data generation module 1002 configured to generate reference data corresponding to the source data in the untrusted execution environment, where the reference data is one-time use data in the process of encrypting the source data;
  • the master key reading module 1003 is configured to read the master key generated for the application in a trusted execution environment
  • the source data encryption module 1005 is configured to encrypt the source data by using the secure data in the untrusted execution environment to obtain target data.
  • the reference data generation module 1002 includes:
  • a random value generation submodule configured to randomly generate a value in the untrusted execution environment as reference data
  • the timestamp reading submodule is configured to read the current timestamp as reference data in the untrusted execution environment.
  • the security data generation module 1004 includes:
  • a target array combination submodule configured to combine the reference data with a preset label in the trusted execution environment to obtain a target array, and the label is used to represent the type of security data;
  • a candidate data generation submodule configured to use the master key to encrypt the target array to obtain candidate data
  • the candidate data regularization submodule is configured to regularize the candidate data into data of a specified length, and use the data of the specified length as the security data matching the tag.
  • the type of the security data includes a secondary key, or, a secondary key and a vector
  • the candidate data regularization submodule includes:
  • a first digest calculation unit configured to, in the trusted execution environment, in response to the tag being a first value, calculate digest data of a first specified length for the candidate data, and the digest data of the first specified length as secondary key, vector;
  • a second digest calculation unit configured to, in the trusted execution environment, in response to the label being the second value, calculate digest data of a second specified length for the candidate data, and the digest data of the second specified length as a secondary key.
  • the security data includes a secondary key, or, a secondary key and a vector
  • the source data encryption module 1005 includes:
  • the first symmetric encryption sub-module is configured to, in the untrusted execution environment, call the Advanced Encryption Standard AES algorithm in the symmetric key algorithm, use the vector as an initialization vector, and combine the secondary key with the AES algorithm.
  • the source data is encrypted into the target data;
  • the second symmetric encryption submodule is configured to, in the untrusted execution environment, invoke the non-AES algorithm in the symmetric key algorithm, and use the secondary key to encrypt the source data into target data.
  • an installation operation detection module configured to detect a first operation of installing an application in an untrusted execution environment
  • a master key generation module configured to generate a master key for the application in a trusted execution environment in response to the first operation.
  • An associative storage module is configured to associate and store the target data and the reference data in the untrusted execution environment.
  • a deletion operation detection module configured to detect and delete the second operation of the target data
  • An association deletion module configured to delete the target data and the reference data in the untrusted execution environment in response to the second operation.
  • an uninstall operation detection module configured to detect a third operation of uninstalling the application
  • a master key deletion module configured to delete the master key generated for the application in the trusted execution environment in response to the third operation
  • a full data deletion module is configured to delete the target data and the reference data in the untrusted execution environment in response to the third operation.
  • the data encryption device provided by the embodiment of the present application can execute the data encryption method provided by any embodiment of the present application, and has functional modules and beneficial effects corresponding to the execution method.
  • FIG. 11 is a schematic structural diagram of a data decryption apparatus provided in Embodiment 5 of the present application, and the apparatus may include the following modules:
  • the target data determination module 1101 is configured to determine the target data decrypted by the application request in an untrusted execution environment
  • a reference data reading module 1102 configured to read reference data associated with the target data in an untrusted execution environment, where the reference data is one-time use data in the process of decrypting the target data;
  • the master key reading module 1103 is configured to read the master key generated for the application in a trusted execution environment
  • the target data decryption module 1105 is configured to decrypt the target data by using the secure data in the untrusted execution environment to obtain source data.
  • the security data generation module 1104 includes:
  • a target array combination submodule configured to combine the reference data with a preset label in the trusted execution environment to obtain a target array, and the label is used to represent the type of security data;
  • a candidate data generation submodule configured to use the master key to encrypt the target array to obtain candidate data
  • the candidate data regularization submodule is configured to regularize the candidate data into data of a specified length, and use the data of the specified length as the security data matching the tag.
  • the type of the security data includes a secondary key, or, a secondary key and a vector
  • the candidate data regularization submodule includes:
  • a first digest calculation unit configured to, in the trusted execution environment, in response to the tag being a first value, calculate digest data of a first specified length for the candidate data, and the digest data of the first specified length as secondary key, vector;
  • a second digest calculation unit configured to, in the trusted execution environment, in response to the label being the second value, calculate digest data of a second specified length for the candidate data, and the digest data of the second specified length as a secondary key.
  • the security data includes a secondary key, or, a secondary key and a vector
  • the target data decryption module 1105 includes:
  • the first symmetric decryption submodule is set to, in the untrusted execution environment, call the Advanced Encryption Standard AES algorithm in the symmetric key algorithm, use the vector as an initialization vector, and combine the secondary key with the AES algorithm. Decrypt target data to source data;
  • the second symmetric decryption submodule is configured to call the non-AES algorithm in the symmetric key algorithm in the untrusted execution environment, and use the secondary key to decrypt the target data into source data.
  • an installation operation detection module configured to detect a first operation of installing an application in an untrusted execution environment
  • a master key generation module configured to generate a master key for the application in a trusted execution environment in response to the first operation.
  • An associative storage module is configured to associate and store the target data and the reference data in the untrusted execution environment.
  • a deletion operation detection module configured to detect and delete the second operation of the target data
  • An association deletion module configured to delete the target data and the reference data in the untrusted execution environment in response to the second operation.
  • an uninstall operation detection module configured to detect a third operation of uninstalling the application
  • a master key deletion module configured to delete the master key generated by the application in the trusted execution environment in response to the third operation
  • a full data deletion module is configured to delete all the target data and all the reference data in the untrusted execution environment in response to the third operation.
  • the data decryption apparatus provided by the embodiment of the present application can execute the data decryption method provided by any embodiment of the present application, and has functional modules and beneficial effects corresponding to the execution method.
  • FIG. 12 is a schematic structural diagram of a mobile terminal according to Embodiment 6 of the present application.
  • the mobile terminal includes a processor 1200, a memory 1201, a communication module 1202, an input device 1203 and an output device 1204; the number of processors 1200 in the mobile terminal may be one or more, and in FIG. 12, one processor is used for processing Take the processor 1200 as an example; the processor 1200, the memory 1201, the communication module 1202, the input device 1203 and the output device 1204 in the mobile terminal can be connected by a bus or in other ways.
  • the memory 1201 can be used to store software programs, computer-executable programs, and modules, such as modules corresponding to the data encryption method and data decryption method in this embodiment, for example, the data shown in FIG. 10 .
  • the processor 1200 executes various functional applications and data processing of the mobile terminal by running the software programs, instructions and modules stored in the memory 1201, ie, implements the above-mentioned data encryption method and data decryption method.
  • the memory 1201 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system and an application program required for at least one function, and the operating system may be at least one of a general-purpose operating system and a trusted operating system; storage The data area may store data and the like created according to the use of the mobile terminal.
  • memory 1201 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid-state storage device.
  • the memory 1201 may include memory located remotely from the processor 1200, and these remote memories may be connected to the mobile terminal through a network. Examples of the above-mentioned network include the Internet, an intranet, a local area network, a mobile communication network, a combination, and the like.
  • the communication module 1202 is configured to establish a connection with the display screen and realize data interaction with the display screen.
  • the input device 1203 can be configured to receive input digital or character information, and generate key signal input related to user settings and function control of the mobile terminal, and can also be a camera for acquiring images and a pickup device for acquiring audio data.
  • the output device 1204 may include audio devices such as speakers.
  • the components of the input device 1203 and the output device 1204 can be set according to actual conditions.
  • the processor 1200 executes various functional applications and data processing of the mobile terminal by running the software programs, instructions and modules stored in the memory 1201, ie, implements the above-mentioned data encryption method and data decryption method.
  • the mobile terminal provided in this embodiment can execute the data encryption method and the data decryption method provided by any embodiment of this application, and achieve corresponding functions and beneficial effects.
  • Embodiment 7 of the present application further provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, a data encryption method or a data decryption method is implemented.
  • the data encryption method includes:
  • reference data corresponding to the source data, where the reference data is one-time-use data in the process of encrypting the source data
  • the source data is encrypted by using the secure data to obtain target data.
  • the data decryption method includes:
  • read reference data associated with the target data where the reference data is one-time use data in the process of decrypting the target data
  • the target data is decrypted using the secure data to obtain source data.
  • the computer program in the computer-readable storage medium provided by the embodiment of the present application is not limited to the above-mentioned method operations, and the embodiment of the present application can also execute the related data encryption method and data decryption method provided by any embodiment of the present application. operate.
  • the present application can be implemented by means of software and general hardware, and can also be implemented by hardware. Based on such understanding, the parts of the embodiments of the present application that are essentially or contribute to related technologies may be embodied in the form of software products, and the computer software products may be stored in a computer-readable storage medium, such as a floppy disk of a computer, a Read-Only Memory (ROM), Random Access Memory (RAM), flash memory (FLASH), hard disk or optical disk, etc.
  • the computer software product may include multiple instructions to enable a mobile terminal to execute
  • the mobile terminal may be a personal computer, a server, or a network device.
  • the multiple units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be realized;
  • the names of the functional units are only for the purpose of distinguishing them from each other.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Theoretical Computer Science (AREA)
  • Signal Processing (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Health & Medical Sciences (AREA)
  • General Health & Medical Sciences (AREA)
  • Bioethics (AREA)
  • Storage Device Security (AREA)

Abstract

本申请实施例公开了一种数据加密方法、数据解密方法、装置、终端和存储介质,该数据加密方法包括:在非可信执行环境中,确定应用请求加密的源数据;在非可信执行环境中,生成与所述源数据对应的参考数据;在可信执行环境中,读取为应用生成的主密钥;在可信执行环境中,使用主密钥对参考数据进行加密处理,获得安全数据;在非可信执行环境中,使用所述安全数据对所述源数据进行加密,得到目标数据。

Description

数据加密方法、数据解密方法、装置、终端和存储介质
本公开要求在2020年08月07日提交中国专利局、申请号为202010790159.3的中国专利申请的优先权,以上申请的全部内容通过引用结合在本公开中。
技术领域
本申请实施例涉及安全技术,例如涉及一种数据加密方法、数据解密方法、装置、终端和存储介质。
背景技术
在移动终端中安装的应用在存储具有敏感性质的数据时,为了保护用户的个人隐私,通常使用对称密钥算法、非对称密钥算法等算法对数据进行加密。
然而,无论加密算法设计得有多么安全和牢固,一旦密钥被泄露,攻击者可以直接使用密钥调用加密算法解密数据,可见,数据的加解密操作存在着安全性风险。
发明内容
本申请实施例提供一种数据加密方法、数据解密方法、装置、终端和存储介质,以在维持计算开销、存储开销的情况下,提高移动终端中数据的安全性。
第一方面,本申请实施例提供了一种数据加密方法,包括:
在非可信执行环境中,确定应用请求加密的源数据;
在所述非可信执行环境中,生成与所述源数据对应的参考数据,所述参考数据是加密所述源数据的过程中一次性使用的数据;
在可信执行环境中,读取为所述应用生成的主密钥;
在所述可信执行环境中,使用所述主密钥对所述参考数据进行加密处理,获得安全数据;
在所述非可信执行环境中,使用所述安全数据对所述源数据进行加密,得到目标数据。
第二方面,本申请实施例还提供了一种数据解密方法,包括:
在非可信执行环境中,确定应用请求解密的目标数据;
在所述非可信执行环境中,读取与所述目标数据关联的参考数据,所述参考数据是解密所述目标数据的过程中一次性使用的数据;
在可信执行环境中,读取为所述应用生成的主密钥;
在所述可信执行环境中,使用所述主密钥对所述参考数据进行加密处理,获得安全数据;
在所述非可信执行环境中,使用所述安全数据对所述目标数据进行解密,获得源数据。
第三方面,本申请实施例还提供了一种数据加密装置,包括:
源数据确定模块,设置为在非可信执行环境中,确定应用请求加密的源数据;
参考数据生成模块,设置为在所述非可信执行环境中,生成与所述源数据对应的参考数据,所述参考数据是加密所述源数据的过程中一次性使用的数据;
主密钥读取模块,设置为在可信执行环境中,读取为所述应用生成的主密钥;
安全数据生成模块,设置为在所述可信执行环境中,使用所述主密钥对所述参考数据进行加密处理,获得安全数据;
源数据加密模块,设置为在所述非可信执行环境中,使用所述安全数据对所述源数据进行加密,得到目标数据。
第四方面,本申请实施例还提供了一种数据解密装置,包括:
目标数据确定模块,设置为在非可信执行环境中,确定应用请求解密的目标数据;
参考数据读取模块,设置为在所述非可信执行环境中,读取与所述目标数据关联的参考数据,所述参考数据是解密所述目标数据的过程中一次性使用的数据;
主密钥读取模块,设置为在可信执行环境中,读取为所述应用生成的主密钥;
安全数据生成模块,设置为在所述可信执行环境中,使用所述主密钥对所述参考数据进行加密处理,获得安全数据;
目标数据解密模块,设置为在所述非可信执行环境中,使用所述安全数据对所述目标数据进行解密,获得源数据。
第五方面,本申请实施例还提供了一种移动终端,所述移动终端包括:
一个或多个处理器;
存储器,设置为存储一个或多个程序;
所述一个或多个处理器,设置为执行所述一个或多个程序以实现如第一方面所述的数据加密方法或者如第二方面所述的数据解密方法。
第六方面,本申请实施例还提供了一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现如第一方面所述的数据加密方法或者如第二方面所述的数据解密方法。
附图说明
图1为本申请实施例一提供的一种数据加密方法的流程图;
图2为本申请实施例一提供的一种移动终端的环境示意图;
图3为本申请实施例一提供的一种加密的流程示意图;
图4为本申请实施例一提供的一种KGF算法的示例图;
图5为本申请实施例一提供的一种AES的加密示意图;
图6是本申请实施例二提供的一种数据加密方法的流程图;
图7是本申请实施例三提供的一种数据解密方法的流程图;
图8为本申请实施例三提供的一种解密的流程示意图;
图9为本申请实施例三提供的一种AES的解密示意图;
图10为本申请实施例四提供的一种数据加密装置的结构示意图;
图11为本申请实施例五提供的一种数据解密装置的结构示意图;
图12为本申请实施例六提供的一种移动终端的结构示意图。
具体实施方式
相关技术中,无论加密算法设计得有多么安全和牢固,一旦密钥被泄露,攻击者可以直接使用密钥调用加密算法解密数据,所以,加密算法的安全性的重点之一,在于所使用密钥的安全保存。
在相关技术中,应用的密钥主要是以硬编码方式预埋在应用的代码中,如Android(安卓)的Java层、Native层。为了减轻这种无保护的密码存储方式所受到的威胁,通常使用代码混淆机制,如OLLVM(Obfuscator-LLVM),OLLVM是一个开源的代码混淆编译器,混淆代码逻辑以提高代码逆向阅读的困难度。
但是,代码混淆机制只能对代码逻辑进行混淆,无法混淆预埋密钥这种数组变量或常量,该类存储方式有以下三个缺点:
(1)密钥无任何单独的安全保护,仅依赖于对代码的安全加固,往往容易被攻击者静态分析提取密钥,攻击者容易通过移动终端的漏洞获取权限。
(2)可能被攻击者逆向代码后,不直接提取密钥,使用上层函数代码直接调用启动密钥的函数,对数据直接解密。
(3)由于不易变更或实行每个应用实例使用不同密钥,所以同一版本的应用或者所有版本的应用预埋的密钥都是一致的,攻击者可以把数据从一个应用导出,放在另一个已被破解的应用上进行数据解密,即数据离开移动终端仍可被解密。
就上述安全性风险而言,本申请实施例公开一种数据加密方法、数据解密方法、装置、终端和存储介质,可较好地应对此类数据安全风险。
下面结合附图和实施例对本申请进行说明。
实施例一
图1为本申请实施例一提供的一种数据加密方法的流程图,本实施例可使用一次性的密钥对数据进行加密,该方法可以由数据加密装置来执行,该数据加密装置可以由软件和/或硬件实现,可配置在移动终端中,移动终端例如手机、平板电脑、智能穿戴设备等,智能穿戴设备例如智能眼镜、智能手表等。
在本实施例中,如图2所示,移动终端包括如下两种环境:
一、非可信执行环境210
非可信执行环境是移动终端通用的环境,运行通用的操作系统(Operating System,OS),例如,Android(安卓)、iOS、Linux等等,非可信执行环境为上层的第三方应用(application,APP)提供服务。
非可信执行环境存在一定的安全隐患,如基于OS实现的应用隔离容易被绕过,OS代码庞大,容易出现漏洞(BUG),OS可以看到应用内部的数据,缺乏隔离意味着应用无法安全存储密钥、敏感数据。
二、可信执行环境220
其中,可信执行环境是移动终端中处理器上的一个安全区域,可信执行环境提供一个隔离于非可信执行环境的执行环境,独立运行可信操作系统(Trusted OS)。
隔离是可信执行环境的本质属性,隔离可以是通过软件,也可以是硬件实现,隔离环境下可应用更多的软件、硬件、网际互连协议(Internet Protocol,IP)、总线一体的安全机制。
对于硬件机制的保护,并不规定某一种硬件实现方法,非可信执行环境不可直接访问可信执行环境,但可作为可信执行环境的客户端(Client)通过应用程序接口(Application Programming Interface,API)向可信执行环境的Trusted OS请求安全服务。
可信执行环境由Global Platform(GP)等实现标准化,可在多种平台上移 植,GP定义了可信执行环境的保护轮廓(Protection Profile),定义了所需的硬件保护强度。
可信执行环境对于密钥使用安全存储机制,保证认证性、完整性和机密性。
可信执行环境中可以同时支持安全加载并执行多个可信应用(Trusted Application,TA),TA之间相互隔离,保证加载到可信执行环境的代码及数据的机密性、完整性,Trusted OS提供可信执行环境中的内部API(Internal API)为TA提供服务。
针对不同的OS,可信执行环境也有所不同,例如,若OS为iOS系统,则可信执行环境为Secure Enclave,又例如,若OS为Android系统,可信执行环境为TEE(Trusted Execution Environment),非可信执行环境为REE(Rich Execution Environment)。
如图1所示,该方法包括如下步骤:
S101、在非可信执行环境中,确定应用请求加密的源数据。
在非可信执行环境(如REE)中安装一个或多个应用(APP),该应用可以为通用操作系统的应用,也可以为第三方应用,例如,摄像应用、浏览器、电子邮箱、记事本、通讯录、购物应用、短视频应用等。
其中,通用操作系统也可记为非可信操作系统,例如,Android、iOS、Linux等。
应用在运行的过程中,会产生不同安全级别的数据,这些数据通常为明文(plaintext),部分或全部数据因安全级别较高、业务需求等因素而待生成并存储的数据,可以作为源数据,等待加密。
在不同的场景中,源数据的形式可有所不同。
例如,对于浏览器,用户在使用账号、密码(又称口令)登录网站时,浏览器可以记录账号、密码,网站在验证账号、密码成功之后会返回Cookie,账号、密码与Cookie均可以作为源数据加密存储。
又例如,对于记事本,用户记录一些待处理的事项,这些事项可以作为源数据加密存储。
又例如,对于通讯录,用户记录联系人信息,如名称、手机号码、头像等,一般情况下,用户解锁移动终端之后可浏览该联系人信息,其他应用在授权的情况下可读取联系人信息,对于部分较为隐私的联系人信息,可作为源数据加密存储。
上述应用及应用对应的待加密的源数据只是作为示例,在实施本申请实施 例时,可以根据实际情况设置其他应用及其他应用对应的待加密的源数据,例如,用户身份信息、支付信息、音视频数据等。另外,除了上述应用及待加密的源数据外,本领域技术人员还可以根据实际需要采用其它应用及待加密的源数据。
S102、在非可信执行环境中,生成与所述源数据对应的参考数据,所述参考数据是加密所述源数据的过程中一次性使用的数据。
如图3所示,在非可信执行环境(如REE)中接收到应用请求加密的源数据之后,可在非可信执行环境中针对源数据生成在本次加密有效的数据,作为参考数据。
在一实施例中,所谓本次加密有效的数据,是指针对本次加密源数据的操作具有唯一性的数据,即参考数据为一次性的数据,并不重复使用。
在一种方式中,可在非可信执行环境(如REE)中,通过rand()函数等方式随机生成一数值Nonce,作为参考数据。
为保证安全性,该随机的数值Nonce的长度可选为32字节或大于32字节。
在另一种方式中,可在非可信执行环境(如REE)中,通过Calendar.getInstance()、new Time()等函数从通用操作系统中读取当前的时间戳Timestamp,作为参考数据。
上述两种方式中随机的数值Nonce、时间戳Timestamp,可以单独使用,也可以组合使用。组合使用时,可以保证本实施例的加密机制整体的抗碰撞性和前向性。
此外,除了上述两种方式之外,还可以使用其他方式生成参考数据,例如,对随机生成的数据进行偏移、异或等操作,通过预设的映射函数将当前的时间戳进行映射等。
S103、在可信执行环境中,读取为应用生成的主密钥。
如图3所示,在可信执行环境(如TEE)中,为非可信执行环境(如REE)中的应用设置有密钥,为便于区分,该密钥可以称为主密钥SK,该主密钥SK可用于生成本次对源数据加密的安全数据。
非可信执行环境中存在应用,可信执行环境中存在与应用对应的主密钥SK。
一般情况下,应用与主密钥SK是一一对应的关系,即一个应用对应一个主密钥SK,相应地,可在数据库中建立应用的标识(如包名)与主密钥SK之间的映射关系。
在对源数据进行加密时,在非可信执行环境(如REE)中可通过可信执行 环境(如TEE)提供的API,将应用的标识、参考数据发送至可信执行环境(如TEE)中,请求可信执行环境(如TEE)中的TA使用参考数据生成安全数据,使用该安全数据加密源数据。
此时,可信执行环境(如TEE)中的TA可在数据库中,查找该应用的标识所映射的主密钥SK。
S104、在可信执行环境中,使用主密钥对参考数据进行加密处理,获得安全数据。
如图3所示,在可信执行环境(如TEE)中,TA提供密钥生成函数KGF(Key Generation Function),该密钥生成函数KFG可用于生成安全数据,对此,以参考数据(如随机的数值Nonce、时间戳Timestamp)作为输入,使用主密钥SK对参考数据进行加密处理,将加密处理之后输出的数据设置为安全数据。
安全数据应用于对称密钥算法,安全数据中至少包含密钥,为便于区分,安全数据中的密钥称为副密钥,当然,除了副密钥之外,安全数据根据对称密钥算法的不同,还可以包含其他数据。
对参考数据进行的加密处理除了包含加密操作之外,为提高安全性,还可以包含其他操作,例如,添加其他维度的数据,执行异或操作,执行偏移操作,等等。
在本申请的一个实施例中,S104可以包括如下步骤,步骤一、步骤二及步骤三。三个步骤如下:
步骤一、在可信执行环境中,将参考数据与预设的标签组合,得到目标数组。
如图4所示,以KGF算法为例,可以由开发人员自定义一个字符串,作为标签Label,存储在移动终端的可信执行环境(如TEE)中。
该标签Label为待生成的一次性的安全数据的人为命名,标签Label可用于表示安全数据的类型,增加输入数据的维度、以提高安全性,同时也方便开发人员记忆和减少安全数据的误操作。
在一个示例中,在标签Label为secret时,secret表示安全数据的类型为密钥,为便于区分,该密钥可以称为副密钥。
在另一个示例中,在标签Label为iv时,iv表示安全数据的类型为副密钥、向量。
在可信执行环境(如TEE)中,TA表现为编码器Encoder的形式,将参考数据(如随机的数值Nonce、时间戳Timestamp)、标签Label按照既定的顺序, 粘接编码为一个Hex数组,作为目标数组M。
示例性地,M=Nonce||Timestamp||Label。
步骤二、在可信执行环境中,使用主密钥将目标数组加密,得到候选数据。
如图4所示,可使用可信执行环境(如TEE)提供的安全密码函数,使用主密钥将目标数组M加密,得到密文形式的数组T,数组T作为候选数据,即T=Enc(SK,M),Enc表示加密函数。
以TEE作为可信执行环境的示例,TEE提供的安全密码函数包括HMAC(Hash-based Message Authentication Code,与密钥相关的哈希运算)算法、AES(Advanced Encryption Standard,高级加密标准)算法、RSA加密算法、ECDSA(Elliptic Curve Digital Signature Algorithm,椭圆曲线数字签名算法)签名算法、RSA签名算法,等等。HMAC与AES的计算速度较快,可选用该两种安全密码函数。
步骤三、在可信执行环境中,对候选数据规整为指定长度的数据,将指定长度的数据作为与标签匹配的安全数据。
在可信执行环境(如TEE)中,TA表现为规整器Regulator的形式。
如图4所示,由于候选数据T可能是任意长度,而后续加密所需的安全数据长度是固定的,规整器Regulator以候选数据T为输入,计算输出指定长度的字符串,作为一次性的安全数据,该安全数据的类型以标签Label定义。
其中,规整器Regulator可使用单向散列函数将候选数据规整为安全数据,即输出的字符串为摘要数据,单向散列函数可记为Hash(T),单向散列函数可计算任意长度数据,生成L字节固定长度的摘要信息B 0B 1B 2…B L-2B L-1,L为正整数,例如,MD5(Message Digest Algorithm,消息摘要算法第五版)可输出16B的摘要数据、SHA(Secure Hash Algorithm,安全哈希算法)1输出20B的摘要数据、SHA224输出28B的摘要数据、SHA256输出32B的摘要数据、SHA384输出48B的摘要数据、SHA512输出64B的摘要数据,等等。
例如,安全数据包括副密钥(One-Time Key),或,副密钥和向量(One-Time IV)。
响应于标签为第一值(如iv),在可信执行环境(如TEE)中,使用单向散列函数对候选数据计算第一指定长度的摘要数据,第一指定长度的摘要数据作为副密钥(One-Time Key)、向量(One-Time IV),该副密钥、向量适用于对称密钥算法中的AES算法。
响应于标签为第二值(如secret),在可信执行环境(如TEE)中,使用单 向散列函数对候选数据计算第二指定长度的摘要数据,第二指定长度的摘要数据作为副密钥(One-Time Key),该副密钥适用于该对称密钥算法中的非AES算法,例如,RC4、Chacha20,等等。
图4中,若标签为第一值(如iv)或第二值(如secret),摘要数据中将有副密钥(One-Time Key);若标签为第一值(如iv),摘要数据中将有向量(One-Time IV)。换言之,若标签为第一值(如iv),摘要数据中可同时有副密钥(One-Time Key)、向量(One-Time IV)。
S105、在非可信执行环境中,使用安全数据对源数据进行加密,得到目标数据。
在本实施例中,如图3所示,可信执行环境(如TEE)中的TA针对应用待加密的源数据生成安全数据之后,将安全数据输出至非可信执行环境(如REE),在非可信执行环境(如REE)中,使用对称密钥算法加密源数据,加密之后的密文即为目标数据。
图3中示出,源数据301与目标数据302。
例如,安全数据包括副密钥(One-Time Key),或,副密钥和向量(One-Time IV)。
在一种实施方式中,在非可信执行环境中,调用对称密钥算法中的AES算法、使用向量作为初始化向量(Initialization Vector,IV)、与副密钥共同将源数据加密为目标数据。
如图5所示,在AES算法的CBC(Cipher Block Chaining,加密块链)模式中,实现分组加密,将源数据切分为多个明文块,如明文块0、明文块1……。针对每个明文块,将明文块与加密向量进行异或处理之后,加密器使用副密钥进行加密,输出密文块,密文块可为二进制的数组,如密文块0、密文块1……。密文块组合之后即为目标数据。
其中,对于第1个明文块(即明文块0),加密向量属于初始化向量IV,即为安全数据中的向量,对于第n个明文块(即明文块1……),加密向量为第n-1个密文块,n>1。
在另一种实施方式中,在非可信执行环境中,调用对称密钥算法中的非AES算法、使用副密钥将源数据加密为目标数据。其中,非AES算法如RC4、Chacha20等。
上述加密算法及安全参数只是作为示例,在实施本申请实施例时,可以根据实际情况设置其他加密算法及其安全参数。
在本实施例中,在非可信执行环境中,确定应用请求加密的源数据,生成与源数据对应的参考数据,参考数据是加密所述源数据的过程中一次性使用的数据;在可信执行环境中,读取为应用生成的主密钥,使用主密钥对参考数据进行加密处理,获得安全数据;在非可信执行环境中,使用安全数据对源数据加密,得到目标数据。
在本实施例中,可信执行环境是基于硬件级别的安全芯片实现,攻击者难以攻破安全芯片,使得可信执行环境的安全强度高,可以保证主密钥、安全数据的安全性。
主密钥是针对应用生成的,使得同一版本的应用或者所有版本的应用所使用的主密钥不相同,而参考数据在本次加解密有效,使得基于主密钥与参考数据生成的安全数据具有一次性的特性,该一次性的安全数据不直接存储,而是在可信执行环境生成,满足选择明文攻击(Chosen-Plaintext Attack,CPA)的安全性,并且,无法被逆向破解。
由于安全数据具有一次性的特性,其他移动终端无法针对同一个源数据生成相同的安全数据,因此,即便加密之后的目标数据离开移动终端后,也无法被其他移动终端解密。
由于可信执行环境内部实施强制访问控制保护,且可信执行环境内部无法被非可信执行环境直接访问,所以,攻击者无法调用启动主密钥的函数对数据进行解密,达到防止非法调用攻击的目标。
此外,在可信执行环境中生成安全数据,由于安全数据的数据量少,可以保证在可信执行环境的计算开销低;在非可信执行环境中,基于性能比安全芯片更高的处理器、使用安全数据对源数据进行加解密,保证在可信执行环境的计算开销低,保证整体的计算开销低。
例如,可信执行环境为独立的安全芯片的运行环境,非可信执行环境为不同于安全芯片的其他硬件上的运行环境。
例如,安全芯片可为,专门为可信执行环境使用的独立硬件芯片。非可信执行环境是在除安全芯片以外的手机硬件上运行,比如手机内存、中央处理器、存储卡等,可不为单独的芯片。
可信执行环境、非可信执行环境在大部分的移动终端有部署,并且,移动终端提供的密码算法是可复用的,使得兼容性在可接受的程度内,不需要额外部署库文件,存储开销小。
除了将应用的密钥以硬编码方式预埋在应用的代码中之外,还可能存在如下两种方式:
一、应用使用白盒密码技术对密钥进行加密存储。
白盒密码技术是指能够抵抗白盒攻击的密码技术,而白盒攻击是指攻击者对移动终端拥有完全的控制能力,能够观测和更改程序运行时的内部数据,这种攻击环境称为白盒攻击环境。
大多移动终端的环境(如Android、iOS等)在很多情况下就是一个白盒攻击环境,保护密钥安全是白盒密码技术的一个基本需求。白盒密码技术通常使用AES算法,可以保证密钥在不以明文形式出现的条件下,对敏感数据完成加解密,提高密钥存储的安全性,适用于移动终端的场景。
白盒密码技术虽然可以解决密钥被逆向代码静态分析、被提取的威胁情形,但是,仍然无法解决密钥硬编码在代码方式上的缺点,即使用上层函数代码直接调用启动密钥的函数,对数据直接解密;数据离开移动终端仍可被解密。
此外,白盒密码技术的库大约需要350KB存储空间,给应用的安装包存储增加了至少350KB,一些对于安装包大小较为敏感的应用难以承受。
二、在基于硬件安全芯片的可信执行环境对密钥进行加密存储。
移动终端部署使用了基于安全芯片的可信执行环境,可信执行环境是中央处理器(Central Processing Unit,CPU)上的一块区域,可信执行环境的作用是给数据和代码的执行提供一个更安全的空间,并保证数据和代码的机密性和完整性。
iOS系统使用的Secure Enclave是一种可信执行环境,Android系统6.0+,API Level 23+之后,Android系统也要求移动终端部署可信执行环境TEE及安全硬件芯片。
一些加密方式使用基于硬件安全芯片的可信执行环境的AES加密服务,对一些敏感的个人数据直接进行加密存储,比如,人脸模型参数、银行卡信息等。但是,安全芯片属于一个独立的硬件,成本高,计算能力有限,使用可信执行环境的加密服务,对于大量的数据和文件直接加密,效率低,时间开销高。
测试结果表明,对100KB数据,使用TEE的AES-128加解密时间开销为6.2秒,TEE的RSA-2048加解密时间开销为45秒。然而个人敏感数据,可能包含较大的音视频文件,大文件或数据加密对应的时间开销过高难以承受。
此外,TEE的加解密服务,也无法直接支持CPA安全性。支持CPA安全性可表现为,两段内容相同的明文,加密得到两段内容不同的密文。故而,需 要每次加密前额外调用一次TEE的密钥生成存储服务,增加了时间开销。
综合对比“应用的密钥以硬编码方式预埋在应用的代码”、“应用使用白盒密码技术对密钥进行加密存储”、“在基于硬件安全芯片的可信执行环境对密钥进行加密存储”与“本实施例”,如表1所示。
表1四类处理方式的对比
Figure PCTCN2021108935-appb-000001
其中,安全芯片的安全强度高于AES-128的安全强度;Android 6.0 API 23+、所支持的任意密码算法均可使用,使得兼容性较好,属于产品可接受的程度。
综上,本实施例在安全强度、整体安全性、数据离开设备失效、计算开销、存储开销均表现优良。
实施例二
图6为本申请实施例二提供的一种数据加密方法的流程图,本实施例以前述实施例为基础,本实施例增加注册主密钥、管理主密钥及参考数据的处理操作,本实施例描述的方法包括如下步骤:
S601、检测在非可信执行环境中安装应用的第一操作。
若本实施例应用于通用操作系统,则可以通过调用通用操作系统的函数监测在非可信执行环境(如REE)中安装应用的第一操作,即第一操作又称安装操作。
以Android为例,应用在安装的时候,Android操作系统会发送广播,基于 该广播机制,可以定义表示安装应用的广播,广播信息可为应用被安装,应用以包名表示。可在AndroidManifest注册表示安装应用的广播,若接收到表示安装应用的广播,则表示检测到在非可信执行环境(如REE)中安装应用的操作。
若本实施例应用于应用本身,则在应用的安装包被执行时,可以认为是在,检测在非可信执行环境(如REE)中安装应用的第一操作。
S602、响应于第一操作,在可信执行环境中为应用生成主密钥。
在非可信执行环境(如REE)中安装应用时,可通过可信执行环境(如TEE)提供的API调用可信执行环境(如TEE)中密钥生成和存储服务,针对该应用生成一个随机的密钥,作为主密钥SK,并且主密钥SK在可信执行环境(如TEE)中长期存储,即在可信执行环境(如TEE)的数据库中建立该应用的标识(如包名)与主密钥SK之间的映射关系。
例如,主密钥SK可以使用HMAC、AES、RSA、ECDSA等算法中的任意一种密钥,也可以根据后续对源数据进行加密的算法而选择。
其中,HMAC的密钥长度一般大于或等于16字节,AES的密钥长度一般大于或等于16字节,RSA的密钥长度一般大于或等于256字节,以确保最低等同AES-128的主流商用密码的安全强度。
S603、在非可信执行环境中,确定应用请求加密的源数据。
S604、在非可信执行环境中,生成与源数据对应的参考数据,所述参考数据是加密所述源数据的过程中一次性使用的数据。
S605、在可信执行环境中,读取为应用生成的主密钥。
S606、在可信执行环境中,使用主密钥对参考数据进行加密处理,获得安全数据。
S607、在非可信执行环境中,使用安全数据对源数据进行加密,得到目标数据。
S608、在非可信执行环境中,关联存储目标数据与参考数据。
在非可信执行环境(如REE)中,在使用安全数据对源数据进行加密,得到目标数据之后,在应用的安装目录下,或者,在独立的存储区域中,除了存储目标数据之外,还存储本次加密所使用的参考数据,建立目标数据与参考数据之间的关联关系,该关联关系表示该参考数据用于加密该目标数据。
目标数据与参考数据之间的存储结构可以自主定义,例如,利用随机的数值Nonce、时间戳Timestamp加密源数据得到目标数据C,存储时可以把固定长度的Nonce、Timestamp作为文件头与目标数据C写在一起,即 Nonce|Timestamp|C;或者,存储时可以把固定长度的Nonce、Timestamp作为文件尾与目标数据C写在一起,即C|Nonce|Timestamp。
S609、检测删除目标数据的第二操作。
S610、响应于第二操作,在非可信执行环境中删除目标数据与参考数据。
在应用的运行过程中,用户会主动请求删除部分目标数据,或者,应用会自动删除自身的目标数据,或者,第三方应用(如清理应用)也会请求删除应用的目标数据。
例如,浏览器中的Cookie作为源数据加密为目标数据,浏览器中设置了自动清理过期的cookie的机制,浏览器在检测到cookie过期之后,删除该cookie,即相应地删除该目标数据。
又例如,记事本中记录的事项作为源数据加密为目标数据,用户在发现该事项已经处理之后,在记事本中删除该事项,即相应地删除该目标数据。
又例如,通讯录中的联系人信息作为源数据加密为目标数据,清理应用在检测到存在相同的联系人信息之后,删除相同的联系人信息中的一个联系人信息,即相应地删除该目标数据。
如果检测到删除目标数据的第二操作,则可以在非可信执行环境(如REE)中查找相应的目标数据,并删除该目标数据,在删除目标数据之后,参考数据失效,此时,可定位该目标数据所映射的参考数据,将该参考数据随同该目标数据删除,保证失效数据及时清理,降低存储开销。
所谓失效,是指删除与参考数据关联的目标数据之后,使用主密钥与该参考数据也无法对其他目标数据进行解密。
S611、检测卸载应用的第三操作。
若本实施例应用于通用操作系统,则可以通过调用通用操作系统的函数监测在非可信执行环境(如REE)中卸载应用的第三操作,即第三操作又称卸载操作。
以Android为例,应用在卸载的时候,Android操作系统会发送广播,基于该广播发送机制,可以定义表示安装应用的广播,广播如应用被卸载,应用可以包名表示。可在AndroidManifest注册表示卸载应用的广播,若接收到表示卸载应用的广播,则表示检测到在非可信执行环境(如REE)中卸载应用的操作。
若本实施例应用于应用本身,则在应用的卸载程序被执行时,可以认为检测在非可信执行环境(如REE)中卸载应用的第一操作。
S612、响应于第三操作,在可信执行环境中删除为应用生成的主密钥。
S613、响应于第三操作,在非可信执行环境中删除目标数据与参考数据。
在检测到卸载应用的第三操作之后,主密钥、目标数据与参考数据失效,并不作为配置文件而保留在移动终端中,保证失效数据及时清理,降低存储开销。
所谓失效,是指在卸载应用完成之后,若重新安装相同的应用,则会重新生成一个新的主密钥、重新针对相同的源数据生成新的参考数据、新的目标数据,使用新的主密钥与新的参考数据无法对原有的目标数据进行解密。
一方面,可通过可信执行环境(如TEE)提供的API请求删除在可信执行环境(如TEE)中为应用生成的主密钥,另一方面,在非可信执行环境(如REE)中删除该应用下所存储的所有目标数据与所有参考数据。
例如,可删除与卸载的应用对应的目标数据与参考数据。
实施例三
图7为本申请实施例三提供的一种数据解密方法的流程图,本实施例使用一次性的密钥对数据进行解密,该方法可以由数据解密装置来执行,该数据解密装置可以由软件和/或硬件实现,可配置在移动终端中,例如,手机、平板电脑、智能穿戴设备(如智能眼镜、智能手表等),等等,该移动终端包括非可信执行环境、可信执行环境,该方法包括如下步骤:
S701、在非可信执行环境中,确定应用请求解密的目标数据。
在非可信执行环境(如REE)中安装一个或多个应用(APP),应用在运行的过程中,会根据不同的业务需求而请求使用相应的数据。
在本实施例中,该数据以密文的形式存储在非可信执行环境(如REE)中,称为目标数据,此时,可从在非可信执行环境(如REE)中读取该目标数据,等待解密。
S702、在非可信执行环境中,读取与所述目标数据关联的参考数据,所述参考数据是解密所述目标数据的过程中一次性使用的数据。
如图8所示,使用参考数据加密得到目标数据,该目标数据与参考数据关联存储在非可信执行环境(如REE)中。
在对目标数据解密时,可从非可信执行环境(如REE)中,基于该关联关系查找该目标数据对应的参考数据。
在一实施例中,参考数据本次解密有效,本次解密有效的数据,是指针对本次解密目标数据的操作具有唯一性的数据,即参考数据为一次性的数据,并 不重复使用。
在一实施例中,该参考数据为随机生成一数值Nonce和/或加密目标数据时的时间戳。
目标数据与参考数据之间的存储结构可以自主定义,在解密时,可以按照该存储结构读取参考数据,例如,存储时可以把固定长度的Nonce、Timestamp作为文件头与目标数据C写在一起,即Nonce|Timestamp|C,则在解密时,可先读取文件头固定长度的字符串,作为Nonce和Timstamp,剩余的字符串为C;或者,存储时可以把固定长度的Nonce、Timestamp作为文件尾与目标数据C写在一起,即C|Nonce|Timestamp,则在解密时,可先读取文件尾固定长度的字符串,作为Nonce和Timstamp,剩余的字符串为C。
S703、在可信执行环境中,读取为应用生成的主密钥。
如图8所示,在对目标数据进行解密时,在非可信执行环境(如REE)中可通过可信执行环境(如TEE)提供的API,将应用的标识、参考数据发送至可信执行环境(如TEE)中,请求可信执行环境(如TEE)中的TA使用参考数据生成安全数据,使用该安全数据解密目标数据。
此时,可信执行环境(如TEE)中的TA可在数据库中,查找该应用的标识所映射的主密钥SK。
S704、在可信执行环境中,使用主密钥对参考数据进行加密处理,获得安全数据。
如图8所示,在可信执行环境(如TEE)中,TA提供密钥生成函数KGF,该密钥生成函数KGF可用于生成安全数据,对此,以参考数据(如随机的数值Nonce、时间戳Timestamp)作为输入,使用主密钥SK对参考数据进行加密处理,将加密处理后输出的数据设置为安全数据。
在本申请的一个实施例中,在可信执行环境(如TEE)中,将参考数据与预设的标签组合为目标数组,其中,标签用于表示安全数据的类型。
在可信执行环境(如TEE)中,使用主密钥将目标数组加密为候选数据。
在可信执行环境(如TEE)中,对候选数据规整为指定长度的数据,作为与标签匹配的安全数据。
在一个示例中,安全数据的类型包括副密钥,或,副密钥和向量,则在本示例中,若标签为第一值,则在可信执行环境中,对候选数据计算第一指定长度的摘要数据,作为副密钥、向量;或者,若标签为第二值,则在可信执行环境中,对候选数据计算第二指定长度的摘要数据,作为副密钥。
例如,第一指定长度的摘要数据作为副密钥、向量,是指第一指定长度的摘要数据中同时包含副密钥、向量,第二指定长度的摘要数据作为副密钥,是指第二指定长度的摘要数据中包含副密钥。
在本申请实施例中,由于S704与S104的应用基本相似,简化描述,相关之处参见S104的部分说明即可,本申请实施例在此不加以详述。
S705、在非可信执行环境中,使用安全数据对目标数据进行解密,获得源数据。
如图8所示,可信执行环境(如TEE)中的TA针对应用待解密的目标数据生成安全数据之后,将安全数据输出至非可信执行环境(如REE),在非可信执行环境(如REE)中,使用对称密钥算法解密目标数据801,解密之后的明文即为源数据802。
例如,安全数据包括副密钥(One-Time Key),或,副密钥和向量(One-Time IV)。
在一种实施方式中,在非可信执行环境(如REE)中,调用对称密钥算法中的AES算法、使用该向量作为初始化向量IV、该向量与副密钥共同将目标数据解密为源数据。
如图9所示,在AES算法的CBC模式中,实现分组解密,将目标数据切分为多个密文块,如密文块0、密文块1……,针对每个密文块,解密器使用副密钥进行解密之后,将解密结果与加密向量进行异或处理之后,输出明文块,如明文块0、明文块1……,明文块组合之后的组合结果即为源数据。
其中,对于第1个明文块(即明文块0),加密向量属于初始化向量IV,即为安全数据中的向量,对于第n(n>1)个明文块(即明文块n-1),例如明文块1……,加密向量为第n-1个密文块(即密文块n-2),例如密文块0……。
在另一种实施方式中,在非可信执行环境中,调用对称密钥算法中的非AES算法、使用副密钥将目标数据解密为源数据。
上述解密算法及安全参数只是作为示例,在实施本申请实施例时,可以根据实际情况设置其他解密算法及安全参数。另外,除了上述解密算法及其安全参数外,本领域技术人员还可以根据实际需要采用其它解密算法及安全参数。
在本实施例中,在非可信执行环境中,确定应用请求解密的目标数据;在非可信执行环境中,读取与目标数据关联的参考数据,所述参考数据是解密所述目标数据的过程中一次性使用的数据;在可信执行环境中,读取为应用生成的主密钥;在可信执行环境中,使用主密钥对参考数据进行加密处理,获得安 全数据;在非可信执行环境中,使用安全数据对目标数据进行解密,获得源数据。
可信执行环境是基于硬件级别的安全芯片实现,攻击者难以攻破安全芯片,使得可信执行环境的安全强度高,可以保证主密钥、安全数据的安全性。
主密钥是针对应用生成的,使得同一版本的应用或者所有版本的应用所使用的主密钥不相同,而参考数据在本次加解密有效,使得基于主密钥与参考数据生成的安全数据具有一次性的特性,该一次性的安全数据不直接存储,而是在可信执行环境生成,满足CPA的安全性,并且无法被逆向破解。
由于安全数据具有一次性的特性,其他移动终端无法针对同一个源数据生成相同的安全数据,因此,即便加密之后的目标数据离开移动终端后,也无法被其他移动终端解密。
由于可信执行环境内部实施强制访问控制保护,且可信执行环境内部无法被非可信执行环境直接访问,所以,攻击者无法调用启动主密钥的函数对数据进行解密,达到防止非法调用攻击的目标。
此外,在可信执行环境中生成安全数据,由于安全数据的数据量少,可以保证在可信执行环境的计算开销低,在非可信执行环境中基于性能比安全芯片更高的处理器、使用安全数据对源数据进行加解密,保证在可信执行环境的计算开销低,保证整体的计算开销低。
最后,可信执行环境、非可信执行环境在大多移动终端有部署,并且,可复用移动终端提供的密码算法,使得兼容性在可接受的程度内,不需要额外部署库文件,存储开销小。
在本申请的一个实施例中,该方法还包括:
检测在非可信执行环境中安装应用的第一操作;
响应于第一操作,在可信执行环境中为应用生成主密钥。
在本申请的一个实施例中,该方法还包括:
在非可信执行环境中,关联存储目标数据与参考数据。
在本申请的一个实施例中,该方法还包括:
检测删除目标数据的第二操作;
响应于第二操作,在非可信执行环境中删除目标数据与参考数据。
在本申请的一个实施例中,该方法还包括:
检测卸载应用的第三操作;
响应于第三操作,在可信执行环境中删除为应用生成的主密钥;
响应于第三操作,在非可信执行环境中删除所有目标数据与所有参考数据。
在本申请实施例中,由于第一操作、第二操作、第三操作的响应与实施例二的应用基本相似,相似内容参见实施例二的部分说明即可,本申请实施例在此不加以详述。
实施例四
图10为本申请实施例四提供的一种数据加密装置的结构示意图,该装置可以包括如下模块:
源数据确定模块1001,设置为在非可信执行环境中,确定应用请求加密的源数据;
参考数据生成模块1002,设置为在所述非可信执行环境中,生成与所述源数据对应的参考数据,所述参考数据是加密所述源数据的过程中一次性使用的数据;
主密钥读取模块1003,设置为在可信执行环境中,读取为所述应用生成的主密钥;
安全数据生成模块1004,设置为在所述可信执行环境中,使用所述主密钥对所述参考数据进行加密处理,获得安全数据;
源数据加密模块1005,设置为在所述非可信执行环境中,使用所述安全数据对所述源数据进行加密,得到目标数据。
在本申请的一个实施例中,所述参考数据生成模块1002包括:
随机数值生成子模块,设置为在所述非可信执行环境中,随机生成一数值,作为参考数据;
和/或,
时间戳读取子模块,设置为在所述非可信执行环境中,读取当前的时间戳,作为参考数据。
在本申请的一个实施例中,所述安全数据生成模块1004包括:
目标数组组合子模块,设置为在所述可信执行环境中,将所述参考数据与预设的标签组合,得到目标数组,所述标签用于表示安全数据的类型;
候选数据生成子模块,设置为使用所述主密钥将所述目标数组加密,得到候选数据;
候选数据规整子模块,设置为对所述候选数据规整为指定长度的数据,将所述指定长度的数据作为与所述标签匹配的安全数据。
在本申请的一个实施例中,所述安全数据的类型包括副密钥,或,副密钥和向量;
所述候选数据规整子模块包括:
第一摘要计算单元,设置为在所述可信执行环境中,响应于所述标签为第一值,对所述候选数据计算第一指定长度的摘要数据,所述第一指定长度的摘要数据作为副密钥、向量;
或者,
第二摘要计算单元,设置为在所述可信执行环境中,响应于所述标签为第二值,对所述候选数据计算第二指定长度的摘要数据,所述第二指定长度的摘要数据作为副密钥。
在本申请的一个实施例中,所述安全数据包括副密钥,或,副密钥和向量;
所述源数据加密模块1005包括:
第一对称加密子模块,设置为在所述非可信执行环境中,调用对称密钥算法中的高级加密标准AES算法、使用所述向量作为初始化向量、与所述副密钥共同将所述源数据加密为目标数据;
或者,
第二对称加密子模块,设置为在所述非可信执行环境中,调用对称密钥算法中的非AES算法、使用所述副密钥将所述源数据加密为目标数据。
在本申请的一个实施例中,还包括:
安装操作检测模块,设置为检测在非可信执行环境中安装应用的第一操作;
主密钥生成模块,设置为响应于所述第一操作,在可信执行环境中为所述应用生成主密钥。
在本申请的一个实施例中,还包括:
关联存储模块,设置为在所述非可信执行环境中,关联存储所述目标数据与所述参考数据。
在本申请的一个实施例中,还包括:
删除操作检测模块,设置为检测删除所述目标数据的第二操作;
关联删除模块,设置为响应于所述第二操作,在所述非可信执行环境中删除所述目标数据与所述参考数据。
在本申请的一个实施例中,还包括:
卸载操作检测模块,设置为检测卸载所述应用的第三操作;
主密钥删除模块,设置为响应于所述第三操作,在所述可信执行环境中删 除为所述应用生成的主密钥;
全量数据删除模块,设置为响应于所述第三操作,在所述非可信执行环境中删除所述目标数据与所述参考数据。
本申请实施例所提供的数据加密装置可执行本申请任意实施例所提供的数据加密方法,具备执行方法相应的功能模块和有益效果。
实施例五
图11为本申请实施例五提供的一种数据解密装置的结构示意图,该装置可以包括如下模块:
目标数据确定模块1101,设置为在非可信执行环境中,确定应用请求解密的目标数据;
参考数据读取模块1102,设置为在非可信执行环境中,读取与所述目标数据关联的参考数据,所述参考数据是解密所述目标数据的过程中一次性使用的数据;
主密钥读取模块1103,设置为在可信执行环境中,读取为所述应用生成的主密钥;
安全数据生成模块1104,设置为在所述可信执行环境中,使用所述主密钥对所述参考数据进行加密处理,获得安全数据;
目标数据解密模块1105,设置为在所述非可信执行环境中,使用所述安全数据对所述目标数据进行解密,获得源数据。
在本申请的一个实施例中,所述安全数据生成模块1104包括:
目标数组组合子模块,设置为在所述可信执行环境中,将所述参考数据与预设的标签组合,得到目标数组,所述标签用于表示安全数据的类型;
候选数据生成子模块,设置为使用所述主密钥将所述目标数组加密,得到候选数据;
候选数据规整子模块,设置为对所述候选数据规整为指定长度的数据,将所述指定长度的数据作为与所述标签匹配的安全数据。
在本申请的一个实施例中,所述安全数据的类型包括副密钥,或,副密钥和向量;
所述候选数据规整子模块包括:
第一摘要计算单元,设置为在所述可信执行环境中,响应于所述标签为第一值,对所述候选数据计算第一指定长度的摘要数据,所述第一指定长度的摘 要数据作为副密钥、向量;
或者,
第二摘要计算单元,设置为在所述可信执行环境中,响应于所述标签为第二值,对所述候选数据计算第二指定长度的摘要数据,所述第二指定长度的摘要数据作为副密钥。
在本申请的一个实施例中,所述安全数据包括副密钥,或,副密钥和向量;
所述目标数据解密模块1105包括:
第一对称解密子模块,设置为在所述非可信执行环境中,调用对称密钥算法中的高级加密标准AES算法、使用所述向量作为初始化向量、与所述副密钥共同将所述目标数据解密为源数据;
或者,
第二对称解密子模块,设置为在所述非可信执行环境中,调用对称密钥算法中的非AES算法、使用所述副密钥将所述目标数据解密为源数据。
在本申请的一个实施例中,还包括:
安装操作检测模块,设置为检测在非可信执行环境中安装应用的第一操作;
主密钥生成模块,设置为响应于所述第一操作,在可信执行环境中为所述应用生成主密钥。
在本申请的一个实施例中,还包括:
关联存储模块,设置为在所述非可信执行环境中,关联存储所述目标数据与所述参考数据。
在本申请的一个实施例中,还包括:
删除操作检测模块,设置为检测删除所述目标数据的第二操作;
关联删除模块,设置为响应于所述第二操作,在所述非可信执行环境中删除所述目标数据与所述参考数据。
在本申请的一个实施例中,还包括:
卸载操作检测模块,设置为检测卸载所述应用的第三操作;
主密钥删除模块,设置为响应于所述第三操作,在所述可信执行环境中删除所述应用生成的主密钥;
全量数据删除模块,设置为响应于所述第三操作,在所述非可信执行环境中删除所有的所述目标数据与所有的所述参考数据。
本申请实施例所提供的数据解密装置可执行本申请任意实施例所提供的数据解密方法,具备执行方法相应的功能模块和有益效果。
实施例六
图12为本申请实施例六提供的一种移动终端的结构示意图。如图12所示,该移动终端包括处理器1200、存储器1201、通信模块1202、输入装置1203和输出装置1204;移动终端中处理器1200的数量可以是一个或多个,图12中以一个处理器1200为例;移动终端中的处理器1200、存储器1201、通信模块1202、输入装置1203和输出装置1204可以通过总线或其他方式连接,图12中以通过总线连接为例。
存储器1201作为一种计算机可读存储介质,可用于存储软件程序、计算机可执行程序以及模块,如本实施例中的数据加密方法、数据解密方法对应的模块,例如,如图10所示的数据加密装置中的源数据确定模块1001、参考数据生成模块1002、主密钥读取模块1003、安全数据生成模块1004与源数据加密模块1005;如图11所示的数据解密装置中目标数据确定模块1101、参考数据读取模块1102、主密钥读取模块1103、安全数据生成模块1104与目标数据解密模块1105。处理器1200通过运行存储在存储器1201中的软件程序、指令以及模块,执行移动终端的多种功能应用以及数据处理,即实现上述的数据加密方法、数据解密方法。
存储器1201可主要包括存储程序区和存储数据区,其中,存储程序区可存储操作系统、至少一个功能所需的应用程序,操作系统可为通用操作系统和可信操作系统中的至少一个;存储数据区可存储根据移动终端的使用所创建的数据等。此外,存储器1201可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件、闪存器件、或其他非易失性固态存储器件。在一些实例中,存储器1201可包括相对于处理器1200远程设置的存储器,这些远程存储器可以通过网络连接至移动终端。上述网络的实例包括互联网、企业内部网、局域网、移动通信网及组合等。
通信模块1202,设置为与显示屏建立连接,并实现与显示屏的数据交互。
输入装置1203可设置为接收输入的数字或字符信息,以及产生与移动终端的用户设置以及功能控制有关的键信号输入,还可以是用于获取图像的摄像头以及获取音频数据的拾音设备。
输出装置1204可以包括扬声器等音频设备。
输入装置1203和输出装置1204的组件可以根据实际情况设定。
处理器1200通过运行存储在存储器1201中的软件程序、指令以及模块, 执行移动终端的多种功能应用以及数据处理,即实现上述的数据加密方法、数据解密方法。
本实施例提供的移动终端,可执行本申请任一实施例提供的数据加密方法、数据解密方法,实现相应的功能和有益效果。
实施例七
本申请实施例七还提供一种计算机可读存储介质,计算机可读存储介质上存储有计算机程序,该计算机程序被处理器执行时实现一种数据加密方法或数据解密方法。
该数据加密方法包括:
在非可信执行环境中,确定应用请求加密的源数据;
在所述非可信执行环境中,生成与所述源数据对应的参考数据,所述参考数据是加密所述源数据的过程中一次性使用的数据;
在可信执行环境中,读取为所述应用生成的主密钥;
在所述可信执行环境中,使用所述主密钥对所述参考数据进行加密处理,获得安全数据;
在所述非可信执行环境中,使用所述安全数据对所述源数据进行加密,得到目标数据。
该数据解密方法包括:
在非可信执行环境中,确定应用请求解密的目标数据;
在所述非可信执行环境中,读取与所述目标数据关联的参考数据,所述参考数据是解密所述目标数据的过程中一次性使用的数据;
在可信执行环境中,读取为所述应用生成的主密钥;
在所述可信执行环境中,使用所述主密钥对所述参考数据进行加密处理,获得安全数据;
在所述非可信执行环境中,使用所述安全数据对所述目标数据进行解密,获得源数据。
本申请实施例所提供的计算机可读存储介质中的计算机程序不限于如上所述的方法操作,本申请实施例还可以执行本申请任意实施例所提供的数据加密方法、数据解密方法中的相关操作。
通过以上关于实施方式的描述,所属领域的技术人员可以清楚地了解到,本申请可借助软件及通用硬件来实现,也可以通过硬件实现。基于这样的理解, 本申请实施例本质上或者说对相关技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如计算机的软盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、闪存(FLASH)、硬盘或光盘等,该计算机软件产品可包括多个指令用以使得一台移动终端执行本申请多个实施例所述的方法,移动终端可以是个人计算机,服务器,或者网络设备等。
上述数据加密装置、数据解密装置的实施例中,所包括的多个单元和模块只是按照功能逻辑进行划分的,但并不局限于上述的划分,只要能够实现相应的功能即可;另外,每个功能单元的名称也只是为了便于相互区分。

Claims (17)

  1. 一种数据加密方法,包括:
    在非可信执行环境中,确定应用请求加密的源数据;
    在所述非可信执行环境中,生成与所述源数据对应的参考数据,所述参考数据是加密所述源数据的过程中一次性使用的数据;
    在可信执行环境中,读取为所述应用生成的主密钥;
    在所述可信执行环境中,使用所述主密钥对所述参考数据进行加密处理,获得安全数据;
    在所述非可信执行环境中,使用所述安全数据对所述源数据进行加密,得到目标数据。
  2. 根据权利要求1所述的方法,其中,所述在所述非可信执行环境中,生成与所述源数据对应的参考数据,包括:
    在所述非可信执行环境中,随机生成一数值,作为参考数据;
    和/或,
    在所述非可信执行环境中,读取当前的时间戳,作为参考数据。
  3. 根据权利要求1所述的方法,其中,所述在所述可信执行环境中,使用所述主密钥对所述参考数据进行加密处理,获得安全数据,包括:
    在所述可信执行环境中,将所述参考数据与预设的标签组合,得到目标数组,所述标签用于表示安全数据的类型;
    在所述可信执行环境中,使用所述主密钥将所述目标数组加密,得到候选数据;
    在所述可信执行环境中,对所述候选数据规整为指定长度的数据,将所述指定长度的数据作为与所述标签匹配的安全数据。
  4. 根据权利要求3所述的方法,其中,所述安全数据的类型包括副密钥,或,副密钥和向量;
    所述在所述可信执行环境中,对所述候选数据规整为指定长度的数据,将所述指定长度的数据作为与所述标签匹配的安全数据,包括:
    在所述可信执行环境中,响应于所述标签为第一值,对所述候选数据计算第一指定长度的摘要数据,所述第一指定长度的摘要数据作为副密钥、向量;
    或者,
    在所述可信执行环境中,响应于所述标签为第二值,对所述候选数据计算第二指定长度的摘要数据,所述第二指定长度的摘要数据作为副密钥。
  5. 根据权利要求1所述的方法,其中,所述安全数据包括副密钥,或,副 密钥和向量;
    所述在所述非可信执行环境中,使用所述安全数据对所述源数据进行加密,得到目标数据,包括:
    在所述非可信执行环境中,调用对称密钥算法中的高级加密标准AES算法、使用所述向量作为初始化向量、与所述副密钥共同将所述源数据加密为目标数据;
    或者,
    在所述非可信执行环境中,调用对称密钥算法中的非AES算法、使用所述副密钥将所述源数据加密为目标数据。
  6. 根据权利要求1-5任一项所述的方法,还包括:
    在所述非可信执行环境中,关联存储所述目标数据与所述参考数据。
  7. 根据权利要求6所述的方法,还包括:
    检测删除所述目标数据的第二操作;
    响应于所述第二操作,在所述非可信执行环境中删除所述目标数据与所述参考数据。
  8. 根据权利要求1-5任一项所述的方法,还包括:
    检测卸载所述应用的第三操作;
    响应于所述第三操作,在所述可信执行环境中删除为所述应用生成的主密钥;
    响应于所述第三操作,在所述非可信执行环境中删除所述目标数据与所述参考数据。
  9. 一种数据解密方法,包括:
    在非可信执行环境中,确定应用请求解密的目标数据;
    在所述非可信执行环境中,读取与所述目标数据关联的参考数据,所述参考数据是解密所述目标数据的过程中一次性使用的数据;
    在可信执行环境中,读取为所述应用生成的主密钥;
    在所述可信执行环境中,使用所述主密钥对所述参考数据进行加密处理,获得安全数据;
    在所述非可信执行环境中,使用所述安全数据对所述目标数据进行解密,获得源数据。
  10. 根据权利要求9所述的方法,还包括:
    在所述非可信执行环境中,关联存储所述目标数据与所述参考数据。
  11. 根据权利要求10所述的方法,还包括:
    检测删除所述目标数据的第二操作;
    响应于所述第二操作,在所述非可信执行环境中删除所述目标数据与所述参考数据。
  12. 一种数据加密装置,包括:
    源数据确定模块,设置为在非可信执行环境中,确定应用请求加密的源数据;
    参考数据生成模块,设置为在所述非可信执行环境中,生成与所述源数据对应的参考数据,所述参考数据是加密所述源数据的过程中一次性使用的数据;
    主密钥读取模块,设置为在可信执行环境中,读取为所述应用生成的主密钥;
    安全数据生成模块,设置为在所述可信执行环境中,使用所述主密钥对所述参考数据进行加密处理,获得安全数据;
    源数据加密模块,设置为在所述非可信执行环境中,使用所述安全数据对所述源数据进行加密,得到目标数据。
  13. 根据权利要求12所述的装置,其中,所述参考数据生成模块包括:
    随机数值生成子模块,设置为在所述非可信执行环境中,随机生成一数值,作为参考数据;
    和/或,
    时间戳读取子模块,设置为在所述非可信执行环境中,读取当前的时间戳,作为参考数据。
  14. 一种数据解密装置,包括:
    目标数据确定模块,设置为在非可信执行环境中,确定应用请求解密的目标数据;
    参考数据读取模块,设置为在所述非可信执行环境中,读取与所述目标数据关联的参考数据,所述参考数据是解密所述目标数据的过程中一次性使用的数据;
    主密钥读取模块,设置为在可信执行环境中,读取为所述应用生成的主密钥;
    安全数据生成模块,设置为在所述可信执行环境中,使用所述主密钥对所述参考数据进行加密处理,获得安全数据;
    目标数据解密模块,设置为在所述非可信执行环境中,使用所述安全数据 对所述目标数据进行解密,获得源数据。
  15. 根据权利要求14所述的装置,其中,所述安全数据生成模块包括:
    目标数组组合子模块,设置为在所述可信执行环境中,将所述参考数据与预设的标签组合,得到目标数组,所述标签用于表示安全数据的类型;
    候选数据生成子模块,设置为使用所述主密钥将所述目标数组加密,得到候选数据;
    候选数据规整子模块,设置为对所述候选数据规整为指定长度的数据,将所述指定长度的数据作为与所述标签匹配的安全数据。
  16. 一种移动终端,所述移动终端包括:
    一个或多个处理器;
    存储器,设置为存储一个或多个程序;
    所述一个或多个处理器,设置为执行所述一个或多个程序以实现如权利要求1-8中任一所述的数据加密方法或者如权利要求9-11中任一所所述的数据解密方法。
  17. 一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现如权利要求1-8中任一所述的数据加密方法或者如权利要求9-11中任一所所述的数据解密方法。
PCT/CN2021/108935 2020-08-07 2021-07-28 数据加密方法、数据解密方法、装置、终端和存储介质 WO2022028289A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
US18/040,796 US20240031129A1 (en) 2020-08-07 2021-07-28 Data encryption method, data decryption method, terminal, and storage medium
EP21852390.0A EP4195583A4 (en) 2020-08-07 2021-07-28 DATA ENCRYPTION METHOD AND APPARATUS, DATA DECRYPTION METHOD AND APPARATUS, TERMINAL AND RECORDING MEDIUM

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010790159.3A CN111917540B (zh) 2020-08-07 2020-08-07 一种数据加解密方法、装置、移动终端和存储介质
CN202010790159.3 2020-08-07

Publications (1)

Publication Number Publication Date
WO2022028289A1 true WO2022028289A1 (zh) 2022-02-10

Family

ID=73283593

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/108935 WO2022028289A1 (zh) 2020-08-07 2021-07-28 数据加密方法、数据解密方法、装置、终端和存储介质

Country Status (4)

Country Link
US (1) US20240031129A1 (zh)
EP (1) EP4195583A4 (zh)
CN (1) CN111917540B (zh)
WO (1) WO2022028289A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116049913A (zh) * 2022-05-24 2023-05-02 荣耀终端有限公司 数据保存方法、装置、电子设备及计算机可读存储介质

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111917540B (zh) * 2020-08-07 2023-05-12 广州市百果园信息技术有限公司 一种数据加解密方法、装置、移动终端和存储介质
CN113542303B (zh) * 2021-08-03 2023-05-09 上海瓶钵信息科技有限公司 秘钥在非可信环境的软件导入系统及方法
EP4145762B1 (en) * 2021-09-06 2023-10-25 Axis AB Method and system for enabling secure processing of data using a processing application
CN114553412B (zh) * 2022-02-28 2024-02-23 百果园技术(新加坡)有限公司 一种数据传输方法、装置、设备及存储介质
CN116707801A (zh) * 2023-08-04 2023-09-05 北京滴普科技有限公司 程序测试用文件数据保护方法、装置、设备及存储介质
CN118337370A (zh) * 2024-06-17 2024-07-12 成都中创锐科信息技术有限公司 基于aes算法的波形数据加密保存与传输方法

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105812332A (zh) * 2014-12-31 2016-07-27 北京握奇智能科技有限公司 数据保护方法
US20170206174A1 (en) * 2016-01-15 2017-07-20 Bittium Wireless Oy Secure memory storage
CN110110548A (zh) * 2019-04-12 2019-08-09 深圳市中易通安全芯科技有限公司 基于加密芯片的可信执行环境下文件加密存储的相关方法
CN111444528A (zh) * 2020-03-31 2020-07-24 海信视像科技股份有限公司 数据安全保护方法、装置及存储介质
CN111917540A (zh) * 2020-08-07 2020-11-10 广州市百果园信息技术有限公司 一种数据加解密方法、装置、移动终端和存储介质

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070101122A1 (en) * 2005-09-23 2007-05-03 Yile Guo Method and apparatus for securely generating application session keys
KR20150050231A (ko) * 2013-10-31 2015-05-08 한국전자통신연구원 폐쇄 도메인에서의 키 생성 장치 및 방법
CN106980794B (zh) * 2017-04-01 2020-03-17 北京元心科技有限公司 基于TrustZone的文件加解密方法、装置及终端设备
US10922441B2 (en) * 2018-05-04 2021-02-16 Huawei Technologies Co., Ltd. Device and method for data security with a trusted execution environment

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105812332A (zh) * 2014-12-31 2016-07-27 北京握奇智能科技有限公司 数据保护方法
US20170206174A1 (en) * 2016-01-15 2017-07-20 Bittium Wireless Oy Secure memory storage
CN110110548A (zh) * 2019-04-12 2019-08-09 深圳市中易通安全芯科技有限公司 基于加密芯片的可信执行环境下文件加密存储的相关方法
CN111444528A (zh) * 2020-03-31 2020-07-24 海信视像科技股份有限公司 数据安全保护方法、装置及存储介质
CN111917540A (zh) * 2020-08-07 2020-11-10 广州市百果园信息技术有限公司 一种数据加解密方法、装置、移动终端和存储介质

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP4195583A4 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116049913A (zh) * 2022-05-24 2023-05-02 荣耀终端有限公司 数据保存方法、装置、电子设备及计算机可读存储介质
CN116049913B (zh) * 2022-05-24 2023-11-03 荣耀终端有限公司 数据保存方法、装置、电子设备及计算机可读存储介质

Also Published As

Publication number Publication date
CN111917540A (zh) 2020-11-10
CN111917540B (zh) 2023-05-12
US20240031129A1 (en) 2024-01-25
EP4195583A4 (en) 2024-08-28
EP4195583A1 (en) 2023-06-14

Similar Documents

Publication Publication Date Title
WO2022028289A1 (zh) 数据加密方法、数据解密方法、装置、终端和存储介质
CN112074836B (zh) 通过可信执行环境保护数据的设备和方法
KR100996784B1 (ko) 공개 키 암호화에 기초한 데이터의 저장 및 검색을 위한, 컴퓨팅 장치에서 구현되는 방법, 시스템 및 복수의 명령어를 저장하는 하나 이상의 컴퓨터 판독가능 매체
KR101067399B1 (ko) 대칭 키 암호화에 기초한 데이터의 저장 및 검색을 위한, 컴퓨팅 장치에서 구현되는 방법, 시스템 및 복수의 명령어를 저장하는 하나 이상의 컴퓨터 판독가능 매체
US20210034765A1 (en) Computational Operations in Enclave Computing Environments
WO2019105290A1 (zh) 数据处理方法、可信用户界面资源数据的应用方法及装置
US7639819B2 (en) Method and apparatus for using an external security device to secure data in a database
US7480806B2 (en) Multi-token seal and unseal
WO2019218919A1 (zh) 区块链场景下的私钥管理方法、装置及系统
US9054865B2 (en) Cryptographic system and methodology for securing software cryptography
WO2022083324A1 (zh) 消息加密方法及装置、消息解密方法及装置、移动终端
CN104392188A (zh) 一种安全数据存储方法和系统
CN106980793B (zh) 基于TrustZone的通用口令存储及读取方法、装置及终端设备
CN107506659A (zh) 一种基于sgx的通用数据库的数据保护系统及方法
WO2018019134A1 (zh) 验证码短信的处理方法及终端
CN106992851A (zh) 基于TrustZone的数据库文件口令加解密方法、装置及终端设备
da Rocha et al. Trusted Client-Side Encryption for Cloud Storage
EP3009952A1 (en) System and method for protecting a device against attacks on procedure calls by encrypting arguments

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21852390

Country of ref document: EP

Kind code of ref document: A1

WWE Wipo information: entry into national phase

Ref document number: 18040796

Country of ref document: US

NENP Non-entry into the national phase

Ref country code: DE

ENP Entry into the national phase

Ref document number: 2021852390

Country of ref document: EP

Effective date: 20230307