How to encrypt a value in ini file

牧云@^-^@ 提交于 2019-12-22 10:35:35

问题


What is the best way to encrypt a value in INI file?

Using Encryption/Decryption key??


回答1:


For what purpose? Security?

If you are trying to (e.g.) encrypt a plaintext password you should probably use some implementation of PKI. Remember though, that then key management becomes your problem. Just encrypting the value is not a panacea because the ini file is most likely on the local host's file system, presumably the same place you'll have to store your key pair. You've simply abstracted the problem down a layer. They won't be able to read your encrypted password directly, but if they can find the place you store your key pair they can decrypt it themselves.




回答2:


To what effect? What are you trying to protect or obfuscate?

You could use one of the many two-way key encryption algorithms available for all platforms... But ask yourself why you're doing it in the first place. If you're trying to make something hack-proof, encrypting ini strings probably isn't going to get you that far because as soon as you decrypt the ini, the string is in memory. And the key to decrypt will be in your program. Childsplay to hack out.

If you just want to stop people editing a setting easily, don't put it in an ini. Choose a binary format that the user will have a hard time editing.




回答3:


For personal scripts where I have an email password, I use TinyEncryption.

I will put the passkey in the code itself. This prevents a casual snooper from just browsing through and picking up an email password.

The code is pretty simple too. Here it is in Python.

import random
import base64
def tinycode(key, text, reverse=False):
    "(de)crypt stuff"
    rand = random.Random(key).randrange
    if reverse:
        text = base64.b64decode(text)
    text = ''.join([chr(ord(elem)^rand(256)) for elem in text])
    if not reverse:
        text = base64.b64encode(text)
    return text

For more enhanced security, I use PGP, but you then have to prompt for a passkey. There's no setup that's perfect, it depends on what your needs are.




回答4:


You could use any standard encryption algorithm with a key, and perhaps prefix the value with some random padding before encrypting.

However where do you plan to store that key then? Or are you going to get the user to enter a password and derive a key from that? If not then it would be fairly pointless to encrypt the value.




回答5:


Do you need to decrypt it too? If not you can just salt and hash it.

If you do want to decrypt it, then Id say you should specify the language as well perhaps.




回答6:


MD5 hash

Then you compare hash("password") with the ini_file.password hash



来源:https://stackoverflow.com/questions/386374/how-to-encrypt-a-value-in-ini-file

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