AES-based encryption and decryption scheme

Decrypt and verify the message
sent by the front end 1. The message sent by the front end is encrypted as a whole, and then the overall encrypted data is used as the value of encodeFieldVals; at the same time, the data sent by the front end to the back end together includes the overall encrypted aesKey
Example of front-end requesting back-end:
    http://127.0.0.1:8080/btoa/user/login
    {
        encodeFieldVals=encrypted data,
        aesKey= aesKey of overall encryption
    }
2. The back-end obtains the values ​​of encodeFieldVals and aesKey, and uses aesKey to encodeFieldVals Overall decryption, the data format of encodeFieldVals after overall decryption is json format.
The decrypted data format is as follows:
{
    "deviceId" : "a123xwsdfx4554rcffffooc87",
    "osVersion" : "5.1.10",
    "userName" : "Wang Wu",
     "password" : "a123xwsdfx4554rcffffooc87a123xwsdfx4554rcffffooc87"
    "phoneNo" :"

    encryptFields : "password,phoneNo",
    serverTimestamp : "1200000",
    signtrue : "asfdsafax3134134912341241WQ"
}
3. Sign verification, the overall decrypted json has a field signtrue, which is the signature of the front-end to the data; Sort all key values, and then assemble all the keys except the key as signtrue and encodeFieldVals in the following format:
    fieldName1=fieldValue1&fieldName2=fieldValue2...
Assemble into a string; after signing, compare with signtrue, if they are equal, the verification is successful; otherwise, the verification is successful. Signing failed.
4. Single-field encryption, overall decryption In the encrypted json data, some sensitive information fields are encrypted, and the encrypted fields are specified by encryptFields, separated by English commas. Take the values ​​of these fields for single-field decryption.

Flowchart:





Encrypt and sign the message returned to the front end
1. If all encryption is configured, obtain the data returned to the front end, encrypt all the data, and return the encrypted data as the value of encodeFieldVals

2. Obtain the data returned to the front end according to The configured field encrypts the single field that needs to be encrypted, and returns the encrypted data to the front end as the value of encodeFieldVals. At the same time, the returned json contains encryptFields to identify which fields are processed by single-field encryption.
{
     "respCode": "000000",

    "userId" : "afasfa134dfdasf",
    "email" : "[email protected]",
    "phoneNo" : "13711645814",
    "nickName" : "Bawang",
    "accountInfo" : {
              "accountNo" : "A1237897029",
              " identityId" : "440902198609228090",
              "nameName" : "Zhao Liu",
              "validateDate" : "20101010-20221010"
    },
       signtrue : "asfdsafax3134134912341241WQ",
       encryptFields: "identityId,nameName"
}
3. Return the encrypted data to the front end
flow chart:








Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326429337&siteId=291194637