How do obfuscate JSON response when dealing with a DB query?

无人久伴 提交于 2019-12-24 05:58:00

问题


[
 {
  "businesscards_id":"12",
  "X_SIZE":"1.75x3",
  "X_PAPER":"14ptGlossCoatedCoverwithUV(C2S)",
  "X_COLOR":"1002",
  "X_QTY":"250",
  "O_RC":"NO",
  "F_PRICE":"12490",
  "UPS_GROUND":"12000",
  "UPS_TWODAY":"24000",
  "UPS_OVERNIGHT":"36000"
 }
]

This JSON encode response is seen in console of Chrome. This array is being returned from a DB query. It is showing my table column names. For security reasons I do not want to show my table column names. How can this JSON object be obfuscated or hashed and/or encoded or dynamically re-written to keep my table col names private?


回答1:


It really depends on how you wish to use the record once it has been received. One strategy might be to return an array of the values only, discarding the keys. Then in your code, use your private knowledge of which array value you need when you process the record. Something like:

var result=[];
Object.keys(record).forEach(function(key){result.push(record[key]);});

And then in your code, use array indices to access the values.




回答2:


Don't do anything to your JSON.

If you don't want your column names to be visible, just dont use your column names. Create a new array using new keys to send with JSON and then change that array back into one containing your column names afterwards.

But it really shouldn't be a problem people seeing them. Nobody has access to your database so letting people see column names isn't an issue.




回答3:


SQL statement:

SELECT `col_name` AS 'something_else'

But also, as everyone else said, don't do this for security. It is pointless.



来源:https://stackoverflow.com/questions/13213570/how-do-obfuscate-json-response-when-dealing-with-a-db-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!