Disclosure of Invention
The embodiment of the application provides a parameter transmission method, device, equipment and storage medium based on JSON (Java Server object) to solve at least one problem existing in the related art, and the technical scheme is as follows:
in a first aspect, an embodiment of the present application provides a method for parameter transmission based on JSON, including:
acquiring dynamic encryption parameters through an initialization API interface and acquiring input parameters through a JSON interface;
determining the interface type of the JSON interface, and carrying out first encryption processing on the input parameters according to the interface type and the dynamic encryption parameters to obtain an encrypted message;
transmitting the encrypted message to a rear end, and carrying out decryption verification on the encrypted message to obtain a decryption verification result;
And when the decryption verification result represents that decryption is successful, determining an output parameter by the rear end in response to the input parameter, and returning the output parameter after performing second encryption processing.
In one embodiment, the dynamic encryption parameters include a ticket and a dynamic key parameter, and the obtaining the dynamic encryption parameters through the initializing API interface includes:
the front end sends an initialization request for the API interface;
and responding to the initialization request by the back end, and sending a bill to the front end so that the front end generates dynamic key parameters required by encryption.
In one embodiment, the performing, according to the interface type and the dynamic encryption parameter, a first encryption process on the input parameter to obtain an encrypted message includes:
Determining a target parameter from the input parameters according to the interface type;
and carrying out first encryption processing on the target parameter and the bill according to the dynamic key parameter to obtain an encrypted message.
In one embodiment, the determining the target parameter from the input parameters according to the interface type includes:
when the interface type is a full-entry secret type interface, determining the input parameter as a target parameter;
And when the interface type is a part of the input secret type interface, determining irregular parameters in the input parameters as target parameters.
In one embodiment, the performing, according to the dynamic key parameter, a first encryption process on the target parameter and the ticket to obtain an encrypted message includes:
performing AES encryption on the target parameter and the bill by utilizing the dynamic key parameter to obtain an AES encryption result;
and carrying out secondary encryption on the AES encryption result through an asymmetric encryption algorithm to obtain an encrypted message, wherein a header of the encrypted message comprises the dynamic key parameter.
In one embodiment, the performing decryption verification on the encrypted message, and obtaining a decryption verification result includes:
decrypting the encrypted message, and determining the function type of the JSON interface when the encrypted message is successfully decrypted to obtain the bill;
And determining the using state of the bill, and determining a decryption verification result according to the function type and the using state.
In one embodiment, the determining the decryption verification result according to the function type and the usage state includes:
when the function type is a query type, if the use time in the use state is smaller than or equal to a time threshold value, determining a decryption verification result representing that decryption is successful;
And when the function type is a transaction type, if the use times in the use state are smaller than or equal to a times threshold value, determining a decryption verification result representing that decryption is successful.
In a second aspect, an embodiment of the present application provides a parameter transmission device based on JSON, including:
The acquisition module is used for acquiring dynamic encryption parameters through an initialization API interface and acquiring input parameters through a JSON interface;
the encryption module is used for determining the interface type of the JSON interface, and carrying out first encryption processing on the input parameters according to the interface type and the dynamic encryption parameters to obtain an encrypted message;
the decryption module is used for transmitting the encrypted message to the rear end, and carrying out decryption verification on the encrypted message to obtain a decryption verification result;
And the output module is used for determining output parameters through the rear end in response to the input parameters when the decryption verification result represents that the decryption is successful, and returning the output parameters after the second encryption processing.
In a third aspect, an embodiment of the present application provides an electronic device, including a processor and a memory, where the memory stores instructions that are loaded and executed by the processor to implement a method in any one of the embodiments of the above aspects.
In a fourth aspect, embodiments of the present application provide a computer readable storage medium storing a computer program, which when executed implements a method in any one of the embodiments of the above aspects.
The beneficial effects in the technical scheme at least comprise:
The method comprises the steps of obtaining dynamic encryption parameters through an initialization API interface, obtaining input parameters through a JSON interface, determining the interface type of the JSON interface, carrying out first encryption processing on the input parameters according to the interface type and the dynamic encryption parameters, obtaining encrypted messages, transmitting the encrypted messages to the rear end, carrying out decryption verification on the encrypted messages to obtain decryption verification results, determining output parameters through the rear end in response to the input parameters when the decryption verification results represent successful decryption, carrying out second encryption processing on the output parameters, and then returning the output parameters, encrypting by utilizing the dynamic encryption parameters, thereby being beneficial to preventing reverse compiling and cracking of the encryption parameters, improving safety, and simultaneously being capable of adapting to different service scenes based on targeted encryption processing of different interface types, and improving flexibility and expandability.
The foregoing summary is for the purpose of the specification only and is not intended to be limiting in any way. In addition to the illustrative aspects, embodiments, and features described above, further aspects, embodiments, and features of the present application will become apparent by reference to the drawings and the following detailed description.
Detailed Description
Hereinafter, only certain exemplary embodiments are briefly described. As will be recognized by those of skill in the pertinent art, the described embodiments may be modified in various different ways without departing from the spirit or scope of the present application. Accordingly, the drawings and description are to be regarded as illustrative in nature and not as restrictive.
Noun interpretation:
JSON (JavaScript Object Notation, JS object profile) is a lightweight data exchange format. Based on a subset of ECMAScript (European Computer Manufacturers Association, js specification formulated by European computer Association), the JSON storage and representation system stores and represents data in a text format completely independent of a programming language, and a concise and clear hierarchical structure enables JSON to be an ideal data exchange language, is easy to read and write by people, is easy to analyze and generate by machines, and effectively improves network transmission efficiency.
The AES encryption algorithm (Advanced Encryption Standard) is a symmetric encryption algorithm, also called an advanced encryption standard, and uses 128-bit, 192-bit or 256-bit keys to encrypt and decrypt data, and has advantages of high strength, high speed, easy implementation, and the like.
The RSA algorithm is an asymmetric encryption algorithm, and is different from the symmetric encryption algorithm in that the RSA algorithm has two different keys, namely a public key and a private key. The public key may be public for encrypting information and the private key is kept secret by the owner for decrypting information encrypted with the public key.
Referring to fig. 1, a flowchart of a JSON-based parameter transmission method according to an embodiment of the present application is shown, and the JSON-based parameter transmission method may at least include steps S100 to S400:
S100, acquiring dynamic encryption parameters through an initialization API interface and acquiring input parameters through a JSON interface.
S200, determining the interface type of the JSON interface, and carrying out first encryption processing on the input parameters according to the interface type and the dynamic encryption parameters to obtain an encrypted message.
S300, transmitting the encrypted message to the rear end, and carrying out decryption verification on the encrypted message to obtain a decryption verification result.
S400, when the decryption verification result represents that decryption is successful, determining output parameters through the rear end in response to the input parameters, and returning the output parameters after performing second encryption processing.
The parameter transmission method based on JSON in the embodiment of the application can be executed through the front end and the back end, and the front end and the back end can be computers, mobile phones, flat plates, cloud servers and the like.
According to the technical scheme, the dynamic encryption parameters are obtained through the initialization API interface, the input parameters are obtained through the JSON interface, the interface type of the JSON interface is determined, the first encryption processing is carried out on the input parameters according to the interface type and the dynamic encryption parameters to obtain the encrypted message, the encrypted message is transmitted to the rear end, the decryption verification is carried out on the encrypted message to obtain a decryption verification result, when the decryption verification result represents successful decryption, the rear end responds to the input parameters to determine the output parameters, the output parameters are returned after the second encryption processing is carried out, the dynamic encryption parameters are utilized for encryption, the situation that the encryption parameters are decoded by reverse compiling is prevented, the safety is improved, meanwhile, the method can adapt to different service scenes based on the specific encryption processing of different interface types, and the flexibility and the expandability are improved.
As shown in fig. 2, in one embodiment, the dynamic encryption parameters include a ticket and a dynamic key parameter, and in step S100, the dynamic encryption parameters are acquired through an initializing API interface, specifically:
the front end sends an initialization request for the API interface, responds to the initialization request based on the BASE64 through the back end, sends a ticket (token) to the front end, decrypts the ticket after the front end receives the ticket, generates dynamic key parameters required by encryption through the BASE64, and provides a basis for the subsequent encryption process.
It should be noted that the dynamic encryption parameters are obtained based on the initialization request, each initialization request generates an effective dynamic encryption parameter, and the dynamic encryption parameter is invalid after being used once, so that the dynamic encryption parameter is dynamic rather than continuously unchanged and effective, and accordingly the dynamic key parameter is dynamic, the dynamic encryption parameter is unpredictable, and the single-use mode can effectively prevent a malicious user from repeatedly requesting an interface, reduce the security risk, and effectively ensure the security of the parameters in the internet transmission process, and effectively prevent information leakage and other various internet security problems caused by packet capturing and cracking of access parameter data.
In one embodiment, a user may access a request JSON interface through a front end, and obtain input parameters (i.e., an entry) associated with the request through the JSON interface.
In one embodiment, the interface types of the JSON interface include, but are not limited to, a full-join secret type interface, a partial-join secret type interface, and a non-encryption type interface. The input parameters (input parameters) are usually controllable, such as number, area code, time and other input parameters, the partial input secret type interfaces are input parameters which are irregular, such as remarks, source channels, picture file streams, picture base64 and the like, and the non-encryption type interfaces are auxiliary type interfaces which are input parameters without sensitive data and are not encrypted.
In one embodiment, in step S200, according to the interface type and the dynamic encryption parameter, a first encryption process is performed on the input parameter to obtain an encrypted message, which includes steps S210-S220:
s210, determining target parameters from the input parameters according to the interface type.
Optionally, when the interface type is a full-entry secret type interface, the input parameters are determined to be target parameters, and when the interface type is a partial-entry secret type interface, irregular parameters in the input parameters are determined to be target parameters. For example, the irregular parameters may be remarks, source channels, picture file streams, picture base64, and the like.
S220, according to the dynamic key parameters, performing first encryption processing on the target parameters and the bill to obtain an encrypted message.
Optionally, steps S2201-S2202 are included:
S2201, performing AES encryption on the target parameter and the bill by utilizing the dynamic key parameter to obtain an AES encryption result;
Optionally, after the front end acquires the bill and determines the target parameter, the front end uses the dynamic key parameter to perform AES encryption on the target parameter and the bill, so as to obtain an AES encryption result. Illustratively, the dynamic key parameters may include a key offset (IV) and a key (key) of AES by which the target parameters and the ticket are AES-encrypted, thereby obtaining an AES encryption result. The AES encryption algorithm has the advantages of high strength, high speed, easiness in implementation and the like, and can effectively protect confidentiality of data.
S2202, performing secondary encryption on the AES encryption result through an asymmetric encryption algorithm to obtain an encrypted message.
And then, performing secondary encryption on an AES encryption result through an asymmetric encryption algorithm such as a public key of an RAS (remote control unit) so as to obtain an encrypted message, wherein a header of the encrypted message comprises a dynamic key parameter and is sent to a rear end together with the encrypted message, the security of the key is ensured by the asymmetric characteristic of the RSA algorithm, the public key is used for encryption, and the private key is used for decryption, so that the difficulty of decryption is increased.
In one embodiment, the encrypted message is transmitted to the back end, and decryption verification is performed on the encrypted message in step S300 to obtain a decryption verification result, which includes steps S310-S320:
S310, decrypting the encrypted message, and determining the function type of the JSON interface when the encrypted message is successfully decrypted to obtain the bill.
Optionally, after the back end receives the encrypted message subjected to double encryption, the encrypted message containing the input parameters (input parameters) is decrypted by using the private key, and if the decryption is successful, the function type of the JSON interface is determined. Among them, the function types include, but are not limited to, query class and transaction class.
Optionally, if the decryption fails, the back end automatically analyzes the reason of the decryption failure and returns to the front end for the user to know and end the flow.
S320, determining the using state of the bill, and determining a decryption verification result according to the function type and the using state.
Optionally, determining the usage status of the ticket, where the usage status includes the usage time and the number of uses, and S320 includes steps S3201-S3202:
S3201, when the function type is query, determining a decryption verification result representing that decryption is successful if the use time in the use state is smaller than or equal to a time threshold.
It should be noted that, for the query class, a manner of setting an expiration time is adopted, and since querying one data may require requesting multiple interfaces, if the interfaces are repeatedly requested to be initialized, resources are wasted, so that the expiration time is set, for example, the time threshold is 2 minutes, and if the expiration time exceeds 2 minutes, the expiration time is expired. In the expiration time, the front end can encrypt by using the dynamic key parameters acquired before, and the initialization interface is not required to be requested again, so that the resource waste caused by frequent request of the initialization interface is avoided, and the efficiency is improved.
Illustratively, the time threshold is 2 minutes, which may be based on actual adjustment in other embodiments. Therefore, when the function type is the query type, if the use time in the use state is less than or equal to 2 minutes, the ticket is considered to be valid, the decryption verification result which represents that the decryption is successful is determined, otherwise, the ticket is determined to be invalid, and the decryption verification result which represents that the decryption is failed is determined.
S3202, when the function type is a transaction type, if the number of times of use in the use state is smaller than or equal to a threshold value of times, determining a decryption verification result representing that decryption is successful, namely decryption failure.
The threshold number of times is 1, and when the function type is handling, if the number of times in the use state is less than or equal to 1, the ticket is considered to be valid, and a decryption verification result representing that the decryption is successful is determined, otherwise, the ticket is determined to be invalid, and a decryption verification result representing that the decryption is failed, namely the decryption is failed, is determined.
In one embodiment, in step S400, when the decryption verification result indicates that the decryption is successful, since the input parameter is obtained after the decryption, the normal JSON request logic is executed at this time, the output parameter is determined by the back end in response to the input parameter, the output parameter is subjected to the second encryption processing and then returned to the JSON interface, the front end receives the output parameter after the second encryption processing and decrypts, the output parameter is obtained after the decryption is successful, and finally the front end executes the normal logic of the front end page based on the output parameter, for example, the query class or the query result or the transaction result corresponding to the query class is displayed. Note that the second encryption processing may be AES encryption, and if decryption fails, the flow ends.
The method of the embodiment of the application introduces bill validity judgment, is beneficial to ensuring the integrity and the authenticity of data, simultaneously, the scheme can easily realize the upgrading of encryption and decryption functions without changing the original architecture of interface access, whether the front end or the rear end can write a general scheme and practice, reduces development resources and time cost, can formulate personalized schemes such as handling types and inquiry types according to different interface characteristics, has high flexibility, can better adapt to the requirements of various service scenes, adopts a dynamic encryption scheme, greatly improves the safety of the interface, avoids users from maliciously using the same input parameters to repeatedly request for submitting the interface, effectively reduces resource consumption, and can not read data content even if a crawler acquires the data after dynamically encrypting the input parameters because the crawler does not decrypt the required secret key and offset, thereby effectively guaranteeing the safety and confidentiality of the data.
Referring to fig. 3, there is shown a block diagram of a JSON-based parameter transmission apparatus in accordance with an embodiment of the present application, which may include:
The acquisition module is used for acquiring dynamic encryption parameters through an initialization API interface and acquiring input parameters through a JSON interface;
The encryption module is used for determining the interface type of the JSON interface, and carrying out first encryption processing on the input parameters according to the interface type and the dynamic encryption parameters to obtain an encrypted message;
The decryption module is used for transmitting the encrypted message to the rear end, and carrying out decryption verification on the encrypted message to obtain a decryption verification result;
And the output module is used for determining output parameters through the rear end in response to the input parameters when the decryption verification result represents that the decryption is successful, and returning the output parameters after the second encryption processing.
The functions of each module in each device of the embodiments of the present application may be referred to the corresponding descriptions in the above methods, and are not described herein again.
Referring to fig. 4, a block diagram of an electronic device according to an embodiment of the present application is shown, where the electronic device includes a memory 310 and a processor 320, and the memory 310 stores instructions executable on the processor 320, and the processor 320 loads and executes the instructions to implement the JSON-based parameter transmission method in the foregoing embodiment. Wherein the number of memory 310 and processors 320 may be one or more.
In one embodiment, the electronic device further includes a communication interface 330 for communicating with an external device for data interactive transmission. If the memory 310, the processor 320 and the communication interface 330 are implemented independently, the memory 310, the processor 320 and the communication interface 330 may be connected to each other and communicate with each other through buses. The bus may be an industry standard architecture (Industry Standard Architecture, ISA) bus, peripheral interconnect (Peripheral ComponentInterconnect, PCI) bus, or an extended industry standard architecture (Extended Industry Standard Architecture, EISA) bus, among others. The bus may be classified as an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown in fig. 4, but not only one bus or one type of bus.
Alternatively, in a specific implementation, if the memory 310, the processor 320, and the communication interface 330 are integrated on a chip, the memory 310, the processor 320, and the communication interface 330 may communicate with each other through internal interfaces.
An embodiment of the present application provides a computer-readable storage medium storing a computer program which, when executed by a processor, implements the JSON-based parameter transmission method provided in the above embodiment.
The embodiment of the application also provides a chip, which comprises a processor and is used for calling the instructions stored in the memory from the memory and running the instructions stored in the memory, so that the communication equipment provided with the chip executes the method provided by the embodiment of the application.
The embodiment of the application also provides a chip which comprises an input interface, an output interface, a processor and a memory, wherein the input interface, the output interface, the processor and the memory are connected through an internal connection path, the processor is used for executing codes in the memory, and when the codes are executed, the processor is used for executing the method provided by the application embodiment.
It should be appreciated that the processor may be a central processing unit (Central Processing Unit, CPU), other general purpose processor, digital signal processor (DIGITAL SIGNAL processing, DSP), application Specific Integrated Circuit (ASIC), field programmable gate array (fieldprogrammablegate array, FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, etc. A general purpose processor may be a microprocessor or any conventional processor or the like. It is noted that the processor may be a processor supporting an advanced reduced instruction set machine (ADVANCED RISC MACHINES, ARM) architecture.
Further, optionally, the memory may include a read-only memory and a random access memory, and may further include a nonvolatile random access memory. The memory may be volatile memory or nonvolatile memory, or may include both volatile and nonvolatile memory. The nonvolatile memory may include a read-only memory (ROM), a Programmable ROM (PROM), an erasable programmable ROM (erasable PROM), an electrically erasable programmable EPROM (EEPROM), or a flash memory, among others. Volatile memory can include random access memory (random access memory, RAM), which acts as external cache memory. By way of example, and not limitation, many forms of RAM are available. For example, static random access memory (STATIC RAM, SRAM), dynamic random access memory (dynamic random access memory, DRAM), synchronous Dynamic Random Access Memory (SDRAM), double data rate synchronous dynamic random access memory (doubledata DATE SDRAM, DDR SDRAM), enhanced synchronous dynamic random access memory (ENHANCED SDRAM, ESDRAM), synchronous link dynamic random access memory (SYNCHLINK DRAM, SLDRAM), and direct memory bus random access memory (direct rambus RAM, DR RAM).
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions in accordance with the present application are fully or partially produced. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable devices. Computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another.
In the description of the present specification, a description referring to the terms "one embodiment," "some embodiments," "examples," "specific examples," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the present application. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, the different embodiments or examples described in this specification and the features of the different embodiments or examples may be combined and combined by those skilled in the art without contradiction.
Furthermore, the terms "first," "second," and the like are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defining "a first" or "a second" may explicitly or implicitly include at least one such feature. In the description of the present application, the meaning of "a plurality" is two or more, unless explicitly defined otherwise.
Any process or method description in a flowchart or otherwise described herein may be understood as representing modules, segments, or portions of code which include one or more executable instructions for implementing specific logical functions or steps of the process. And the scope of the preferred embodiments of the present application includes additional implementations in which functions may be performed in a substantially simultaneous manner or in an opposite order from that shown or discussed, including in accordance with the functions that are involved.
Logic and/or steps represented in the flowcharts or otherwise described herein, e.g., a ordered listing of executable instructions for implementing logical functions, can be embodied in any computer-readable medium for use by or in connection with an instruction execution system, apparatus, or device, such as a computer-based system, processor-containing system, or other system that can fetch the instructions from the instruction execution system, apparatus, or device and execute the instructions.
It is to be understood that portions of the present application may be implemented in hardware, software, firmware, or a combination thereof. In the above-described embodiments, the various steps or methods may be implemented in software or firmware stored in a memory and executed by a suitable instruction execution system. All or part of the steps of the methods of the embodiments described above may be performed by a program that, when executed, comprises one or a combination of the steps of the method embodiments, instructs the associated hardware to perform the method.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing module, or each unit may exist alone physically, or two or more units may be integrated in one module. The integrated modules may be implemented in hardware or in software functional modules. The integrated modules described above, if implemented in the form of software functional modules and sold or used as a stand-alone product, may also be stored in a computer-readable storage medium. The storage medium may be a read-only memory, a magnetic or optical disk, or the like.
The foregoing is merely illustrative of the present application, and the present application is not limited thereto, and any person skilled in the art will readily recognize that various changes and substitutions are possible within the scope of the present application. Therefore, the protection scope of the application is subject to the protection scope of the claims.