Bug 57954 - Unable to read encrypted values from properties file
Summary: Unable to read encrypted values from properties file
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.6.0
Hardware: Other other
: P2 blocker (vote)
Target Milestone: ---
Assignee: Ant Notifications List
Depends on:
Reported: 2015-05-27 10:50 UTC by Peeyush
Modified: 2015-06-11 07:00 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Peeyush 2015-05-27 10:50:27 UTC
I am trying to deploy code on Weblogic server. We have the credentials to deploy on the server in import.properties file. The values of username and password are encrypted using base64 algorithm. But when the file is loaded into the ant script it throws an exception as below:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run (sca-deploy) on project ABC: An Ant BuildException has occured: Unable to load file: java.io.UnsupportedEncodingException: base64 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run (sca-deploy) on project ABC: An Ant BuildException has occured: Unable to load file: java.io.UnsupportedEncodingException: base64

Please let me know what is missed.

We are loading the file as:

<loadproperties srcFile="import.properties" encoding="base64" />
Comment 1 Peeyush 2015-05-27 10:54:50 UTC
import.properties contains below entries: (values are encoded in base64)

Comment 2 Dominique Devienne 2015-05-27 11:21:01 UTC
the encoding attribute is for the whole file, not property values. Load the property file "normally", get the values for username and password, and if you need those decoded from base64, you'll have to do it "manually" or coax Ant into doing it (I suspect it's possible, but convoluted and not straightforward.).

This is not a bug IMHO. --DD
Comment 3 Peeyush 2015-05-27 11:32:26 UTC
Thanks Dominique for the guidance.
But is there any link or blog or document that I can follow to achieve this functionality.

Any help would be appreciated.
Comment 4 Stefan Bodewig 2015-05-27 11:33:56 UTC
In addition to what Dominique said - the encoding attribute expects a charset name supported by the Java classlib, "base64" is not such an encoding name.

Unrelated: do yourself a favor and don't call base64-encoding a string an "encryption".  This is obfuscation at best, since everybody can "decrypt" it easily.  You should be using real crypto if you want to store your passwords safely.
Comment 5 Peeyush 2015-05-27 11:38:36 UTC

so can anyone help me in doing that. I don't want to specify the credentials separately, they should remain in the properties file hidden by some encryption method and when loaded ant can decrypt the values.
Comment 6 Stefan Bodewig 2015-05-27 11:39:06 UTC
To be honest I can't think of a combination of Ant tasks that would base64-decode only the value side of a property file.

I see two approaches:

* a custom PropertyEvaluator that decoded values on the fly

* a custom FilterReader http://ant.apache.org/manual/Types/filterchain.html or string filter for a TokenFilter http://ant.apache.org/manual/Types/filterchain.html#tokenfilter that splits the line, base64-decodes the value part and reassembles the line.

The second one is probably easier to implement and integrate.  Either case it will require you to write your own code in Java, compile it, and make it available to the build process.
Comment 7 Dominique Devienne 2015-05-27 11:59:15 UTC
See also http://stackoverflow.com/questions/10132221/how-do-i-use-base64-encoding-with-loadproperties-in-ant and the link in the one answer, which uses Groovy to script to decrypting within Ant (could probably use another scripting language and leverage the JDK APIs. With a recent enough JDK, the scripting might even be built-in to the JDK).
Comment 8 Peeyush 2015-06-01 13:53:26 UTC

Can someone give me a sample ant file with java code for encryption and decryption of credentials in properties file. The method to encrypt can be any.
Also the blog mentioned in the comments does not work.
Comment 9 Jan Mat 2015-06-11 07:00:08 UTC
If you store encrypted values in a properties file you cant mix encrypted+plain values in one file without additional to specify which values are encrypted.
<property file="">
  <encrypted-values prefix="encrypted"/>
  <encrypted-values match=".*\.md5$"/>

Having different encryption algorithm would encrease that amount of work.

Another approach is having a Decrypt/EncryptFilter, so you could load one value.
<loadfile property="password" srcFile="encrypted">
    <decrypt algorithm="base64"/>