WO2017185312A1 - 加密、解密方法及装置 - Google Patents

加密、解密方法及装置 Download PDF

Info

Publication number
WO2017185312A1
WO2017185312A1 PCT/CN2016/080571 CN2016080571W WO2017185312A1 WO 2017185312 A1 WO2017185312 A1 WO 2017185312A1 CN 2016080571 W CN2016080571 W CN 2016080571W WO 2017185312 A1 WO2017185312 A1 WO 2017185312A1
Authority
WO
WIPO (PCT)
Prior art keywords
ciphertext
plaintext
sequence
location
input
Prior art date
Application number
PCT/CN2016/080571
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 CN201680014791.0A priority Critical patent/CN108028754B/zh
Priority to PCT/CN2016/080571 priority patent/WO2017185312A1/zh
Publication of WO2017185312A1 publication Critical patent/WO2017185312A1/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/14Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols using a plurality of keys or algorithms
    • H04L9/16Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols using a plurality of keys or algorithms the keys or algorithms being changed during operation

Definitions

  • the present invention relates to the field of communications technologies, and in particular, to a method and an apparatus for encrypting and decrypting.
  • the input method When a user logs in to a third-party application using a terminal, it is necessary to input key information such as an account number and a password through an input method. If the input method transmits the information input to the third-party application and is monitored by a Trojan virus, etc., the account and the input account will be Information such as passwords is stolen by malicious programs. Therefore, the input method needs to be secured to prevent the input information from being stolen.
  • a conventional encryption and decryption algorithm is usually used.
  • the input method uses a conventional encryption algorithm to encrypt the information, and then the ciphertext is transmitted to the SDK, and the SDK performs correspondingly.
  • the decryption the input of the original information, for use by third-party applications, where the SDK is a software development kit built into third-party applications.
  • the algorithm encrypts the continuous plaintext sequence by byte or bit, which has the advantage of reducing the overhead of ciphertext delivery and eliminating the ciphertext length extension, but Since the algorithm encrypts consecutive bytes or bits, if it is necessary to insert, modify, or delete the encrypted information, the encryption of the entire sequence input before will be invalidated, and therefore, the user cannot input the input. The need for information to be inserted, modified, and deleted in real time.
  • the embodiment of the invention provides an encryption and decryption method and device for satisfying the requirement for the user to insert, modify and delete the input information in real time.
  • an encryption method comprising:
  • the first ciphertext sequence includes i ciphertexts corresponding to the i plaintexts, and the first location information includes location indication information and input indication information of each of the i ciphertexts.
  • the location indication information of a ciphertext is used to indicate the location of the ciphertext in the first ciphertext sequence, and the input indication information of a ciphertext is used to indicate the input order of the plaintext corresponding to the ciphertext;
  • the terminal may generate each plaintext encryption according to the master key and the built-in keystream generator.
  • the key stream generator includes a monotonically increasing counter, and the preset length of the counter can be represented as L.
  • the preset length L of the counter is 128 bits, since 8 bits are equal to 1 byte, Therefore, the preset length L of the counter can also be 16 bytes, and when the length of the plaintext received by the terminal is calculated in bytes, if the current value of the counter is N, the value of the counter is received every time the terminal receives 16 bytes. Add 1 to the current value to N+1, and N is an integer greater than or equal to 1.
  • the editing operation is any one of deleting, inserting, and replacing.
  • the location indication information is a location of the ciphertext in the first ciphertext sequence.
  • the serial number indicates that the input indication information is an input serial number of the plaintext corresponding to the ciphertext.
  • the modifying the first secret based on the editing operation when the editing operation is deleted, the modifying the first secret based on the editing operation
  • the sequence of the text and the first location information obtain the second ciphertext sequence and the second location information, specifically:
  • the modifying the first secret based on the editing operation obtain the second ciphertext sequence and the second location information, specifically:
  • the ciphertext is moved backward by one bit to obtain a second ciphertext sequence, and the location of the target ciphertext in the first ciphertext sequence is the same as the inserted plaintext location;
  • a fifth possible implementation manner of the first aspect when the editing operation is a replacement, the modifying the operation based on the editing operation Deriving the first ciphertext sequence and the first location information to obtain a second ciphertext sequence and second location information, specifically:
  • the second location information is obtained.
  • the terminal can not only operate by the above-mentioned replacement method, but also can perform operations by first deleting and then inserting, that is, according to the third possible implementation manner of the foregoing first aspect.
  • the deletion is performed, and then inserted according to the fourth possible implementation manner of the above first aspect to complete the corresponding replacement.
  • a decryption method comprising:
  • the second ciphertext sequence includes j ciphertexts
  • the second location information includes location indication information and input indication information of each ciphertext in the j ciphertexts
  • the location indication information of a cipher text is used to indicate the location of the ciphertext in the second ciphertext sequence
  • the input indication information of a ciphertext is used to indicate the input order of the plaintext corresponding to the ciphertext. J ⁇ 1;
  • the ciphertext is decrypted based on the input indication information of the ciphertext in the master key and the second location information, Obtaining the plaintext corresponding to the ciphertext, including:
  • first value and the second value are determined according to the input indication information of the ciphertext, and the first value and the second value are integers greater than or equal to 0.
  • the master key in the decryption method is consistent with the master key in the encryption method
  • the key stream generator in the decryption method is similar to the key stream generator in the above encryption method, and the embodiment of the present invention does not Let me repeat.
  • the location indication information is a location of the ciphertext in the second ciphertext sequence.
  • the serial number indicates that the input indication information is an input serial number of the plaintext corresponding to the ciphertext.
  • the input indication information is an input sequence number of the plaintext corresponding to the ciphertext
  • the The input indication information of the ciphertext in the second location information is obtained by acquiring the first value and the second value, specifically:
  • the quotient of the division is determined as the first value, and the second value is determined to be zero;
  • the quotient of the division is determined as the first value, and the remainder of the division is determined as the second value.
  • the first value is represented as P
  • the second value is represented as Q
  • the input number of the plaintext corresponding to the ciphertext is represented as S
  • the first value is obtained according to the input indication information S of the ciphertext in the second location information.
  • an encryption device comprising:
  • a receiving unit configured to receive the input i plaintext, where i ⁇ 1;
  • An encryption unit configured to encrypt each plaintext in the i plaintext based on the master key according to the input order of the plaintext, to obtain a first ciphertext sequence and a first corresponding to the first ciphertext sequence Position information, the first ciphertext sequence includes i ciphertexts corresponding to the i plaintexts, and the first location information includes location indication information of each ciphertext of the i ciphertexts Entering the indication information, the location indication information of a ciphertext is used to indicate the location of the ciphertext in the first ciphertext sequence, and the input indication information of a ciphertext is used to indicate the input order of the plaintext corresponding to the ciphertext ;
  • An editing unit configured to modify the first ciphertext sequence and the first location information to obtain a second ciphertext sequence and a second, if the editing operation of the input plaintext is detected, based on the editing operation Location information, the order of the ciphertext in the second ciphertext sequence is consistent with the sequence of the edited plaintext, and the location indication information of each ciphertext in the second location information is used to indicate that the corresponding ciphertext is in the The position in the second ciphertext sequence;
  • a sending unit configured to send the second ciphertext sequence and the second location information.
  • the editing operation is any one of deleting, inserting, and replacing.
  • the location indication information is a location of the ciphertext in the first ciphertext sequence.
  • the serial number indicates that the input indication information is an input serial number of the plaintext corresponding to the ciphertext.
  • the editing unit when the editing operation is deleted, if the editing operation of the input plaintext is detected, the editing unit is specifically used for:
  • the editing unit when the editing operation is an insertion, if an edit operation of the input plaintext is detected,
  • the editing unit is specifically used for:
  • the editing unit when the editing operation is a replacement, if an edit operation of the input plaintext is detected,
  • the editing unit is specifically used for:
  • the second location information is obtained.
  • a decryption apparatus comprising:
  • a receiving unit configured to receive a second ciphertext sequence and a second location information, where the second ciphertext sequence includes j ciphertexts, where the second location information includes a location indication of each ciphertext in the j ciphertexts Information and input indication information, a location indication information of a ciphertext is used to indicate a location of the ciphertext in the second ciphertext sequence, and an input indication information of a ciphertext is used to indicate a plaintext corresponding to the ciphertext Input order, said j ⁇ 1;
  • a decrypting unit configured to, for each ciphertext in the second ciphertext sequence, decrypt the ciphertext based on the input indication information of the ciphertext in the master key and the second location information, to obtain The plaintext corresponding to the ciphertext;
  • a determining unit configured to determine a location of the plaintext corresponding to each ciphertext based on the location indicated by the location indication information of each ciphertext in the second location information.
  • the decrypting unit for each ciphertext in the second ciphertext sequence, is specifically configured to:
  • the location indication information is a location of the ciphertext in the second ciphertext sequence.
  • the serial number indicates that the input indication information is an input serial number of the plaintext corresponding to the ciphertext.
  • the decryption unit when the input indication information is an input sequence number of the plaintext corresponding to the ciphertext, the decryption unit Also specifically used for:
  • the quotient of the division is determined as the first value, and the second value is determined to be zero;
  • the quotient of the division is determined as the first value, and the remainder of the division is determined as the second value.
  • a fifth aspect provides a terminal, where the terminal includes: a processor, a memory, an input unit, a system bus, and a communication interface;
  • the memory is configured to store a computer execution instruction
  • the processor is connected to the memory through the system bus
  • the input unit is configured to receive input information
  • the processor executes the The computer stored in the memory executes instructions to cause the terminal to perform the encryption method of any one of the first aspect to the fifth possible implementation of the first aspect.
  • a sixth aspect provides a terminal, where the terminal includes: a processor, a memory, a system bus, and a communication interface;
  • the memory is configured to store a computer execution instruction
  • the processor is connected to the memory through the system bus, and when the terminal is running, the processor executes the computer execution instruction stored in the memory, so that The terminal performs the decryption method of any one of the second aspect to the third possible implementation of the second aspect.
  • An encryption and decryption method and apparatus receive an input i plaintext, and encrypting each plaintext in the i plaintext based on the master key according to the input order of the plaintext, obtaining the first ciphertext sequence and the first location information corresponding to the first ciphertext sequence, and detecting For the editing operation of the input plaintext, based on the editing operation, modifying the first ciphertext sequence and the first location information to obtain the second ciphertext sequence and the second location information, and the order and editing of the ciphertext in the second ciphertext sequence
  • the order of the plaintexts is the same.
  • the location indication information of each ciphertext in the second location information is used to indicate the location of the corresponding ciphertext in the second ciphertext sequence, and then the second ciphertext sequence and the second location.
  • the information is sent to the receiving end, so that the receiving end decrypts the second ciphertext sequence based on the recorded second location information, and obtains the corresponding plaintext, so as not to affect the encryption of the entire sequence input before, It can satisfy the user's real-time editing, insertion and replacement of the input information, which improves the speed of encryption and decryption to a certain extent.
  • FIG. 1 is a schematic structural diagram of a terminal according to an embodiment of the present disclosure
  • FIG. 2 is a schematic flowchart of an encryption method according to an embodiment of the present invention.
  • FIG. 3 is a schematic diagram of a display interface of a terminal according to an embodiment of the present disclosure.
  • FIG. 4 is a schematic diagram of a display interface of another terminal according to an embodiment of the present invention.
  • FIG. 5 is a schematic diagram of a display interface of another terminal according to an embodiment of the present disclosure.
  • FIG. 6 is a schematic diagram of a display interface of another terminal according to an embodiment of the present disclosure.
  • FIG. 7 is a schematic flowchart diagram of a decryption method according to an embodiment of the present invention.
  • FIG. 8 is a schematic structural diagram of an encryption apparatus according to an embodiment of the present disclosure.
  • FIG. 9 is a schematic structural diagram of a decryption apparatus according to an embodiment of the present invention.
  • the application scenario of the present invention is first introduced.
  • terminals such as mobile phones, tablet computers, computers, etc.
  • applications such as Weibo, chat, readers and games.
  • the input method side encrypts the input information and sends the encrypted information to the third party.
  • the application, the third-party application SDK (English: Software Development Kit, Chinese software development kit) decrypts the encrypted information accordingly, thereby obtaining the input account and password for use by third-party applications.
  • the input information is often encrypted by a stream cipher algorithm, such as the RC4 algorithm, but the algorithm encrypts successive plaintext sequences by bytes or bits, but in the field of communication technology, data communication and In the network protocol, the message transmission is a continuous output. Therefore, if the sender needs to modify the encrypted message, for example, if the user deletes, inserts or modifies the previously input application account and password, the entire sequence previously input is performed.
  • the encryption will be void.
  • the basic principle of the present invention is that when the input information such as the application account and the password input by the user is encrypted, the location information of each input character is recorded, and when the user deletes, inserts or modifies the input information, the user is based on the editing operation. Corresponding editing operation, correspondingly modifying the previously recorded location information, and transmitting the encrypted input information and location information to the receiving end, so that the receiving end decrypts the encrypted input information based on the recorded location information, Enter the corresponding application account and password.
  • FIG. 1 is a schematic structural diagram of a terminal according to an embodiment of the present invention.
  • the terminal may be a mobile phone, a tablet computer, a notebook computer, an UMPC (Ultra-mobile Personal Computer), a netbook, or a PDA (Personal Digital Assistant).
  • the terminal is a mobile phone as an example.
  • FIG. 1 is a block diagram showing a partial structure of a mobile phone related to various embodiments of the present invention.
  • the mobile phone 100 includes a memory 110, a processor 120, an input unit 130, a display unit 140, an RF (radio frequency) circuit 150, an audio circuit 160, a power source 170, and a system bus not shown. Communication interface, etc.
  • a memory 110 a processor 120, an input unit 130, a display unit 140, an RF (radio frequency) circuit 150, an audio circuit 160, a power source 170, and a system bus not shown. Communication interface, etc.
  • RF radio frequency
  • the components of the mobile phone 100 will be specifically described below with reference to FIG. 1 :
  • the memory 110 can be used to store software programs and modules, and the processor 120 executes various functional applications and data processing of the mobile phone 100 by running software programs and modules stored in the memory 110.
  • the memory 110 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application required for at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may be stored according to The data created by the use of the mobile phone 100 (such as audio data, image data, phone book, etc.) and the like.
  • the memory 110 may include a high speed random access memory, and may also include a nonvolatile memory such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device.
  • the processor 120 is a control center of the handset 100 that connects various portions of the entire handset using various interfaces and lines, by running or executing software programs and/or modules stored in the memory 110, and recalling data stored in the memory 110, The various functions and processing data of the mobile phone 100 are executed to perform overall monitoring of the mobile phone.
  • the processor 120 may include one or more processing units; preferably, the processor 120 may integrate an application processor and a modem processor, where the application processor mainly processes an operating system, a user interface, an application, and the like.
  • the modem processor primarily handles wireless communications. It can be understood that the above modem processor may not be integrated into the processor 120.
  • the input unit 130 can be configured to receive input numeric or character information and to generate key signal inputs related to user settings and function control of the handset 100.
  • the input unit 130 may include a touch screen 131 and other input devices 132.
  • the touch screen 131 also referred to as a touch panel, can collect touch operations on or near the user (such as the operation of the user using any suitable object or accessory on the touch screen 131 or near the touch screen 131 using a finger, a stylus, etc.), and The corresponding connecting device is driven according to a preset program.
  • the touch screen 131 may include two parts of a touch detection device and a touch controller.
  • the touch detection device detects the touch orientation of the user, and detects a signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts the touch information into contact coordinates, and sends the touch information.
  • the processor 120 is provided and can receive commands from the processor 120 and execute them.
  • the touch screen 131 can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic waves.
  • the input unit 130 may also include other input devices 132.
  • the invention includes, but is not limited to, one or more of a physical keyboard, function keys (such as a volume control button, a power switch button, etc.), a trackball, a mouse, a joystick, and the like.
  • function keys such as a volume control button, a power switch button, etc.
  • trackball such as a mouse, a joystick, and the like.
  • the display unit 140 can be used to display information input by the user or information provided to the user and various menus of the mobile phone 100.
  • the display unit 140 may include a display panel 141.
  • the display panel 141 may be configured in the form of an LCD (Liquid Crystal Display), an OLED (Organic Light-Emitting Diode), or the like.
  • the touch screen 131 may cover the display panel 141, and when the touch screen 131 detects a touch operation on or near it, transmits to the processor 120 to determine the type of the touch event, and then the processor 120 displays the panel according to the type of the touch event. A corresponding visual output is provided on 141.
  • touch screen 131 and the display panel 141 are two separate components to implement the input and input functions of the mobile phone 400 in FIG. 1, in some embodiments, the touch screen 131 and the display panel 141 may be integrated to implement the mobile phone 100. Input and output functions.
  • the RF circuit 150 can be used to transmit and receive information or receive and transmit signals during a call.
  • RF circuits include, but are not limited to, an antenna, at least one amplifier, a transceiver, a coupler, an LNA (low noise amplifier), a duplexer, and the like.
  • RF circuitry 150 can also communicate with the network and other devices via wireless communication.
  • the wireless communication may use any communication standard or protocol, including but not limited to GSM (global system of mobile communication), GPRS (general packet radio service), CDMA (code division multiple access) , code division multiple access), WCDMA (wideband code division multiple access), LTE (long term evolution), e-mail, SMS (short messaging service), and the like.
  • the audio circuit 160, the speaker 161, and the microphone 162 can provide an audio interface between the user and the handset 100.
  • the audio circuit 160 can transmit the converted electrical data of the received audio data to the speaker 161 for conversion to the sound signal output by the speaker 161; on the other hand, the microphone 162 converts the collected sound signal into an electrical signal by the audio circuit 160. After receiving, it is converted into audio data, and the audio data is output to the RF circuit 150 for transmission to, for example, another mobile phone, or the audio data is output to the memory 110 for further processing.
  • the mobile phone 100 also includes a power source 170 (such as a battery) that supplies power to various components.
  • a power source 170 such as a battery
  • the power source can be logically coupled to the processor 120 through a power management system to manage functions such as charging, discharging, and power management through the power management system.
  • the mobile phone 100 may further include a sensor module, an audio module, a WiFi (Wireless Fidelity) module, a Bluetooth module, and the like, and details are not described herein.
  • a sensor module an audio module
  • a WiFi (Wireless Fidelity) module a WiFi (Wireless Fidelity) module
  • a Bluetooth module a Bluetooth module
  • FIG. 2 is a schematic flowchart of an encryption method according to an embodiment of the present invention. The method is applied to a terminal. Referring to FIG. 2, the method includes the following steps.
  • Step 201 Receive input i plaintext, where i ⁇ 1.
  • Step 202 Encrypt each plaintext in the i plaintext based on the master key according to the input order of the plaintext, to obtain a first ciphertext sequence and first location information corresponding to the first ciphertext sequence; wherein, the first The ciphertext sequence includes i ciphertexts corresponding to i plaintexts, and the first location information includes location indication information and input indication information of each ciphertext in the ciphertext, and location indication information of a ciphertext is used to indicate the ciphertext. The position of the text in the first ciphertext sequence, the input indication information of a ciphertext is used to indicate the input order of the plaintext corresponding to the ciphertext.
  • the location indication information of each ciphertext included in the first ciphertext may be a location number of the ciphertext in the first ciphertext sequence, and each of the ciphertexts included in the first location information is dense.
  • the input indication information of the text may be the input number of the plaintext corresponding to the ciphertext.
  • the location indication information and the input indication information may also be other, and only the location indication information of each ciphertext is ensured.
  • the input indication information of each ciphertext is used to indicate the input order of the plaintext corresponding to the ciphertext, which is not limited in the embodiment of the present invention.
  • the terminal When the terminal encrypts each plaintext in the i plaintext based on the master key according to the input order of the i plaintexts, the terminal may generate each plaintext encryption according to the master key and the built-in keystream generator.
  • the key stream generator includes a monotonically increasing counter, and the preset length of the counter can be represented as L.
  • the preset length L of the counter is 128 bits. Since 8 bits are equal to 1 byte, the counter is The preset length L can also be 16 bytes, and when the length of the plaintext received by the terminal is calculated in bytes, if the current value of the counter is N, the value of the counter is incremented by 1 every time the terminal receives 16 bytes. That is, the current value becomes N+1, and N is an integer greater than or equal to 1.
  • the terminal is based on the input order of the i plaintexts, based on the master key and the built-in secret
  • the corresponding counter has a value of 2.
  • the following is the fifth plaintext as an example.
  • the terminal is based on the master key pair counter.
  • the value 2 is encrypted, and the corresponding key stream is M0, M1, ..., Mn, and the terminal intercepts the fifth key M5 in the key stream, and determines the key for the fifth plaintext encryption.
  • the terminal encrypts the counter value 2+1 based on the master key, and obtains the corresponding key stream as M00, M01, ..., M0n, and the terminal intercepts the first key M00 in the key stream, and determines the 17th plaintext.
  • the terminal when the terminal encrypts each plaintext in the i plaintext based on the master key in the input order of the plaintext, the terminal may receive all or part of the plaintext in the i plaintext.
  • the received plaintext is encrypted.
  • the terminal can also encrypt the plaintext when the plaintext is received. The embodiment of the present invention does not limit this.
  • the encryption algorithm AES may be used for encryption.
  • other encryption algorithms may be used, which is not limited in the embodiment of the present invention.
  • Step 203 If an editing operation on the input plaintext is detected, the first ciphertext sequence and the first location information are modified based on the editing operation to obtain a second ciphertext sequence and second location information.
  • the order of the ciphertext in the second ciphertext sequence is consistent with the order of the edited plaintext, and the second The location indication information of each ciphertext in the location information is used to indicate the location of the corresponding ciphertext in the second ciphertext sequence.
  • the plaintext input in the edit operation of the input plaintext refers to the plaintext displayed on the terminal interface, and the plaintext may be the original plaintext input by the user without encryption, or may be displayed after being encrypted and displayed on the interface.
  • the encrypted text is displayed as a black dot, and the black dot may also be the plaintext input here.
  • the content displayed on the interface after encrypting the original plaintext may also be other characters.
  • the editing operation may be any one of deleting, inserting, and replacing, and when the editing operation is different, the modification of the second ciphertext sequence and the second location information is also different, and the specific location indication information of the ciphertext is specific.
  • the location number of the ciphertext in the first ciphertext sequence when the input indication information of the ciphertext is the input sequence number of the plaintext corresponding to the ciphertext, the second ciphertext sequence and the second location are used for different editing operations.
  • the information is modified accordingly as described in (1)-(3).
  • (1) when the editing operation is deleted, modifying the first ciphertext sequence and the first location information according to the editing operation, to obtain the second ciphertext sequence and the second location information, specifically: based on the deleted plaintext location, Deleting the target ciphertext at the same position as the deleted plaintext position in the first ciphertext sequence; moving each ciphertext after the target ciphertext in the first ciphertext sequence one bit forward to obtain a second ciphertext sequence; The position number of each ciphertext after the target ciphertext in the first location information is decremented by one, and the input sequence number corresponding to the target ciphertext in the first location information is deleted, to obtain second location information.
  • the display interfaces of the i plaintexts are specifically displayed as Black dot, if the edit operation is deleted, the deleted plaintext position is the third digit, and the target ciphertext c on the third digit in the first ciphertext sequence abcd is deleted based on the deleted plaintext position, after the target ciphertext c
  • the first ciphertext sequence and the first location information are as shown in the example of (1) above. If the editing operation is an insertion, the inserted plaintext position is the third digit, and the new plaintext obtained based on the inserted plaintext position is new.
  • the first ciphertext sequence and the first location information are as shown in the example of (1) above.
  • the replaced plaintext position is the third digit
  • the replacement plaintext is obtained based on the replaced plaintext position, and the plaintext is replaced.
  • the input sequence number is 5, and the replacement ciphertext obtained by encrypting the replacement plaintext is q, and the target ciphertext in the third digit of the first ciphertext sequence abcd is replaced with the replacement ciphertext q, and the second ciphertext sequence is abqd.
  • the terminal can not only perform the operation by the method of (3) above, but also perform the operation by deleting first, then inserting, that is, deleting according to the method of (1) above, and then deleting.
  • the insertion is carried out according to the method of the above (2) to complete the corresponding replacement.
  • Step 204 Send a second ciphertext sequence and second location information.
  • the terminal may send the corresponding second ciphertext sequence and the second location information to the receiving end, so that the receiving end decrypts the second ciphertext sequence based on the second location information. , get the corresponding plaintext.
  • An encryption method provided by the embodiment of the present invention obtains the first ciphertext sequence and the corresponding ciphertext in the plaintext by encrypting the input i plaintext and encrypting each plaintext in the plaintext based on the master key.
  • the first location information corresponding to the first ciphertext sequence when the editing operation of the input plaintext is detected, the first ciphertext sequence and the first location information are modified based on the editing operation to obtain the second ciphertext sequence and the second location information.
  • Position information, the order of the ciphertext in the second ciphertext sequence is consistent with the sequence of the edited plaintext, and the location indication information of each ciphertext in the second location information is used to indicate that the corresponding ciphertext is in the second ciphertext sequence.
  • the position, the second ciphertext sequence and the second position information are sent, so that the user can perform the editing operation of deleting, inserting and replacing the input information in real time without affecting the entire sequence input previously. Increased encryption speed.
  • FIG. 7 is a schematic flowchart of a decryption method according to an embodiment of the present invention. The method is applied to a receiving end. Referring to FIG. 7, the method includes the following steps.
  • Step 301 Receive a second ciphertext sequence and second location information, where the second ciphertext sequence includes j ciphertexts, and the second location information includes location indication information and input indication information of each ciphertext in the j ciphertexts.
  • the location indication information of a ciphertext is used to indicate the location of the ciphertext in the second ciphertext sequence
  • the input indication information of a ciphertext is used to indicate the input order of the plaintext corresponding to the ciphertext, j ⁇ 1.
  • the location indication information of each ciphertext in the j ciphertexts included in the second location information may specifically be a location sequence number of the ciphertext in the second ciphertext sequence, and the second location information includes each of the ciphertexts included in the second ciphertext.
  • the input indication information of the text may specifically be an input serial number of the plaintext corresponding to the ciphertext.
  • the location indication information and the input indication information may also be other. It is only necessary to ensure that the location indication information of each ciphertext is used to indicate the location of the ciphertext in the second ciphertext sequence, and the input indication information of each ciphertext is used to indicate the input order of the plaintext corresponding to the ciphertext. This embodiment of the present invention does not limit this.
  • Step 302 Decrypt the ciphertext according to the input indication information of the ciphertext in the master key and the second location information for each ciphertext in the second ciphertext sequence to obtain the plaintext corresponding to the ciphertext.
  • the receiving end obtains the first value and the second value according to the input indication information of the ciphertext in the second location information, and then, based on the master key and the first value,
  • the built-in key stream generator generates a corresponding key stream, and obtains a key corresponding to the second value from the key stream, and then performs an exclusive OR operation on the key corresponding to the second value to obtain an exclusive OR operation.
  • first value and the second value are determined according to the input indication information of the ciphertext, and the first value and the second value are integers greater than or equal to 0.
  • the master key in the decryption method is consistent with the master key in the encryption method
  • the key stream generator in the decryption method is similar to the key stream generator in the above encryption method, and the key and the encryption key are obtained.
  • the method for obtaining the key at the time of decryption is similar to that of the present invention, and details are not described herein again.
  • the input indication information of the ciphertext is the secret
  • the input sequence number of the plaintext corresponding to the text obtains the first value and the second value according to the input indication information of the ciphertext in the second location information, specifically: if the input sequence number and the preset length of the plaintext corresponding to the ciphertext can Divisible, the quotient of the division is determined as the first value, and the second value is determined to be zero; if the input number of the plaintext corresponding to the ciphertext cannot be divisible by the preset length, the quotient of the division is determined as the first value The remainder of the division is determined as the second value.
  • the preset length is the preset length L of the monotonically increasing counter built in the key stream generator. For example, when the preset length L is 16, if the current value of the counter is N, the received sequence For every 16 bytes added, the value of the counter is incremented by 1, that is, the current value becomes N+1, and N is an integer greater than or equal to 1.
  • the first value is represented as P
  • the second value is represented as Q
  • the input number of the plaintext corresponding to the ciphertext is represented as S
  • the second ciphertext sequence includes 18 ciphertexts, for the 1st to 16th ciphertexts, the same key stream is used.
  • the fifth ciphertext is taken as an example. If the input number of the fifth ciphertext is 5, the input sequence number 5 cannot be divided by the preset length 16, so that the quotient 0 of 5 divided by 16 is determined as the first value P.
  • the fifth key M5 is intercepted, and the fifth ciphertext is decrypted by the fifth key to obtain the corresponding plaintext.
  • the input number of the 17th ciphertext is 17, and the input number 17 cannot be divided by the preset length 16, so that the quotient 1 of 17 divided by 16 is determined as the first value P, and the remainder 1 is determined as the second value Q, that is, the value of the counter. 2+1, the terminal encrypts 2+1 based on the master key, and the obtained key stream is M00, M01, ..., M0n, and the terminal intercepts the first key M00 from the key stream, and uses the 17th secret.
  • the key decrypts the 17th ciphertext to obtain the corresponding plaintext.
  • Step 303 Determine, according to the location indicated by the location indication information of each ciphertext in the second location information, the location of the plaintext corresponding to each ciphertext.
  • the receiving end may determine the plaintext corresponding to each plaintext in the j plaintexts according to the location indicated by the location indication information of each ciphertext in the second location information. Position to get the plaintext corresponding to the second ciphertext sequence.
  • the second ciphertext sequence includes j ciphertexts
  • the second location information includes the location of each ciphertext in the j ciphertexts by receiving the second ciphertext sequence and the second location information.
  • the ciphertext is decrypted based on the input indication information of the ciphertext in the master key and the second location information, to obtain the ciphertext corresponding
  • the location of the plaintext corresponding to each ciphertext is determined based on the location indicated by the location indication information of each ciphertext in the second location information, that is, the plaintext corresponding to the second ciphertext sequence is obtained, so that the user can Change the position information caused by the deletion, insertion and replacement of the input information, decrypt the corresponding plaintext, and improve the understanding to a certain extent. Secret speed.
  • FIG. 8 is an encryption device according to an embodiment of the present invention. Referring to FIG. 8, the device includes:
  • the receiving unit 401 is configured to receive the input i plaintext, where the value is i ⁇ 1;
  • the encryption unit 402 is configured to encrypt each plaintext in the i plaintext based on the master key according to the input order of the plaintext, to obtain a first ciphertext sequence and a first ciphertext sequence corresponding to the first ciphertext sequence.
  • a location information the first ciphertext sequence includes i ciphertexts corresponding to the i plaintexts, and the first location information includes location indication information and an input indication of each of the i ciphertexts.
  • Information the location indication information of a cipher text is used to indicate the location of the ciphertext in the first ciphertext sequence, and the input indication information of a ciphertext is used to indicate an input order of the plaintext corresponding to the ciphertext;
  • the location indication information of each ciphertext included in the first ciphertext may be a location number of the ciphertext in the first ciphertext sequence, and each of the ciphertexts included in the first location information is dense.
  • the input indication information of the text may be the input number of the plaintext corresponding to the ciphertext.
  • the location indication information and the input indication information may also be other, and only the location indication information of each ciphertext is ensured.
  • the input indication information of each ciphertext is used to indicate the input order of the plaintext corresponding to the ciphertext, which is not limited in the embodiment of the present invention.
  • each plaintext encryption key can be generated according to the master key and the built-in keystream generator. Exchanging each plaintext with the key of the plaintext encryption, that is, obtaining the ciphertext corresponding to each plaintext, corresponding to the encrypted ciphertext according to the position of the i plaintext, that is, the first ciphertext sequence.
  • the editing unit 403 is configured to: if the editing operation of the input plaintext is detected, modify the first ciphertext sequence and the first location information to obtain a second ciphertext sequence and the first The second location information, the sequence of the ciphertext in the second ciphertext sequence is consistent with the sequence of the edited plaintext, and the location indication information of each ciphertext in the second location information is used to indicate that the corresponding ciphertext is in the The position in the second ciphertext sequence;
  • the plaintext input in the editing operation of the input plaintext refers to the plaintext displayed on the device interface, and the plaintext may be the original plaintext input by the user without encryption, or may be displayed on the interface after being encrypted.
  • Content for example, after encryption, the plain text is displayed as a black dot, the black The point can also refer to the plain text entered here.
  • the content displayed on the interface after encrypting the original plaintext can also be other characters.
  • the sending unit 404 is configured to send the second ciphertext sequence and the second location information.
  • the editing operation is any one of deleting, inserting, and replacing.
  • the location indication information is a location sequence number of the ciphertext in the first ciphertext sequence
  • the input indication information is an input sequence number of the plaintext corresponding to the ciphertext.
  • the editing unit when the editing operation is deleted, if an editing operation on the input plaintext is detected, the editing unit is specifically configured to:
  • the editing unit when the editing operation is an insertion, if an editing operation on the input plaintext is detected, the editing unit is specifically configured to:
  • the inserted plaintext position is the third digit
  • the new plaintext entered based on the inserted plaintext position the new plaintext input serial number is 5, and the newly added plaintext is encrypted.
  • the editing unit when the editing operation is replacement, if an editing operation on the input plaintext is detected, the editing unit is specifically configured to:
  • the second location information is obtained.
  • the replaced plaintext position is the third digit
  • the replacement plaintext is obtained based on the replaced plaintext position
  • the input plain number of the replacement plaintext is 5
  • the replacement ciphertext obtained by encrypting the replacement plaintext is q, which will be
  • the target ciphertext on the third bit in the ciphertext sequence abcd is replaced with the ciphertext q
  • the second ciphertext sequence is abqd
  • the location number 3 of the target ciphertext c in the first location information is determined as the replacement ciphertext.
  • An encryption device receives an input plaintext and encrypts each plaintext in the i plaintext based on the master key according to the input order of the plaintext to obtain a first ciphertext sequence and The first location information corresponding to the first ciphertext sequence, when the editing operation of the input plaintext is detected, the first ciphertext sequence and the first location information are modified based on the editing operation to obtain the second ciphertext sequence and the second location information. Position information, the order of the ciphertext in the second ciphertext sequence is consistent with the sequence of the edited plaintext, and the location indication information of each ciphertext in the second location information is used to indicate that the corresponding ciphertext is in the second ciphertext sequence. The position, the second ciphertext sequence and the second position information are sent, so that the user can perform the editing operation of deleting, inserting and replacing the input information in real time without affecting the entire sequence input previously. Increased encryption speed.
  • FIG. 9 is a decryption apparatus according to an embodiment of the present invention.
  • the apparatus includes:
  • the receiving unit 501 is configured to receive a second ciphertext sequence, where the second ciphertext sequence includes j ciphertexts, where the second location information includes a location of each ciphertext in the j ciphertexts.
  • the indication information and the input indication information, the location indication information of a ciphertext is used to indicate the location of the ciphertext in the second ciphertext sequence, and the input indication information of a ciphertext is used to indicate the plaintext corresponding to the ciphertext Input order, the j ⁇ 1;
  • the decrypting unit 502 is configured to, for each ciphertext in the second ciphertext sequence, decrypt the ciphertext based on the input indication information of the ciphertext in the master key and the second location information, Obtaining the plaintext corresponding to the ciphertext;
  • the determining unit 503 is configured to determine a location of the plaintext corresponding to each ciphertext based on the location indicated by the location indication information of each ciphertext in the second location information.
  • the decrypting unit is specifically configured to:
  • first value and the second value are determined according to the input indication information of the ciphertext, and the first value and the second value are integers greater than or equal to 0.
  • the master key in the decryption device is consistent with the master key in the encryption device, and the key stream generator in the decryption device is similar to the key stream generator in the above-described encryption device, and acquires the key and encryption key.
  • the method for obtaining the key at the time of decryption is similar to that of the present invention, and details are not described herein again.
  • the location indication information is a location sequence number of the ciphertext in the second ciphertext sequence
  • the input indication information is an input sequence number of the plaintext corresponding to the ciphertext.
  • the decryption unit when the input indication information is an input sequence number of the plaintext corresponding to the ciphertext, the decryption unit is further configured to:
  • the quotient of the division is determined as the first value, and the second value is determined to be zero;
  • the quotient of the division is determined as the first value, and the remainder of the division is determined as the second value.
  • the first value is represented as P
  • the second value is represented as Q
  • the input number of the plaintext corresponding to the ciphertext is represented as S
  • the first value is obtained according to the input indication information S of the ciphertext in the second location information.
  • the decryption apparatus receives the second ciphertext sequence and the second location information, where the second ciphertext sequence includes j ciphertexts, and the second location information includes the location of each ciphertext in the j ciphertexts.
  • the ciphertext is decrypted based on the input indication information of the ciphertext in the master key and the second location information, to obtain the ciphertext corresponding
  • the location of the plaintext corresponding to each ciphertext is determined based on the location indicated by the location indication information of each ciphertext in the second location information, that is, the plaintext corresponding to the second ciphertext sequence is obtained, so that the user can
  • the change of the position information caused by the modification, insertion and replacement of the input information, the decryption of the corresponding plaintext, and the decryption speed are improved to some extent.
  • An embodiment of the present invention provides a terminal as shown in FIG. 1, which includes a processor 120, a memory 110, an input unit 130, a system bus, and a communication interface.
  • the memory 110 is configured to store computer execution instructions
  • the processor 120 is coupled to the memory 110 via the system bus
  • the input unit is configured to receive input information, when the terminal is running, the processor The computer executes the instructions stored by the memory 110 to cause the terminal to perform the encryption method as described above in FIG.
  • the above-described encryption method as shown in FIG. 2 can be implemented by the processor 120 in hardware form executing computer-executed instructions in the form of software stored in the memory 110. To avoid repetition, we will not repeat them here.
  • the terminal receives the input plaintext and encrypts each plaintext in the i plaintext based on the master key according to the input order of the plaintext to obtain the first ciphertext sequence and the first a first location information corresponding to a ciphertext sequence, when detecting an edit operation on the input plaintext, modifying the first ciphertext sequence and the first location information based on the editing operation to obtain a second ciphertext sequence and a second location Information, the order of the ciphertext in the second ciphertext sequence is consistent with the sequence of the edited plaintext, and the location indication information of each ciphertext in the second location information is used to indicate that the corresponding ciphertext is in the second ciphertext sequence. Position, send the second ciphertext sequence and the second location information, so as to satisfy the user's real-time deletion, insertion and replacement of the input information, without affecting the entire sequence input previously, to a certain extent Improve the speed of terminal encryption.
  • An embodiment of the present invention provides another terminal as shown in FIG. 1, which includes a processor 120, a memory 110, a system bus, and a communication interface.
  • the memory 110 is configured to store computer execution instructions
  • the processor 120 is coupled to the memory 110 via the system bus, and when the terminal is running, the processor 120 executes the computer stored by the memory 110
  • An instruction is executed to cause the terminal to perform the above-described decryption method as shown in FIG.
  • decryption method For a specific decryption method, refer to the related description in the embodiment shown in FIG. 7, and details are not described herein again.
  • the above-described decryption method as shown in FIG. 7 can be implemented by the processor 120 in hardware form executing the computer-executed instructions in the form of software stored in the memory 110. To avoid repetition, we will not repeat them here.
  • a terminal provided by the embodiment of the present invention receives a second ciphertext sequence and a second location letter
  • the second ciphertext sequence includes j ciphertexts
  • the second location information includes location indication information and input indication information of each ciphertext in the j ciphertexts, and is used for each ciphertext in the second ciphertext sequence.
  • the location determines the location of the plaintext corresponding to each ciphertext, that is, obtains the plaintext corresponding to the second ciphertext sequence, so that the corresponding location information may be decrypted according to the user's change of the input information, such as deletion, insertion, and replacement.
  • the speed of terminal decryption is improved to some extent.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Storage Device Security (AREA)
  • Document Processing Apparatus (AREA)

