Easy encrypted your configuration in Clojure using the power of buddy.
-
[encrypted-config "0.1.1"]
compile "encrypted-config:encrypted-config:0.1.1"
<dependency>
<groupId>encrypted-config</groupId>
<artifactId>encrypted-config</artifactId>
<version>0.1.1</version>
</dependency>
;; To encrypted a given input-text using the secret-key
(str->encrypted input-text secret-key)
;; You will get back the map of
;; {:encrypted-key <key-generated-by-the-system>
;; :encrypted-text <encrypted-text-that-you-can-use>}
(str->decrypted encrypted-text encrypted-key secret-key)
(let [input-text "MyP@ssword!"
secret-key "MySec$tKey@"
{:keys [encrypted-key
encrypted-text]}
(str->encrypted input-text secret-key)
;; Now let's decrypt the text we have just encrypted
decrypted-text (str->decrypted encrypted-text
encrypted-key
secret-key)]
(do
(println (str "FYI: input-text : " input-text))
(println (str "FYI: secret-key : " secret-key))
(println (str "FYI: encrypted-key : " encrypted-key))
(println (str "FYI: encrypted-text : " encrypted-text))))
Your result will be like:
FYI: input-text : MyP@ssword! FYI: secret-key* : MySec$tKey@ FYI: encrypted-key* : b0ed81af1e42b826ccdcabc3fa059d0c FYI: encrypted-text : 3e8a19218245b48c5f546c902c75deb98077d7e2d7030afde9f0b10a8e3a6bb0
So you can safely store the encrypted-text
in the property file and decrypted it back safely.
Copyright © 2017 Burin Choomnuan
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.