encrypt and decrypt property file value in java

后端 未结 4 797
执念已碎
执念已碎 2020-12-30 06:04

I am looking for a way to encrypt a password in a configuration file that is being read by a Java program. Currently, I read-in the password from the text file, but that lea

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-30 07:02

    I am having trouble with the string-->encrytped bytes-->string conversions.

    I'd stuff the byte array through a base64 en/decoder, this way you'll have to persist strings that contain nothing but chars within (a subset of) ASCII, which should limit your trouble. Have a look e.g. at commons codecs and replace your new String(decrypted) with a call to one of the static methods in the org.apache.commons.codec.binary.Base64 class.

    Besides that I think what you ultimately want to do is not strictly to "encrypt" the password but rather to store only a hash of the password, which was already discussed on SO.

提交回复
热议问题