Abstract

本发明实施例提供一种加密、解密方法及装置,涉及通信技术领域,用于满足用户对此前输入的信息进行实时的删除、插入和修改。该方法包括:接收输入的i个明文,i≥1;按照明文的输入顺序,基于主密钥对i个明文中每个明文进行加密,得到第一密文序列和第一位置信息,第一密文序列包括i个明文对应的i个密文,第一位置信息包括i个密文中每个密文的位置指示信息和输入指示信息,位置指示信息用于指示密文在第一密文序列中的位置,输入指示信息用于指示密文对应的明文的输入顺序;若检测到对输入的明文的编辑操作,则基于编辑操作,修改第一密文序列和第一位置信息,得到第二密文序列和第二位置信息;发送第二密文序列和第二位置信息。

Description

加密、解密方法及装置 技术领域
本发明涉及通信技术领域,尤其涉及一种加密、解密方法及装置。
背景技术
当用户使用终端登录第三方应用时,需要通过输入法输入账号和密码等关键信息,若在输入法将输入的信息发送给第三方应用的过程中被木马病毒等监听,将导致输入的账号和密码等信息被恶意程序盗取,因此,需要对输入法进行安全保护,以防止输入信息被窃取。
目前,对输入法进行安全保护时,通常采用常规的加解密算法,对于用户输入的信息,即明文,输入法使用常规加密算法对该信息进行加密后,将密文传递给SDK,SDK进行相应的解密,得到输入的原始信息,供第三方的应用使用,其中,SDK为第三方应用内置的软件开发工具包。当输入法采用流密码算法进行加密时,比如RC4,该算法是对连续明文序列进行按字节或按比特加密,其优点是可以减小密文传递的开销,消除密文的长度扩展,但是,由于该算法是对连续的字节或比特进行加密,若需要插入、修改、删除已经加密的信息,则对此前输入的整条序列进行的加密将会作废,因此,无法满足用户对输入的信息进行实时插入、修改和删除的需求。
发明内容
本发明实施例提供一种加密、解密方法及装置,用于满足用户对输入的信息进行实时插入、修改和删除的需求。
为解决现有技术中的技术问题,本发明的实施例采用如下技术方案:
第一方面,提供一种加密方法,所述方法包括:
接收输入的i个明文,所述i≥1;
按照所述明文的输入顺序,基于主密钥对所述i个明文中的每个明文进行加密,得到第一密文序列以及与所述第一密文序列对应的第一位置信 息,所述第一密文序列包括与所述i个明文对应的i个密文,所述第一位置信息包括所述i个密文中的每个密文的位置指示信息和输入指示信息,一个密文的位置指示信息用于指示所述密文在所述第一密文序列中的位置,一个密文的输入指示信息用于指示所述密文对应的明文的输入顺序;
若检测到对所述输入的明文的编辑操作,则基于所述编辑操作,修改所述第一密文序列和所述第一位置信息,得到第二密文序列和第二位置信息,所述第二密文序列中密文的顺序与编辑后的明文的顺序一致,所述第二位置信息中的每个密文的位置指示信息用于指示对应的密文在所述第二密文序列中的位置;
发送所述第二密文序列以及第二位置信息。
其中,当按照该i个明文的输入顺序,基于主密钥对该i个明文中的每个明文进行加密时,该终端可以根据主密钥和内置的密钥流发生器生成每个明文加密时的密钥,并将每个明文与该明文加密时的密钥进行异或操作,即得到每个明文对应的密文,按照i个明文的位置对应加密得到的i个密文,即为第一密文序列。
需要说明的是,该密钥流发生器内置一单调递增的计数器,且计数器的预设长度可以表示为L,比如,该计数器的预设长度L为128比特,由于8比特等于1字节,因此,计数器的预设长度L也可以为16字节,且当终端接收到的明文的长度按照字节计算时,若计数器当前的数值为N,终端每接收16个字节,计数器的值就加1,即由当前数值变为N+1,N为大于等于1的整数。
具体的,按照该i个明文的输入顺序,基于主密钥和内置的密钥流发生器生成每个明文加密时的密钥的操作可以为:对于i个明文中的每个明文,若该明文为第k个明文,即该明文的输入序号为k,终端接收到该明文时计算器的值变为N+t,则该终端基于主密钥对计数器的值N+t进行加密,得到对应的密钥流,并截取密钥流中的第r个密钥,确定为该明文加密时的密钥,其中,t和r满足L*t+r=k,且t和r为满足L*t+r=k时的最小非负整数。
结合第一方面,在第一方面的第一种可能的实现方式中,所述编辑操作为删除、插入和替换中的任一种。
结合第一方面或者第一方面的第一种可能的实现方式,在第一方面的第二种可能的实现方式中,所述位置指示信息为所述密文在第一密文序列中的位置序号,所述输入指示信息为与所述密文对应的明文的输入序号。
结合第一方面的第二种可能的实现方式,在第一方面的第三种可能的实现方式中,当所述编辑操作为删除时,所述基于所述编辑操作,修改所述第一密文序列和所述第一位置信息,得到第二密文序列和第二位置信息,具体为:
基于删除的明文位置,删除所述第一密文序列中与所述删除的明文位置相同的位置上的目标密文;
将所述第一密文序列中所述目标密文之后的每个密文向前移动一位,得到第二密文序列;
将所述第一位置信息中所述目标密文之后的每个密文的位置序号减一,以及删除所述第一位置信息中所述目标密文对应的输入序号,得到第二位置信息。
结合第一方面的第二种可能的实现方式,在第一方面的第四种可能的实现方式中,当所述编辑操作为插入时,所述基于所述编辑操作,修改所述第一密文序列和所述第一位置信息,得到第二密文序列和第二位置信息,具体为:
基于插入的明文位置,获取新增明文,并对所述新增明文进行加密,得到新增密文;
将所述新增密文添加在所述第一密文序列中所述目标密文的位置,并将所述第一密文序列中的所述目标密文以及所述目标密文之后的每个密文向后移动一位,得到第二密文序列,所述目标密文在所述第一密文序列中的位置与所述插入的明文位置相同;
将所述第一位置信息中所述目标密文的位置序号确定为所述新增密文的位置序号,以及所述新增明文的输入序号确定为所述新增密文对应的明文的输入序号,并将所述目标密文的位置序号以及所述目标密文之后的每个密文的位置序号加一,得到第二位置信息。
结合第一方面的第二种可能的实现方式,在第一方面的第五种可能的实现方式中,当所述编辑操作为替换时,所述基于所述编辑操作,修改所 述第一密文序列和所述第一位置信息,得到第二密文序列和第二位置信息,具体为:
基于替换的明文位置,获取替换明文,并对所述替换明文进行加密,得到替换密文;
将所述第一密文序列中与所述替换的明文位置相同的位置上的目标密文替换为所述替换密文,得到第二密文序列;
将所述第一位置信息中所述目标密文的位置序号确定为所述替换密文的位置序号,以及将所述替换明文的输入序号确定为所述第一位置信息中所述替换密文对应的输入序号,得到所述第二位置信息。
进一步,当该编辑操作为替换时,该终端不仅可以通过上述替换的方法进行操作,还可以通过先删除,后插入的方法进行操作,即先按照上述第一方面的第三种可能的实现方式进行删除,再按照上述第一方面的第四种可能的实现方式进行插入,以完成相应的替换。
第二方面,提供一种解密方法,所述方法包括:
接收第二密文序列和第二位置信息,所述第二密文序列包括j个密文,所述第二位置信息包括所述j个密文中每个密文的位置指示信息和输入指示信息,一个密文的位置指示信息用于指示所述密文在所述第二密文序列中的位置,一个密文的输入指示信息用于指示所述密文对应的明文的输入顺序,所述j≥1;
对于所述第二密文序列中的每个密文,基于主密钥和所述第二位置信息中所述密文的输入指示信息,对所述密文进行解密,得到所述密文对应的明文;
基于所述第二位置信息中每个密文的位置指示信息所指示的位置确定每个密文对应的明文的位置。
结合第二方面,在第二方面的第一种可能的实现方式中,所述基于主密钥和所述第二位置信息中所述密文的输入指示信息,对所述密文进行解密,得到所述密文对应的明文,包括:
根据所述第二位置信息中所述密文的输入指示信息,获取第一数值和第二数值;
基于所述主密钥和所述第一数值生成密钥流,从所述密钥流中获取所 述第二数值对应的密钥;
基于所述第二数值对应的密钥,对所述密文进行解密,得到所述密文对应的明文。
需要说明的是,第一数值和第二数值是根据该密文的输入指示信息确定的,且第一数值和第二数值为大于等于0的整数。
另外,解密方法中的主密钥与加密方法中的主密钥保持一致,且解密方法中的密钥流发生器与上述加密方法中的密钥流发生器类似,本发明实施例在此不再赘述。
结合第二方面或者第二方面的第一种可能的实现方式,在第二方面的第二种可能的实现方式中,所述位置指示信息为所述密文在第二密文序列中的位置序号,所述输入指示信息为与所述密文对应的明文的输入序号。
结合第二方面的第二种可能的实现方式,在第二方面的第三种可能的实现方式中,当所述输入指示信息为所述密文对应的明文的输入序号时,所述根据所述第二位置信息中所述密文的输入指示信息,获取第一数值和第二数值,具体为:
若所述密文对应的明文的输入序号与预设长度能够整除,则将相除的商确定为第一数值,将第二数值确定为零;
若所述密文对应的明文的输入序号与所述预设长度不能整除,则将相除的商确定为第一数值,将相除的余数确定为第二数值。
进一步的,若第一数值表示为P,第二数值表示为Q,密文对应的明文的输入序号表示为S,则根据第二位置信息中该密文的输入指示信息S,获取第一数值P和第二数值Q时,还可以根据第一数值P,第二数值Q,该密文对应明文的输入序号S和预设长度L满足的关系式L*P+Q=S进行确定,其中,P和Q为满足关系式L*P+Q=S的最小非负整数。
第三方面,提供一种加密装置,所述装置包括:
接收单元,用于接收输入的i个明文,所述i≥1;
加密单元,用于按照所述明文的输入顺序,基于主密钥对所述i个明文中的每个明文进行加密,得到第一密文序列以及与所述第一密文序列对应的第一位置信息,所述第一密文序列包括与所述i个明文对应的i个密文,所述第一位置信息包括所述i个密文中的每个密文的位置指示信息和 输入指示信息,一个密文的位置指示信息用于指示所述密文在所述第一密文序列中的位置,一个密文的输入指示信息用于指示所述密文对应的明文的输入顺序;
编辑单元,用于若检测到对所述输入的明文的编辑操作,则基于所述编辑操作,修改所述第一密文序列和所述第一位置信息,得到第二密文序列和第二位置信息,所述第二密文序列中密文的顺序与编辑后的明文的顺序一致,所述第二位置信息中的每个密文的位置指示信息用于指示对应的密文在所述第二密文序列中的位置;
发送单元,用于发送所述第二密文序列以及第二位置信息。
结合第三方面,在第三方面的第一种可能的实现方式中,所述编辑操作为删除、插入和替换中的任一种。
结合第三方面或者第三方面的第一种可能的实现方式,在第三方面的第二种可能的实现方式中,所述位置指示信息为所述密文在第一密文序列中的位置序号,所述输入指示信息为与所述密文对应的明文的输入序号。
结合第三方面的第二种可能的实现方式,在第三方面的第三种可能的实现方式中,当所述编辑操作为删除时,若检测到对所述输入的明文的编辑操作,所述编辑单元具体用于:
基于删除的明文位置,删除所述第一密文序列中与所述删除的明文位置相同的位置上的目标密文;
将所述第一密文序列中所述目标密文之后的每个密文向前移动一位,得到第二密文序列;
将所述第一位置信息中所述目标密文之后的每个密文的位置序号减一,以及删除所述第一位置信息中所述目标密文对应的输入序号,得到第二位置信息。
结合第三方面的第二种可能的实现方式,在第三方面的第四种可能的实现方式中,当所述编辑操作为插入时,若检测到对所述输入的明文的编辑操作,所述编辑单元具体用于:
基于插入的明文位置,获取新增明文,并对所述新增明文进行加密,得到新增密文;
将所述新增密文添加在所述第一密文序列中所述目标密文的位置,并 将所述第一密文序列中的所述目标密文以及所述目标密文之后的每个密文向后移动一位,得到第二密文序列,所述目标密文在所述第一密文序列中的位置与所述插入的明文位置相同;
将所述第一位置信息中所述目标密文的位置序号确定为所述新增密文的位置序号,以及所述新增明文的输入序号确定为所述新增密文对应的明文的输入序号,并将所述目标密文的位置序号以及所述目标密文之后的每个密文的位置序号加一,得到第二位置信息。
结合第三方面的第二种可能的实现方式,在第三方面的第五种可能的实现方式中,当所述编辑操作为替换时,若检测到对所述输入的明文的编辑操作,所述编辑单元具体用于:
基于替换的明文位置,获取替换明文,并对所述替换明文进行加密,得到替换密文;
将所述第一密文序列中与所述替换的明文位置相同的位置上的目标密文替换为所述替换密文,得到第二密文序列;
将所述第一位置信息中所述目标密文的位置序号确定为所述替换密文的位置序号,以及将所述替换明文的输入序号确定为所述第一位置信息中所述替换密文对应的输入序号,得到所述第二位置信息。
第四方面,提供一种解密装置,所述装置包括:
接收单元,用于接收第二密文序列和第二位置信息,所述第二密文序列包括j个密文,所述第二位置信息包括所述j个密文中每个密文的位置指示信息和输入指示信息,一个密文的位置指示信息用于指示所述密文在所述第二密文序列中的位置,一个密文的输入指示信息用于指示所述密文对应的明文的输入顺序,所述j≥1;
解密单元,用于对于所述第二密文序列中的每个密文,基于主密钥和所述第二位置信息中所述密文的输入指示信息,对所述密文进行解密,得到所述密文对应的明文;
确定单元,用于基于所述第二位置信息中每个密文的位置指示信息所指示的位置确定每个密文对应的明文的位置。
结合第四方面,在第四方面的第一种可能的实现方式中,对于所述第二密文序列中的每个密文,所述解密单元具体用于:
根据所述第二位置信息中所述密文的输入指示信息,获取第一数值和第二数值;
基于所述主密钥和所述第一数值生成密钥流,从所述密钥流中获取所述第二数值对应的密钥;
基于所述第二数值对应的密钥,对所述密文进行解密,得到所述密文对应的明文。
结合第四方面或者第四方面的第一种可能的实现方式,在第四方面的第二种可能的实现方式中,所述位置指示信息为所述密文在第二密文序列中的位置序号,所述输入指示信息为与所述密文对应的明文的输入序号。
结合第四方面的第二种可能的实现方式,在第四方面的第三种可能的实现方式中,当所述输入指示信息为所述密文对应的明文的输入序号时,所述解密单元还具体用于:
若所述密文对应的明文的输入序号与预设长度能够整除,则将相除的商确定为第一数值,将第二数值确定为零;
若所述密文对应的明文的输入序号与所述预设长度不能整除,则将相除的商确定为第一数值,将相除的余数确定为第二数值。
第五方面,提供一种终端,所述终端包括:处理器、存储器、输入单元、系统总线和通信接口;
所述存储器用于存储计算机执行指令,所述处理器与所述存储器通过所述系统总线连接,所述输入单元用于接收输入的信息,当所述终端运行时,所述处理器执行所述存储器存储的所述计算机执行指令,以使所述终端执行第一方面至第一方面的第五种可能的实现方式中的任一项所述的加密方法。
第六方面,提供一种终端,所述终端包括:处理器、存储器、系统总线和通信接口;
所述存储器用于存储计算机执行指令,所述处理器与所述存储器通过所述系统总线连接,当所述终端运行时,所述处理器执行所述存储器存储的所述计算机执行指令,以使所述终端执行第二方面至第二方面的第三种可能的实现方式中的任一项所述的解密方法。
本发明的实施例提供的一种加密、解密方法及装置,通过接收输入的 i个明文,并按照明文的输入顺序,基于主密钥对i个明文中的每个明文进行加密,得到第一密文序列以及与第一密文序列对应的第一位置信息,在检测到对输入的明文的编辑操作时,基于该编辑操作,修改第一密文序列和第一位置信息,得到第二密文序列和第二位置信息,第二密文序列中密文的顺序与编辑后的明文的顺序一致,第二位置信息中的每个密文的位置指示信息用于指示对应的密文在第二密文序列中的位置,之后,将第二密文序列以及第二位置信息发送给接收端,以使接收端基于记录的第二位置信息,对第二密文序列进行解密,得到相应的明文,从而在不影响对此前输入的整条序列进行的加密的基础上,满足用户对输入的信息进行实时的删除、插入和替换等编辑操作,在一定程度上提高了加密、解密的速度。
附图说明
为了更清楚地说明本发明实施例的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1为本发明实施例提供的一种终端的结构示意图;
图2为本发明实施例提供的一种加密方法的流程示意图;
图3为本发明实施例提供的一种终端的显示界面示意图;
图4为本发明实施例提供的另一种终端的显示界面示意图;
图5为本发明实施例提供的又一种终端的显示界面示意图;
图6为本发明实施例提供的另一种终端的显示界面示意图;
图7为本发明实施例提供的一种解密方法的流程示意图;
图8为本发明实施例提供的一种加密装置的结构示意图;
图9为本发明实施例提供的一种解密装置的结构示意图。
具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的 范围。
在介绍本发明之前,首先对本发明的应用场景进行介绍,随着通信技术的快速发展,出现了诸如手机、平板电脑、计算机等越来越多的终端,用户可以通过这些终端访问各种各样的应用,比如,微博、聊天软件、阅读器和游戏等。当用户访问这些应用时,用户需要通过终端的输入法输入应用账号和密码,为了保证输入账号和密码的安全,输入法侧会对输入的信息进行加密,并将加密后的信息发送给第三方应用,第三方应用中的SDK(英文:Software Development Kit,中文软件开发工具包)对加密后的信息进行相应的解密,从而得到输入账号和密码供第三方应用使用。
但是,现有技术中对输入的信息常采用流密码算法进行加密,比如RC4算法,但这种算法是将连续的明文序列按照字节或比特进行加密,而在通信技术领域中,数据通信和网络协议中消息传输为连续的输出,因此,若发送方需要修改已经加密的消息,比如,若用户对之前输入的应用账号和密码进行了删除、插入或修改,则此前输入的整条序列进行的加密将会作废。
本发明的基本原理在于,在对用户输入的应用账号和密码等输入信息进行加密时,记录每个输入字符的位置信息,并在用户对输入信息进行删除、插入或修改等编辑操作时,基于相应的编辑操作,对之前记录的位置信息进行相应的修改,并将加密后的输入信息和位置信息发送给接收端,以使接收端基于记录的位置信息,对加密的输入信息进行解密,得到相应的应用账号和密码等输入信息。
图1为本发明实施例所应用的一种终端的结构示意图,该终端可以为手机、平板电脑、笔记本电脑、UMPC(Ultra-mobile Personal Computer,超级移动个人计算机)、上网本、PDA(Personal Digital Assistant,个人数字助理)等终端设备,本发明实施例以终端为手机为例进行说明,图1示出的是与本发明各实施例相关的手机的部分结构的框图。
如图1所示,手机100包括:存储器110、处理器120、输入单元130、显示单元140、RF(radio frequency,射频)电路150、音频电路160、电源170,以及未图示的系统总线和通信接口等。本领域技术人员可以理解,图1中示出的手机结构并不构成对手机的限定,可以包括比图示更多或更 少的部件,或者组合某些部件,或者不同的部件布置。
下面结合图1对手机100的各个构成部件进行具体的介绍:
存储器110可用于存储软件程序以及模块,处理器120通过运行存储在存储器110的软件程序以及模块,从而执行手机100的各种功能应用以及数据处理。存储器110可主要包括存储程序区和存储数据区,其中,存储程序区可存储操作系统、至少一个功能所需的应用程序(比如声音播放功能、图像播放功能等)等;存储数据区可存储根据手机100的使用所创建的数据(比如音频数据、图像数据、电话本等)等。此外,存储器110可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件、闪存器件、或其他易失性固态存储器件。
处理器120是手机100的控制中心,利用各种接口和线路连接整个手机的各个部分,通过运行或执行存储在存储器110内的软件程序和/或模块,以及调用存储在存储器110内的数据,执行手机100的各种功能和处理数据,从而对手机进行整体监控。可选的,处理器120可包括一个或多个处理单元;优选的,处理器120可集成应用处理器和调制解调处理器,其中,应用处理器主要处理操作系统、用户界面和应用程序等,调制解调处理器主要处理无线通信。可以理解的是,上述调制解调处理器也可以不集成到处理器120中。
输入单元130可用于接收输入的数字或字符信息,以及产生与手机100的用户设置以及功能控制有关的键信号输入。具体地,输入单元130可包括触摸屏131以及其他输入设备132。触摸屏131,也称为触控面板,可收集用户在其上或附近的触摸操作(比如用户使用手指、触笔等任何适合的物体或附件在触摸屏131上或在触摸屏131附近的操作),并根据预先设定的程式驱动相应的连接装置。可选的,触摸屏131可包括触摸检测装置和触摸控制器两个部分。其中,触摸检测装置检测用户的触摸方位,并检测触摸操作带来的信号,将信号传送给触摸控制器;触摸控制器从触摸检测装置上接收触摸信息,并将它转换成触点坐标,再送给处理器120,并能接收处理器120发来的命令并加以执行。此外,可以采用电阻式、电容式、红外线以及表面声波等多种类型实现触摸屏131。除了触摸屏131,输入单元130还可以包括其他输入设备132。具体地,其他输入设备132可以包 括但不限于物理键盘、功能键(比如音量控制按键、电源开关按键等)、轨迹球、鼠标、操作杆等中的一种或多种。
显示单元140可用于显示由用户输入的信息或提供给用户的信息以及手机100的各种菜单。显示单元140可包括显示面板141,可选的,可以采用LCD(Liquid Crystal Display,液晶显示器)、OLED(Organic Light-Emitting Diode,有机发光二极管)等形式来配置显示面板141。进一步的,触摸屏131可覆盖显示面板141,当触摸屏131检测到在其上或附近的触摸操作后,传送给处理器120以确定触摸事件的类型,随后处理器120根据触摸事件的类型在显示面板141上提供相应的视觉输出。虽然在图1中,触摸屏131与显示面板141是作为两个独立的部件来实现手机400的输入和输入功能,但是在某些实施例中,可以将触摸屏131与显示面板141集成而实现手机100的输入和输出功能。
RF电路150可用于收发信息或通话过程中,信号的接收和发送。通常,RF电路包括但不限于天线、至少一个放大器、收发信机、耦合器、LNA(low noise amplifier,低噪声放大器)、双工器等。此外,RF电路150还可以通过无线通信与网络和其他设备通信。所述无线通信可以使用任一通信标准或协议,包括但不限于GSM(global system of mobile communication,全球移动通讯系统)、GPRS(general packet radio service,通用分组无线服务)、CDMA(code division multiple access,码分多址)、WCDMA(wideband code division multiple access,宽带码分多址)、LTE(long term evolution,长期演进)、电子邮件、SMS(short messaging service,短消息服务)等。
音频电路160、扬声器161、麦克风162可提供用户与手机100之间的音频接口。音频电路160可将接收到的音频数据转换后的电信号,传输到扬声器161,由扬声器161转换为声音信号输出;另一方面,麦克风162将收集的声音信号转换为电信号,由音频电路160接收后转换为音频数据,再将音频数据输出至RF电路150以发送给比如另一手机,或者将音频数据输出至存储器110以便进一步处理。
手机100还包括给各个部件供电的电源170(比如电池),优选的,电源可以通过电源管理系统与处理器120逻辑相连,从而通过电源管理系统实现管理充电、放电、以及功耗管理等功能。
尽管未示出,手机100还可以包括传感器模块、音频模块、WiFi(wireless fidelity,无线保真)模块、蓝牙模块等,在此不再赘述。
图2为本发明实施例提供的一种加密方法的流程示意图,应用于终端,参见图2,该方法包括以下几个步骤。
步骤201:接收输入的i个明文,所述i≥1。
步骤202:按照该明文的输入顺序,基于主密钥对i个明文中的每个明文进行加密,得到第一密文序列以及与第一密文序列对应的第一位置信息;其中,第一密文序列包括与i个明文对应的i个密文,第一位置信息包括i个密文中的每个密文的位置指示信息和输入指示信息,一个密文的位置指示信息用于指示该密文在第一密文序列中的位置,一个密文的输入指示信息用于指示该密文对应的明文的输入顺序。
其中,第一位置信息包括的i个密文中每个密文的位置指示信息具体可以为该密文在第一密文序列中的位置序号,第一位置信息包括的i个密文中每个密文的输入指示信息具体可以为与该密文对应的明文的输入序号,当然,在实际应用中,该位置指示信息和输入指示信息也可以为其他,只需确保每个密文的位置指示信息用于指示该密文在第一密文序列中的位置,每个密文的输入指示信息用于指示该密文对应的明文的输入顺序即可,本发明实施例对此不作限定。
当该终端按照该i个明文的输入顺序,基于主密钥对该i个明文中的每个明文进行加密时,该终端可以根据主密钥和内置的密钥流发生器生成每个明文加密时的密钥,并将每个明文与该明文加密时的密钥进行异或操作,即得到每个明文对应的密文,按照i个明文的位置对应加密得到的i个密文,即为第一密文序列。
其中,该密钥流发生器内置一单调递增的计数器,且计数器的预设长度可以表示为L,比如,该计数器的预设长度L为128比特,由于8比特等于1字节,因此,计数器的预设长度L也可以为16字节,且当终端接收到的明文的长度按照字节计算时,若计数器当前的数值为N,终端每接收16个字节,计数器的值就加1,即由当前数值变为N+1,N为大于等于1的整数。
具体的,该终端按照该i个明文的输入顺序,基于主密钥和内置的密 钥流发生器生成每个明文加密时的密钥的操作可以为:对于i个明文中的每个明文,若该明文为第k个明文,即该明文的输入序号为k,终端接收到该明文时计算器的值变为N+t,则该终端基于主密钥对计数器的值N+t进行加密,得到对应的密钥流,并截取密钥流中的第r个密钥,确定为该明文加密时的密钥,其中,t和r满足L*t+r=k,且t和r为满足L*t+r=k时的最小非负整数。
比如,当前计数器的值为2,t=0,计数器长度L=16,用户输入i=18个明文,对于第1-16个明文进行加密时,对应计数器的值为2的密钥流。下面以第5个明文为例进行介绍,终端接收到第5个明文时,由于计数器尚未接收到满一个计数器长度L=16的明文,计数器的值仍然为2,该终端基于主密钥对计数器的值2进行加密,得到对应的密钥流为M0、M1、…、Mn,终端截取密钥流中的第5个密钥M5,确定为第5个明文加密时的密钥,此时,L=16、t=0、r=5、k=5满足公式L*t+r=k。
当输入第17个明文时,由于计数器接收到满一个计数器长度L=16的明文,则计数器的值加t=1,即计数器的值为2+1。该终端基于主密钥对计数器值2+1进行加密,得到对应的密钥流为M00、M01、…、M0n,终端截取密钥流中的第1个密钥M00,确定为第17个明文加密时的密钥,此时,L=16、t=1和r=1、k=17满足L*t+r=k。
可见,由于考虑了明文输入的顺序使得密文序列在解密时需要利用该输入的顺序产生相应解密的密钥。
需要说明的是,当该终端按照i个明文的输入顺序,基于主密钥对该i个明文中的每个明文进行加密时,该终端可以在接收到该i个明文中的全部或部分明文时,就接收到的明文进行加密,当然,该终端也可以在接收到每一个明文时,就对该明文进行加密,本发明实施例对此不作限定。
另外,终端基于主密钥对计数器的值N+t进行加密时,可以采用加密算法AES进行加密,当然,在实际应用中,也可以采用其他的加密算法,本发明实施例对此不作限定。
步骤203:若检测到对输入的明文的编辑操作,则基于该编辑操作,修改第一密文序列和第一位置信息,得到第二密文序列和第二位置信息。
其中,第二密文序列中密文的顺序与编辑后的明文的顺序一致,第二 位置信息中的每个密文的位置指示信息用于指示对应的密文在第二密文序列中的位置。
需要说明的是,对输入的明文的编辑操作中的输入的明文,是指显示在终端界面上的明文,该明文可以是用户输入的未进行加密的原始明文,也可以是加密后显示在界面的内容,比如,加密后明文显示为黑点,该黑点也可以是指此处输入的明文,当然,对原始明文进行加密后显示在界面上的内容也可以为其他字符。
其中,该编辑操作可以删除、插入和替换中的任一种,且当该编辑操作不同时,对第二密文序列和第二位置信息的修改也不同,具体的当密文的位置指示信息为该密文在第一密文序列中的位置序号,密文的输入指示信息为与该密文对应的明文的输入序号时,针对不同的编辑操作,对第二密文序列和第二位置信息进行相应的修改如下(1)-(3)所述。
(1)、当该编辑操作为删除时,基于该编辑操作,修改第一密文序列和第一位置信息,得到第二密文序列和第二位置信息,具体为:基于删除的明文位置,删除第一密文序列中与删除的明文位置相同的位置上的目标密文;将第一密文序列中目标密文之后的每个密文向前移动一位,得到第二密文序列;将第一位置信息中目标密文之后的每个密文的位置序号减一,以及删除所述第一位置信息中所述目标密文对应的输入序号,得到第二位置信息。
比如,第一密文序列为abcd,若第一位置信息以Pn=M进行表示,n表示密文在第一密文序列中的位置序号,M表示该密文对应的明文的输入序号,则第一密文序列abcd对应的第一位置信息可以为P1=1,P2=2,P3=3,P4=4,如图3所示,i个明文的显示界面具体显示为黑点,若编辑操作为删除时,删除的明文位置为第三位,则基于删除的明文位置删除第一密文序列abcd中第三位上的目标密文c,将目标密文c之后的密文d向前移动一位,得到第二密文序列为abd;将第一位置信息中目标密文之后的密文d的位置序号减一,即P3=4,相应的第二位置信息为P1=1,P2=2,P3=4,删除后相应的明文的显示界面如图4所示。
(2)、当该编辑操作为插入时,基于该编辑操作,修改第一密文序列和第一位置信息,得到第二密文序列和第二位置信息,具体为:基于插入 的明文位置,获取新增明文,并对新增明文进行加密,得到新增密文;将新增密文添加在第一密文序列中目标密文的位置,并将第一密文序列中的目标密文以及目标密文之后的每个密文向后移动一位,得到第二密文序列,目标密文在第一密文序列中的位置与插入的明文位置相同;将第一位置信息中目标密文的位置序号确定为新增密文的位置序号,以及新增明文的输入序号确定为新增密文对应的明文的输入序号,并将目标密文的位置序号以及目标密文之后的每个密文的位置序号加一,得到第二位置信息。
比如,第一密文序列和第一位置信息如上述(1)的例子所示,若编辑操作为插入时,插入的明文位置为第三位,基于插入的明文位置获取的新增明文,新增明文的输入序号为5,对新增明文加密后得到的新增密文为h,将新增密文h插入在第一密文序列abcd中的第三位上,即目标密文c的位置上,并将第一密文序列中的目标密文c和密文d向后移动一位,得到第二密文序列为abhcd;将第一位置信息中目标密文c的位置序号3确定为新增密文h的位置序号,将新增明文的输入序号5确定为新增密文h对应的明文的输入序号,即P3=5,并将目标密文c的位置序号以及密文d的位置序号加一,得到第二位置信息为P1=1,P2=2,P3=5,P4=3,P5=4,插入后相应的明文的显示界面如图5所示。
(3)、当该编辑操作为替换时,基于该编辑操作,修改第一密文序列和第一位置信息,得到第二密文序列和第二位置信息,具体为:基于替换的明文位置,获取替换明文,并对替换明文进行加密,得到替换密文;将第一密文序列中与替换的明文位置相同的位置上的目标密文替换为替换密文,得到第二密文序列;将第一位置信息中目标密文的位置序号确定为替换密文的位置序号,以及将所述替换明文的输入序号确定为所述第一位置信息中所述替换密文对应的输入序号,得到所述第二位置信息。
比如,第一密文序列和第一位置信息如上述(1)的例子所示,若编辑操作为替换时,替换的明文位置为第三位,基于替换的明文位置获取替换明文,替换明文的输入序号为5,对替换明文加密后得到的替换密文为q,将第一密文序列abcd中的第三位上的目标密文替换为替换密文q,得到第二密文序列为abqd,将第一位置信息中目标密文c的位置序号3确定为替换密文q的位置序号,即P3=5,相应的第二位置信息为P1=1,P2=2,P3=5, P4=4,替换后相应的明文的显示界面如图6所示。
进一步,当该编辑操作为替换时,该终端不仅可以通过上述(3)的方法进行操作,还可以通过先删除,后插入的方法进行操作,即先按照上述(1)的方法进行删除,再按照上述(2)的方法进行插入,以完成相应的替换,具体步骤参见上述(1)和(2),本发明实施例在此不再赘述。
步骤204:发送第二密文序列以及第二位置信息。
当用户对输入的明文进行修改确认后,该终端可以将相应的第二密文序列和第二位置信息发送给接收端,以使接收端基于第二位置信息,对第二密文序列进行解密,得到相应的明文。
本发明实施例提供的一种加密方法,通过接收输入的i个明文,并按照明文的输入顺序,基于主密钥对i个明文中的每个明文进行加密,得到第一密文序列以及与第一密文序列对应的第一位置信息,在检测到对输入的明文的编辑操作时,基于该编辑操作,修改第一密文序列和第一位置信息,得到第二密文序列和第二位置信息,第二密文序列中密文的顺序与编辑后的明文的顺序一致,第二位置信息中的每个密文的位置指示信息用于指示对应的密文在第二密文序列中的位置,发送第二密文序列以及第二位置信息,从而在不影响此前输入的整条序列的基础上,满足用户对输入的信息进行实时的删除、插入和替换等编辑操作,在一定程度上提高了加密速度。
图7为本发明实施例提供的一种解密方法的流程示意图,应用于接收端,参见图7,该方法包括以下几个步骤。
步骤301:接收第二密文序列和第二位置信息;其中,第二密文序列包括j个密文,第二位置信息包括j个密文中每个密文的位置指示信息和输入指示信息,一个密文的位置指示信息用于指示该密文在第二密文序列中的位置,一个密文的输入指示信息用于指示该密文对应的明文的输入顺序,j≥1。
其中,第二位置信息包括的j个密文中每个密文的位置指示信息具体可以为该密文在第二密文序列中的位置序号,第二位置信息包括的i个密文中每个密文的输入指示信息具体可以为与该密文对应的明文的输入序号,当然,在实际应用中,该位置指示信息和输入指示信息也可以为其他, 只需确保每个密文的位置指示信息用于指示该密文在第二密文序列中的位置,每个密文的输入指示信息用于指示该密文对应的明文的输入顺序即可,本发明实施例对此不作限定。
步骤302:对于第二密文序列中的每个密文,基于主密钥和第二位置信息中该密文的输入指示信息,对该密文进行解密,得到该密文对应的明文。
对于第二密文序列中的每个密文,接收端根据第二位置信息中该密文的输入指示信息,获取第一数值和第二数值,之后,基于主密钥和第一数值,通过内置的密钥流发生器生成对应的密钥流,并从该密钥流中获取第二数值对应的密钥,再将第二数值对应的密钥与该密文进行异或操作,即得到该密文对应的明文。
需要说明的是,第一数值和第二数值是根据该密文的输入指示信息确定的,且第一数值和第二数值为大于等于0的整数。
另外,解密方法中的主密钥与加密方法中的主密钥保持一致,且解密方法中的密钥流发生器与上述加密方法中的密钥流发生器类似,获取加密时的密钥与获取解密时的密钥的方法与也类似,本发明实施例在此不再赘述。
具体的,对于第二密文序列中的每个密文,若该密文的位置指示信息为该密文在第二密文序列中的位置序号,该密文的输入指示信息为与该密文对应的明文的输入序号,则根据第二位置信息中该密文的输入指示信息,获取第一数值和第二数值,具体为:若该密文对应的明文的输入序号与预设长度能够整除,则将相除的商确定为第一数值,将第二数值确定为零;若该密文对应的明文的输入序号与预设长度不能整除,则将相除的商确定为第一数值,将相除的余数确定为第二数值。
需要说明的是,预设长度为密钥流发生器中内置的单调递增的计数器的预设长度L,比如,当该预设长度L为16时,若计数器当前的数值为N,接收的序列每增加16个字节,计数器的值就加1,即有当前数值变为N+1,N为大于等于1的整数。
进一步的,若第一数值表示为P,第二数值表示为Q,密文对应的明文的输入序号表示为S,则根据第二位置信息中该密文的输入指示信息S, 获取第一数值P和第二数值Q时,还可以根据第一数值P,第二数值Q,该密文的输入序号S和预设长度L满足的关系式L*P+Q=S进行确定,其中,P和Q为满足关系式L*P+Q=S的最小非负整数。
比如,计数器长度L=16,第二密文序列包括18个密文时,对于第1-16个密文,对应同一个密钥流。下面以第5个密文为例进行介绍,若第5个密文的输入序号为5,输入序号5不能整除预设长度16,从而将5除以16的商0确定为第一数值P,余数5确定为第二数值Q,即计数器的数值例如N=2,终端基于主密钥对N=2进行加密,得到的密钥流为M0、M1、…、Mn,终端从密钥流中截取第5个密钥M5,利用第5个密钥对第5个密文进行解密,得到相应的明文,此时,L=16,P=0、Q=5、S=5,满足公式L*P+Q=S。
第17个密文的输入序号为17,输入序号17不能整除预设长度16,从而将17除以16的商1确定为第一数值P,余数1确定为第二数值Q,即计数器的数值为2+1,终端基于主密钥对2+1进行加密,得到的密钥流为M00、M01、…、M0n,终端从密钥流中截取第1个密钥M00,利用第17个密钥对第17个密文进行解密,得到相应的明文,此时,L=16,P=1、Q=1、S=17,满足公式L*P+Q=S。
步骤303:基于第二位置信息中每个密文的位置指示信息所指示的位置确定每个密文对应的明文的位置。
当得到第二密文序列中每个密文对应的明文后,接收端可以根据第二位置信息中每个密文的位置指示信息所指示的位置,确定j个明文中每个明文对应的明文位置,以得到第二密文序列对应的明文。
本发明实施例提供的一种解密方法,通过接收第二密文序列和第二位置信息,第二密文序列包括j个密文,第二位置信息包括j个密文中每个密文的位置指示信息和输入指示信息,对于第二密文序列中的每个密文,基于主密钥和第二位置信息中该密文的输入指示信息,对该密文进行解密,得到该密文对应的明文,之后,基于第二位置信息中每个密文的位置指示信息所指示的位置确定每个密文对应的明文的位置,即得到第二密文序列对应的明文,从而可以根据用户对输入的信息的删除、插入和替换等修改造成的位置信息的变化,解密出相应的明文,在一定程度上提高了解 密速度。
图8为本发明实施例提供的一种加密装置,参见图8,该装置包括:
接收单元401,用于接收输入的i个明文,所述i≥1;
加密单元402,用于按照所述明文的输入顺序,基于主密钥对所述i个明文中的每个明文进行加密,得到第一密文序列以及与所述第一密文序列对应的第一位置信息,所述第一密文序列包括与所述i个明文对应的i个密文,所述第一位置信息包括所述i个密文中的每个密文的位置指示信息和输入指示信息,一个密文的位置指示信息用于指示所述密文在所述第一密文序列中的位置,一个密文的输入指示信息用于指示所述密文对应的明文的输入顺序;
其中,第一位置信息包括的i个密文中每个密文的位置指示信息具体可以为该密文在第一密文序列中的位置序号,第一位置信息包括的i个密文中每个密文的输入指示信息具体可以为与该密文对应的明文的输入序号,当然,在实际应用中,该位置指示信息和输入指示信息也可以为其他,只需确保每个密文的位置指示信息用于指示该密文在第一密文序列中的位置,每个密文的输入指示信息用于指示该密文对应的明文的输入顺序即可,本发明实施例对此不作限定。
当按照该i个明文的输入顺序,基于主密钥对该i个明文中的每个明文进行加密时,可以根据主密钥和内置的密钥流发生器生成每个明文加密时的密钥,并将每个明文与该明文加密时的密钥进行异或操作,即得到每个明文对应的密文,按照i个明文的位置对应加密得到的i个密文,即为第一密文序列。
编辑单元403,用于若检测到对所述输入的明文的编辑操作,则基于所述编辑操作,修改所述第一密文序列和所述第一位置信息,得到第二密文序列和第二位置信息,所述第二密文序列中密文的顺序与编辑后的明文的顺序一致,所述第二位置信息中的每个密文的位置指示信息用于指示对应的密文在所述第二密文序列中的位置;
需要说明的是,对输入的明文的编辑操作中的输入的明文,是指显示在装置界面上的明文,该明文可以是用户输入的未进行加密的原始明文,也可以是加密后显示在界面的内容,比如,加密后明文显示为黑点,该黑 点也可以是指此处输入的明文,当然,对原始明文进行加密后显示在界面上的内容也可以为其他字符。
发送单元404,用于发送所述第二密文序列以及第二位置信息。
可选的,所述编辑操作为删除、插入和替换中的任一种。
可选的,所述位置指示信息为所述密文在第一密文序列中的位置序号,所述输入指示信息为与所述密文对应的明文的输入序号。
在本发明的另一实施例中,当所述编辑操作为删除时,若检测到对所述输入的明文的编辑操作,所述编辑单元具体用于:
基于删除的明文位置,删除所述第一密文序列中与所述删除的明文位置相同的位置上的目标密文;
将所述第一密文序列中所述目标密文之后的每个密文向前移动一位,得到第二密文序列;
将所述第一位置信息中所述目标密文之后的每个密文的位置序号减一,以及删除所述第一位置信息中所述目标密文对应的输入序号,得到第二位置信息。
比如,第一密文序列为abcd,若第一位置信息以Pn=M进行表示,n表示密文在第一密文序列中的位置序号,M表示该密文对应的明文的输入序号,则第一密文序列abcd对应的第一位置信息可以为P1=1,P2=2,P3=3,P4=4,若编辑操作为删除时,删除的明文位置为第三位,则基于删除的明文位置删除第一密文序列abcd中第三位上的目标密文c,将目标密文c之后的密文d向前移动一位,得到第二密文序列为abd;将第一位置信息中目标密文之后的密文d的位置序号减一,即P3=4,相应的第二位置信息为P1=1,P2=2,P3=4。
在本发明的另一实施例中,当所述编辑操作为插入时,若检测到对所述输入的明文的编辑操作,所述编辑单元具体用于:
基于插入的明文位置,获取新增明文,并对所述新增明文进行加密,得到新增密文;
将所述新增密文添加在所述第一密文序列中所述目标密文的位置,并将所述第一密文序列中的所述目标密文以及所述目标密文之后的每个密文向后移动一位,得到第二密文序列,所述目标密文在所述第一密文序列 中的位置与所述插入的明文位置相同;
将所述第一位置信息中所述目标密文的位置序号确定为所述新增密文的位置序号,以及所述新增明文的输入序号确定为所述新增密文对应的明文的输入序号,并将所述目标密文的位置序号以及所述目标密文之后的每个密文的位置序号加一,得到第二位置信息。
比如,若编辑操作为插入时,插入的明文位置为第三位,基于插入的明文位置获取的新增明文,新增明文的输入序号为5,对新增明文加密后得到的新增密文为h,将新增密文h插入在第一密文序列abcd中的第三位上,即目标密文c的位置上,并将第一密文序列中的目标密文c和密文d向后移动一位,得到第二密文序列为abhcd;将第一位置信息中目标密文c的位置序号3确定为新增密文h的位置序号,将新增明文的输入序号5确定为新增密文h对应的明文的输入序号,即P3=5,并将目标密文c的位置序号以及密文d的位置序号加一,得到第二位置信息为P1=1,P2=2,P3=5,P4=3,P5=4。
在本发明的另一实施例中,当所述编辑操作为替换时,若检测到对所述输入的明文的编辑操作,所述编辑单元具体用于:
基于替换的明文位置,获取替换明文,并对所述替换明文进行加密,得到替换密文;
将所述第一密文序列中与所述替换的明文位置相同的位置上的目标密文替换为所述替换密文,得到第二密文序列;
将所述第一位置信息中所述目标密文的位置序号确定为所述替换密文的位置序号,以及将所述替换明文的输入序号确定为所述第一位置信息中所述替换密文对应的输入序号,得到所述第二位置信息。
比如,若编辑操作为替换时,替换的明文位置为第三位,基于替换的明文位置获取替换明文,替换明文的输入序号为5,对替换明文加密后得到的替换密文为q,将第一密文序列abcd中的第三位上的目标密文替换为替换密文q,得到第二密文序列为abqd,将第一位置信息中目标密文c的位置序号3确定为替换密文q的位置序号,即P3=5,相应的第二位置信息为P1=1,P2=2,P3=5,P4=4。
进一步,当该编辑操作为替换时,不仅可以通过上述替换的方法进行 操作,还可以通过先删除,后插入的方法进行操作,即先按照上述删除的方法删除待替换的明文,再按照上述插入的方法在对应的位置上插入替换明文,以完成相应的替换,本发明实施例在此不再赘述。
本发明实施例提供的一种加密装置,通过接收输入的i个明文,并按照明文的输入顺序,基于主密钥对i个明文中的每个明文进行加密,得到第一密文序列以及与第一密文序列对应的第一位置信息,在检测到对输入的明文的编辑操作时,基于该编辑操作,修改第一密文序列和第一位置信息,得到第二密文序列和第二位置信息,第二密文序列中密文的顺序与编辑后的明文的顺序一致,第二位置信息中的每个密文的位置指示信息用于指示对应的密文在第二密文序列中的位置,发送第二密文序列以及第二位置信息,从而在不影响此前输入的整条序列的基础上,满足用户对输入的信息进行实时的删除、插入和替换等编辑操作,在一定程度上提高了加密速度。
图9为本发明实施例提供的一种解密装置,参见图9,该装置包括:
接收单元501,用于接收第二密文序列和第二位置信息,所述第二密文序列包括j个密文,所述第二位置信息包括所述j个密文中每个密文的位置指示信息和输入指示信息,一个密文的位置指示信息用于指示所述密文在所述第二密文序列中的位置,一个密文的输入指示信息用于指示所述密文对应的明文的输入顺序,所述j≥1;
解密单元502,用于对于所述第二密文序列中的每个密文,基于主密钥和所述第二位置信息中所述密文的输入指示信息,对所述密文进行解密,得到所述密文对应的明文;
确定单元503,用于基于所述第二位置信息中每个密文的位置指示信息所指示的位置确定每个密文对应的明文的位置。
可选的,对于所述第二密文序列中的每个密文,所述解密单元具体用于:
根据所述第二位置信息中所述密文的输入指示信息,获取第一数值和第二数值;
基于所述主密钥和所述第一数值生成密钥流,从所述密钥流中获取所述第二数值对应的密钥;
基于所述第二数值对应的密钥,对所述密文进行解密,得到所述密文对应的明文。
需要说明的是,第一数值和第二数值是根据该密文的输入指示信息确定的,且第一数值和第二数值为大于等于0的整数。
另外,解密装置中的主密钥与加密装置中的主密钥保持一致,且解密装置中的密钥流发生器与上述加密装置中的密钥流发生器类似,获取加密时的密钥与获取解密时的密钥的方法与也类似,本发明实施例在此不再赘述。
可选的,所述位置指示信息为所述密文在第二密文序列中的位置序号,所述输入指示信息为与所述密文对应的明文的输入序号。
在本发明的另一实施例中,当所述输入指示信息为所述密文对应的明文的输入序号时,所述解密单元还具体用于:
若所述密文对应的明文的输入序号与预设长度能够整除,则将相除的商确定为第一数值,将第二数值确定为零;
若所述密文对应的明文的输入序号与所述预设长度不能整除,则将相除的商确定为第一数值,将相除的余数确定为第二数值。
进一步的,若第一数值表示为P,第二数值表示为Q,密文对应的明文的输入序号表示为S,则根据第二位置信息中该密文的输入指示信息S,获取第一数值P和第二数值Q时,还可以根据第一数值P,第二数值Q,该密文的输入序号S和预设长度L满足的关系式L*P+Q=S进行确定,其中,P和Q为满足关系式L*P+Q=S的最小非负整数。
本发明实施例提供的一种解密装置,通过接收第二密文序列和第二位置信息,第二密文序列包括j个密文,第二位置信息包括j个密文中每个密文的位置指示信息和输入指示信息,对于第二密文序列中的每个密文,基于主密钥和第二位置信息中该密文的输入指示信息,对该密文进行解密,得到该密文对应的明文,之后,基于第二位置信息中每个密文的位置指示信息所指示的位置确定每个密文对应的明文的位置,即得到第二密文序列对应的明文,从而可以根据用户对输入的信息的删除、插入和替换等修改造成的位置信息的变化,解密出相应的明文,在一定程度上提高了解密速度。
本发明实施例提供如图1所示的一种终端,该终端包括处理器120、存储器110、输入单元130、系统总线和通信接口。
所述存储器110用于存储计算机执行指令,所述处理器120与所述存储器110通过所述系统总线连接,所述输入单元用于接收输入的信息,当所述终端运行时,所述处理器120执行所述存储器110存储的所述计算机执行指令,以使所述终端执行上述如图2所示的加密方法。
在具体实现过程中,上述如图2所示的加密方法可以通过硬件形式的处理器120执行存储器110中存储的软件形式的计算机执行指令实现。为避免重复,此处不再赘述。
本发明实施例提供的一种终端,通过接收输入的i个明文,并按照明文的输入顺序,基于主密钥对i个明文中的每个明文进行加密,得到第一密文序列以及与第一密文序列对应的第一位置信息,在检测到对输入的明文的编辑操作时,基于该编辑操作,修改第一密文序列和第一位置信息,得到第二密文序列和第二位置信息,第二密文序列中密文的顺序与编辑后的明文的顺序一致,第二位置信息中的每个密文的位置指示信息用于指示对应的密文在第二密文序列中的位置,发送第二密文序列以及第二位置信息,从而在不影响此前输入的整条序列的基础上,满足用户对输入的信息进行实时的删除、插入和替换等编辑操作,在一定程度上提高了终端加密的速度。
本发明实施例提供如图1所示的另一种终端,该终端包括处理器120、存储器110、系统总线和通信接口。
所述存储器110用于存储计算机执行指令,所述处理器120与所述存储器110通过所述系统总线连接,当所述终端运行时,所述处理器120执行所述存储器110存储的所述计算机执行指令,以使所述终端执行上述如图7所示的解密方法。具体的解密方法可参见如图7所示的实施例中的相关描述,此处不再赘述。
在具体实现过程中,上述如图7所示的解密方法可以通过硬件形式的处理器120执行存储器110中存储的软件形式的计算机执行指令实现。为避免重复,此处不再赘述。
本发明实施例提供的一种终端,通过接收第二密文序列和第二位置信 息,第二密文序列包括j个密文,第二位置信息包括j个密文中每个密文的位置指示信息和输入指示信息,对于第二密文序列中的每个密文,基于主密钥和第二位置信息中该密文的输入指示信息,对该密文进行解密,得到该密文对应的明文,之后,基于第二位置信息中每个密文的位置指示信息所指示的位置确定每个密文对应的明文的位置,即得到第二密文序列对应的明文,从而可以根据用户对输入的信息的删除、插入和替换等修改造成的位置信息的变化,解密出相应的明文,在一定程度上提高了终端解密的速度。
最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的精神和范围。

