Anonymization method and apparatus, device, and storage medium
View Patent ↗This disclosure provides an anonymization method and apparatus, a device, and a storage medium, and pertains to the field of communications network technologies. The method includes: receiving a data obtaining request of a first terminal, and obtaining requested target data based on the data obtaining request; determining behavior data generated when the target data is obtained; determining, based on the behavior data, a first permutation character sequence corresponding to the target data; and anonymizing, based on the first permutation character sequence, a to-be-anonymized character string in the target data, and outputting the anonymized target data. In this disclosure, because the behavior data is different each time and is not easy to crack, anonymization is implemented without relying on plaintext information, thereby improving anonymization security and meeting anonymization requirements specified by laws.
1. An anonymization method, wherein the method comprises:
receiving a data obtaining request of a first terminal, and obtaining target data based on the data obtaining request;
determining behavior data generated when the target data is obtained;
determining, based on the behavior data, a first permutation character sequence corresponding to the target data by:
determining at least one character string in the target data according to an anonymization rule of the target data,
obtaining, based on each character format of the at least one character string and a quantity of binary digits that can be embedded into a character in each character format, a second permutation character sequence corresponding to the character format;
converting the behavior data into a watermark ciphertext sequence; and
for any character in the watermark ciphertext sequence, obtaining a permutation character that is in the second permutation character sequence corresponding to the character format of the character and that has location information indicating the character, and replacing the character with the permutation character to obtain the first permutation character sequence; and
anonymizing, based on the first permutation character sequence, a character string in the target data to generate anonymized target data, and outputting the anonymized target data.
2. The method according to claim 1 , wherein the behavior data comprises a user identifier of a user requesting to obtain the target data, a system time for obtaining the target data, and a system identifier of a system for obtaining the target data.
3. The method according to claim 1 , wherein the converting the behavior data into the watermark ciphertext sequence comprises:
converting the behavior data into binary data to obtain a binary sequence;
grouping the binary sequence based on a quantity of binary digits that can be embedded into each type of character in each character string, to obtain a plurality of groups; and
converting a binary number in each group into a decimal number to obtain the watermark ciphertext sequence.
4. The method according to claim 3 , wherein the converting the behavior data into binary data to obtain the binary sequence comprises:
obtaining a first encryption key; and
encrypting the behavior data based on the first encryption key to obtain the binary sequence.
5. The method according to claim 1 , wherein the anonymizing the character string in the target data based on the first permutation character sequence comprises:
sequentially replacing characters in the character string in the target data with characters in the first permutation character sequence, to obtain an anonymized character string.
6. The method according to claim 1 , wherein the anonymizing the character string in the target data based on the first permutation character sequence comprises:
sequentially replacing characters in at least one character string in the target data with characters in the first permutation character sequence, to obtain permuted target data; and
encrypting characters in the permuted target data based on a third encryption key and a preset format-preserving encryption algorithm, to obtain the anonymized target data.
7. The method according to claim 1 , wherein before the receiving the data obtaining request, the method further comprises:
receiving a login request of the first terminal, wherein the login request carries a user account and a login password of a user;
performing permission verification on the user based on the user account and the login password; and
when the permission verification succeeds, allowing the first terminal to perform a login operation.
8. The method according to claim 1 , wherein the method further comprises:
receiving a behavior data obtaining request of a second terminal, wherein the behavior data obtaining request of the second terminal carries the anonymized target data; and
determining, based on the anonymized target data, the behavior data generated when the target data is obtained.
9. The method according to claim 8 , wherein the determining, based on the anonymized target data, the behavior data generated when the target data is obtained comprises:
obtaining, based on a character format of at least one anonymized character string in the anonymized target data, the second permutation character sequence corresponding to each character format of the at least one character string;
extracting a cyclically repeated character sequence from the anonymized target data, to obtain the watermark ciphertext sequence;
for each character in the watermark ciphertext sequence, converting, into a binary number, location information of the character in the second permutation character sequence corresponding to a character format of the character, to obtain a binary sequence; and
converting the binary sequence into the behavior data.
10. The method according to claim 9 , wherein the converting the binary sequence into the behavior data comprises:
obtaining a first encryption key; and
decrypting the binary sequence based on the first encryption key to obtain the behavior data.
11. The method according to claim 9 , wherein the extracting the cyclically repeated character sequence from the anonymized target data, to obtain the watermark ciphertext sequence comprises:
obtaining a third encryption key;
decrypting the anonymized target data based on the third encryption key and a preset format-preserving encryption algorithm, to obtain permuted target data; and
extracting the cyclically repeated character sequence from the permuted target data, to obtain the watermark ciphertext sequence.
12. A device, wherein the device comprises: a processor, a memory, a communications interface, and a bus, wherein
the memory, the processor, and the communications interface are connected through the bus, the memory stores at least one programmable instruction, and the processor invokes the at least one programmable instruction stored in the memory, to configure the device to:
receive a data obtaining request of a first terminal, and obtain target data based on the data obtaining request;
determine behavior data generated when the target data is obtained;
determine, based on the behavior data, a first permutation character sequence corresponding to the target data;
determine at least one character string in the target data according to an anonymization rule of the target data;
obtain, based on each character format of the at least one character string and a quantity of binary digits that can be embedded into a character in each character format, a second permutation character sequence corresponding to the character format;
convert the behavior data into a watermark ciphertext sequence; and
obtain, for any character in the watermark ciphertext sequence, a permutation character that is included in the second permutation character sequence corresponding to a character format of the character and that has location information indicating the character, and
replace the character with the permutation character to obtain the first permutation character sequence; and
anonymize, based on the first permutation character sequence, a character string in the target data to generate anonymized target data, and outputting the anonymized target data.
13. The device according to claim 12 , wherein the processor invokes the at least one programmable instruction stored in the memory to further configure the device to:
convert the behavior data into binary data to obtain a binary sequence;
group the binary sequence based on a quantity of binary digits that can be embedded into each type of character in each character string, to obtain a plurality of groups; and
convert a binary number in each group into a decimal number to obtain the watermark ciphertext sequence.
14. The device according to claim 13 , wherein the processor invokes the at least one programmable instruction stored in the memory to further configure the device to:
obtain a first encryption key; and
encrypt the behavior data based on the first encryption key to obtain the binary sequence.
15. The device according to claim 12 , wherein the processor invokes the at least one programmable instruction stored in the memory to further configure the device to:
sequentially replace characters in the character string in the target data with characters in the first permutation character sequence, to obtain an anonymized character string.
16. The device according to claim 12 , wherein the processor invokes the at least one programmable instruction stored in the memory to further configure the device to:
receive a behavior data obtaining request of a second terminal, wherein the behavior data obtaining request of the second terminal carries the anonymized target data; and
determine, based on the anonymized target data, the behavior data generated when the target data is obtained.
17. The device according to claim 12 , wherein the processor invokes the at least one programmable instruction stored in the memory to further configure the device to:
obtain, based on a character format of the at least one anonymized character string in the anonymized target data, the second permutation character sequence corresponding to each character format of the at least one character string;
extract a cyclically repeated character sequence from the anonymized target data, to obtain the watermark ciphertext sequence;
convert, for each character in the watermark ciphertext sequence, into a binary number, location information of the character in the second permutation character sequence corresponding to a character format of the character, to obtain a binary sequence; and
convert the binary sequence into the behavior data.
18. A non-transitory computer-readable storage medium, wherein the storage medium comprises at least one instruction, and when the at least one instruction is run on a computer, the computer is enabled to perform the method according to claim 1 .