Encrypting config files for deployment

末鹿安然 提交于 2019-12-04 19:16:14

reduce the problem to its simplest form:

  • you have a program
  • that will be given an encrypted file
  • and you want to decrypt the file
  • without hard-coding the key

the obvious solution is to ask for the key when needed from a trusted third party

One possible way to do this would be to include the decryption key at the beginning of the file, and the key has been reprocessed in some fashion that you can determine from the key. One possibility would be to pick, like, say sixteen different things, 0 being, say, rotate the first two bytes to the end; 1 being rotate the last two bytes to the front; 2 being add 1 to every byte; and so on for 14 additional functions. Now add this value in front of the key as the "reprocess flag".

The first byte of the key would then be a branch table to one of 16 different routines to say what to do with the key. Note that the reprocess flag doesn't have to be the first byte, it can be any byte in the key as long as you remember to throw that byte away when handling the key.

Then you process the key according to whatever decryption algorithm you would use.

Now, given this reprocess flag - especially if the entire key was in hexadecimal - would require someone follow the logic to determine which of the 16 different functions your code executed, then figure out the decryption method. It's not going to stop everyone but it will probably do a fairly good job driving away all but the most determined.

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