Claims (22)

  1. 一种加密方法,其特征在于,所述方法包括:
    接收输入的i个明文,所述i≥1;
    按照所述明文的输入顺序,基于主密钥对所述i个明文中的每个明文进行加密,得到第一密文序列以及与所述第一密文序列对应的第一位置信息,所述第一密文序列包括与所述i个明文对应的i个密文,所述第一位置信息包括所述i个密文中的每个密文的位置指示信息和输入指示信息,一个密文的位置指示信息用于指示所述密文在所述第一密文序列中的位置,一个密文的输入指示信息用于指示所述密文对应的明文的输入顺序;
    若检测到对所述输入的明文的编辑操作,则基于所述编辑操作,修改所述第一密文序列和所述第一位置信息,得到第二密文序列和第二位置信息,所述第二密文序列中密文的顺序与编辑后的明文的顺序一致,所述第二位置信息中的每个密文的位置指示信息用于指示对应的密文在所述第二密文序列中的位置;
    发送所述第二密文序列以及第二位置信息。
  2. 根据权利要求1所述的方法,其特征在于,所述编辑操作为删除、插入和替换中的任一种。
  3. 根据权利要求1或2所述的方法,其特征在于,所述位置指示信息为所述密文在第一密文序列中的位置序号,所述输入指示信息为与所述密文对应的明文的输入序号。
  4. 根据权利要求3所述的方法,其特征在于,当所述编辑操作为删除时,所述基于所述编辑操作,修改所述第一密文序列和所述第一位置信息,得到第二密文序列和第二位置信息,具体为:
    基于删除的明文位置,删除所述第一密文序列中与所述删除的明文位置相同的位置上的目标密文;
    将所述第一密文序列中所述目标密文之后的每个密文向前移动一位,得到第二密文序列;
    将所述第一位置信息中所述目标密文之后的每个密文的位置序号减一,以及删除所述第一位置信息中所述目标密文对应的输入序号,得到第二位置信息。
  5. 根据权利要求3所述的方法,其特征在于,当所述编辑操作为插入时,所述基于所述编辑操作,修改所述第一密文序列和所述第一位置信息,得到第二密文序列和第二位置信息,具体为:
    基于插入的明文位置,获取新增明文,并对所述新增明文进行加密,得到新增密文;
    将所述新增密文添加在所述第一密文序列中所述目标密文的位置,并将所述第一密文序列中的所述目标密文以及所述目标密文之后的每个密文向后移动一位,得到第二密文序列,所述目标密文在所述第一密文序列中的位置与所述插入的明文位置相同;
    将所述第一位置信息中所述目标密文的位置序号确定为所述新增密文的位置序号,以及所述新增明文的输入序号确定为所述新增密文对应的明文的输入序号,并将所述目标密文的位置序号以及所述目标密文之后的每个密文的位置序号加一,得到第二位置信息。
  6. 根据权利要求3所述的方法,其特征在于,当所述编辑操作为替换时,所述基于所述编辑操作,修改所述第一密文序列和所述第一位置信息,得到第二密文序列和第二位置信息,具体为:
    基于替换的明文位置,获取替换明文,并对所述替换明文进行加密,得到替换密文;
    将所述第一密文序列中与所述替换的明文位置相同的位置上的目标密文替换为所述替换密文,得到第二密文序列;
    将所述第一位置信息中所述目标密文的位置序号确定为所述替换密文的位置序号,以及将所述替换明文的输入序号确定为所述第一位置信息中所述替换密文对应的输入序号,得到所述第二位置信息。
  7. 一种解密方法,其特征在于,所述方法包括:
    接收第二密文序列和第二位置信息,所述第二密文序列包括j个密文,所述第二位置信息包括所述j个密文中每个密文的位置指示信息和输入指示信息,一个密文的位置指示信息用于指示所述密文在所述第二密文序列中的位置,一个密文的输入指示信息用于指示所述密文对应的明文的输入顺序,所述j≥1;
    对于所述第二密文序列中的每个密文,基于主密钥和所述第二位置信 息中所述密文的输入指示信息,对所述密文进行解密,得到所述密文对应的明文;
    基于所述第二位置信息中每个密文的位置指示信息所指示的位置确定每个密文对应的明文的位置。
  8. 根据权利要求7所述的方法,其特征在于,所述基于主密钥和所述第二位置信息中所述密文的输入指示信息,对所述密文进行解密,得到所述密文对应的明文,包括:
    根据所述第二位置信息中所述密文的输入指示信息,获取第一数值和第二数值;
    基于所述主密钥和所述第一数值生成密钥流,从所述密钥流中获取所述第二数值对应的密钥;
    基于所述第二数值对应的密钥,对所述密文进行解密,得到所述密文对应的明文。
  9. 根据权利要求7或8所述的方法,其特征在于,所述位置指示信息为所述密文在第二密文序列中的位置序号,所述输入指示信息为与所述密文对应的明文的输入序号。
  10. 根据权利要求9所述的方法,其特征在于,当所述输入指示信息为所述密文对应的明文的输入序号时,所述根据所述第二位置信息中所述密文的输入指示信息,获取第一数值和第二数值,具体为:
    若所述密文对应的明文的输入序号与预设长度能够整除,则将相除的商确定为第一数值,将第二数值确定为零;
    若所述密文对应的明文的输入序号与所述预设长度不能整除,则将相除的商确定为第一数值,将相除的余数确定为第二数值。
  11. 一种加密装置,其特征在于,所述装置包括:
    接收单元,用于接收输入的i个明文,所述i≥1;
    加密单元,用于按照所述明文的输入顺序,基于主密钥对所述i个明文中的每个明文进行加密,得到第一密文序列以及与所述第一密文序列对应的第一位置信息,所述第一密文序列包括与所述i个明文对应的i个密文,所述第一位置信息包括所述i个密文中的每个密文的位置指示信息和输入指示信息,一个密文的位置指示信息用于指示所述密文在所述第一密文序 列中的位置,一个密文的输入指示信息用于指示所述密文对应的明文的输入顺序;
    编辑单元,用于若检测到对所述输入的明文的编辑操作,则基于所述编辑操作,修改所述第一密文序列和所述第一位置信息,得到第二密文序列和第二位置信息,所述第二密文序列中密文的顺序与编辑后的明文的顺序一致,所述第二位置信息中的每个密文的位置指示信息用于指示对应的密文在所述第二密文序列中的位置;
    发送单元,用于发送所述第二密文序列以及第二位置信息。
  12. 根据权利要求11所述的装置,其特征在于,所述编辑操作为删除、插入和替换中的任一种。
  13. 根据权利要求11或12所述的装置,其特征在于,所述位置指示信息为所述密文在第一密文序列中的位置序号,所述输入指示信息为与所述密文对应的明文的输入序号。
  14. 根据权利要求13所述的装置,其特征在于,当所述编辑操作为删除时,若检测到对所述输入的明文的编辑操作,所述编辑单元具体用于:
    基于删除的明文位置,删除所述第一密文序列中与所述删除的明文位置相同的位置上的目标密文;
    将所述第一密文序列中所述目标密文之后的每个密文向前移动一位,得到第二密文序列;
    将所述第一位置信息中所述目标密文之后的每个密文的位置序号减一,以及删除所述第一位置信息中所述目标密文对应的输入序号,得到第二位置信息。
  15. 根据权利要求13所述的装置,其特征在于,当所述编辑操作为插入时,若检测到对所述输入的明文的编辑操作,所述编辑单元具体用于:
    基于插入的明文位置,获取新增明文,并对所述新增明文进行加密,得到新增密文;
    将所述新增密文添加在所述第一密文序列中所述目标密文的位置,并将所述第一密文序列中的所述目标密文以及所述目标密文之后的每个密文向后移动一位,得到第二密文序列,所述目标密文在所述第一密文序列中的位置与所述插入的明文位置相同;
    将所述第一位置信息中所述目标密文的位置序号确定为所述新增密文的位置序号,以及所述新增明文的输入序号确定为所述新增密文对应的明文的输入序号,并将所述目标密文的位置序号以及所述目标密文之后的每个密文的位置序号加一,得到第二位置信息。
  16. 根据权利要求13所述的装置,其特征在于,当所述编辑操作为替换时,若检测到对所述输入的明文的编辑操作,所述编辑单元具体用于:
    基于替换的明文位置,获取替换明文,并对所述替换明文进行加密,得到替换密文;
    将所述第一密文序列中与所述替换的明文位置相同的位置上的目标密文替换为所述替换密文,得到第二密文序列;
    将所述第一位置信息中所述目标密文的位置序号确定为所述替换密文的位置序号,以及将所述替换明文的输入序号确定为所述第一位置信息中所述替换密文对应的输入序号,得到所述第二位置信息。
  17. 一种解密装置,其特征在于,所述装置包括:
    接收单元,用于接收第二密文序列和第二位置信息,所述第二密文序列包括j个密文,所述第二位置信息包括所述j个密文中每个密文的位置指示信息和输入指示信息,一个密文的位置指示信息用于指示所述密文在所述第二密文序列中的位置,一个密文的输入指示信息用于指示所述密文对应的明文的输入顺序,所述j≥1;
    解密单元,用于对于所述第二密文序列中的每个密文,基于主密钥和所述第二位置信息中所述密文的输入指示信息,对所述密文进行解密,得到所述密文对应的明文;
    确定单元,用于基于所述第二位置信息中每个密文的位置指示信息所指示的位置确定每个密文对应的明文的位置。
  18. 根据权利要求17所述的装置,其特征在于,对于所述第二密文序列中的每个密文,所述解密单元具体用于:
    根据所述第二位置信息中所述密文的输入指示信息,获取第一数值和第二数值;
    基于所述主密钥和所述第一数值生成密钥流,从所述密钥流中获取所述第二数值对应的密钥;
    基于所述第二数值对应的密钥,对所述密文进行解密,得到所述密文对应的明文。
  19. 根据权利要求17或18所述的装置,其特征在于,所述位置指示信息为所述密文在第二密文序列中的位置序号,所述输入指示信息为与所述密文对应的明文的输入序号。
  20. 根据权利要求19所述的装置,其特征在于,当所述输入指示信息为所述密文对应的明文的输入序号时,所述解密单元还具体用于:
    若所述密文对应的明文的输入序号与预设长度能够整除,则将相除的商确定为第一数值,将第二数值确定为零;
    若所述密文对应的明文的输入序号与所述预设长度不能整除,则将相除的商确定为第一数值,将相除的余数确定为第二数值。
  21. 一种终端,其特征在于,所述终端包括:处理器、存储器、输入单元、系统总线和通信接口;
    所述存储器用于存储计算机执行指令,所述处理器与所述存储器通过所述系统总线连接,所述输入单元用于接收输入的信息,当所述终端运行时,所述处理器执行所述存储器存储的所述计算机执行指令,以使所述终端执行上述权利要求1-6任一项所述的加密方法。
  22. 一种终端,其特征在于,所述终端包括:处理器、存储器、系统总线和通信接口;
    所述存储器用于存储计算机执行指令,所述处理器与所述存储器通过所述系统总线连接,当所述终端运行时,所述处理器执行所述存储器存储的所述计算机执行指令,以使所述终端执行上述权利要求7-10任一项所述的解密方法。
PCT/CN2016/080571 2016-04-28 2016-04-28 加密、解密方法及装置 WO2017185312A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201680014791.0A CN108028754B (zh) 2016-04-28 2016-04-28 加密、解密方法、装置及终端
PCT/CN2016/080571 WO2017185312A1 (zh) 2016-04-28 2016-04-28 加密、解密方法及装置

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2016/080571 WO2017185312A1 (zh) 2016-04-28 2016-04-28 加密、解密方法及装置

Publications (1)

Publication Number Publication Date
WO2017185312A1 true WO2017185312A1 (zh) 2017-11-02

Family

ID=60160545

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/080571 WO2017185312A1 (zh) 2016-04-28 2016-04-28 加密、解密方法及装置

Country Status (2)

Country Link
CN (1) CN108028754B (zh)
WO (1) WO2017185312A1 (zh)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108900965A (zh) * 2018-06-27 2018-11-27 Oppo广东移动通信有限公司 位置提示方法、装置、存储介质及电子设备
CN112422494A (zh) * 2020-08-06 2021-02-26 上海幻电信息科技有限公司 数据传输方法、数据安全验证方法及数据传输系统
US11387980B2 (en) 2017-12-21 2022-07-12 Nordic Semiconductor Asa Hardware multiple cipher engine
CN116527233A (zh) * 2023-03-13 2023-08-01 安徽合工质能双碳科技有限公司 基于云计算的能源监测数据管理系统

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1831900A (zh) * 2005-03-08 2006-09-13 株式会社东芝 解密装置和解密方法
CN101984574A (zh) * 2010-11-29 2011-03-09 北京卓微天成科技咨询有限公司 一种数据加解密方法及装置
CN102012993A (zh) * 2010-11-29 2011-04-13 北京卓微天成科技咨询有限公司 一种数据选择加密解密方法及装置
CN102064936A (zh) * 2010-11-29 2011-05-18 北京卓微天成科技咨询有限公司 一种数据加解密方法及装置
CN102402670A (zh) * 2011-08-03 2012-04-04 广东欧珀移动通信有限公司 一种文件加解密方法
WO2014007296A1 (ja) * 2012-07-04 2014-01-09 日本電気株式会社 順序保存暗号化システム、暗号化装置、復号化装置、暗号化方法、復号化方法およびこれらのプログラム

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1633070A (zh) * 2004-10-29 2005-06-29 徐子杰 一种数据加密解密方法及加密解密装置
US8447968B2 (en) * 2005-10-28 2013-05-21 Alcatel Lucent Air-interface application layer security for wireless networks
US7428306B2 (en) * 2006-04-18 2008-09-23 International Business Machines Corporation Encryption apparatus and method for providing an encrypted file system
CN102624708A (zh) * 2012-02-23 2012-08-01 浙江工商大学 一种面向云存储的高效数据加密、更新和访问控制方法
US9237014B2 (en) * 2013-05-28 2016-01-12 Hong Kong Applied Science & Technology Research Institute Company, Limited Partial CipherText updates using variable-length segments delineated by pattern matching and encrypted by fixed-length blocks

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1831900A (zh) * 2005-03-08 2006-09-13 株式会社东芝 解密装置和解密方法
CN101984574A (zh) * 2010-11-29 2011-03-09 北京卓微天成科技咨询有限公司 一种数据加解密方法及装置
CN102012993A (zh) * 2010-11-29 2011-04-13 北京卓微天成科技咨询有限公司 一种数据选择加密解密方法及装置
CN102064936A (zh) * 2010-11-29 2011-05-18 北京卓微天成科技咨询有限公司 一种数据加解密方法及装置
CN102402670A (zh) * 2011-08-03 2012-04-04 广东欧珀移动通信有限公司 一种文件加解密方法
WO2014007296A1 (ja) * 2012-07-04 2014-01-09 日本電気株式会社 順序保存暗号化システム、暗号化装置、復号化装置、暗号化方法、復号化方法およびこれらのプログラム

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US11387980B2 (en) 2017-12-21 2022-07-12 Nordic Semiconductor Asa Hardware multiple cipher engine
CN108900965A (zh) * 2018-06-27 2018-11-27 Oppo广东移动通信有限公司 位置提示方法、装置、存储介质及电子设备
CN112422494A (zh) * 2020-08-06 2021-02-26 上海幻电信息科技有限公司 数据传输方法、数据安全验证方法及数据传输系统
CN112422494B (zh) * 2020-08-06 2022-09-23 上海幻电信息科技有限公司 数据传输方法、数据安全验证方法及数据传输系统
CN116527233A (zh) * 2023-03-13 2023-08-01 安徽合工质能双碳科技有限公司 基于云计算的能源监测数据管理系统
CN116527233B (zh) * 2023-03-13 2023-09-19 安徽合工质能双碳科技有限公司 基于云计算的能源监测数据管理系统

Also Published As

Publication number Publication date
CN108028754B (zh) 2020-12-01
CN108028754A (zh) 2018-05-11

Similar Documents

Publication Publication Date Title
WO2018176781A1 (zh) 信息发送方法、信息接收方法、装置及系统
CN111193695B (zh) 一种第三方账号登录的加密方法、装置及存储介质
WO2018133686A1 (zh) 一种密码保护方法、装置及存储介质
EP3226463B1 (en) Data encryption and decryption method and encryption and decryption device
CN108769027B (zh) 安全通信方法、装置、移动终端和存储介质
WO2017185312A1 (zh) 加密、解密方法及装置
US10454905B2 (en) Method and apparatus for encrypting and decrypting picture, and device
WO2019223441A1 (zh) 文件分享方法、装置、可读存储介质及移动终端
US10791124B2 (en) Method and terminal device for encrypting message
WO2020037577A1 (zh) 通讯通道加密、解密和建立方法及装置、存储器和终端
CN108616878B (zh) 一种加密解密方法、设备和计算机存储介质
WO2021089035A1 (zh) 一种签约数据的管理方法、装置
CN111193588B (zh) 基于进程的信息处理方法、装置及存储介质
US9166794B2 (en) Securing private key access for cross-component message processing
CN106331379B (zh) 保密通话方法、装置及便携式移动终端
CN107040367B (zh) 会话密钥协商的方法、装置和系统
WO2023065772A1 (zh) 日志数据处理方法及装置、存储介质和电子设备
CN114553612B (zh) 数据加密、解密方法、装置、存储介质及电子设备
WO2018107398A1 (zh) 验证消息合法性的方法和服务器
CN111050316B (zh) 锁卡方法及装置、计算机可读存储介质及终端设备
CN111625278A (zh) 一种源代码文件的生成方法及相关设备
CN106209736B (zh) 流媒体数据播放方法、终端及流媒体服务器
KR20050113204A (ko) 통신 장치 상의 데이터를 보호하는 시스템 및 방법
WO2018094594A1 (zh) 通信方法和设备
CN110601841B (zh) Sm2协同签名及解密方法、装置

Legal Events

Date Code Title Description
NENP Non-entry into the national phase

Ref country code: DE

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

Ref document number: 16899825

Country of ref document: EP

Kind code of ref document: A1

122 Ep: pct application non-entry in european phase

Ref document number: 16899825

Country of ref document: EP

Kind code of ref document: A1