This project provides a minimal Java wrapper around the Windows Data Protection API with a permissive license.
In your Maven pom, add the following as a dependency:
<dependency>
<groupId>com.tasktop</groupId>
<artifactId>wdpapi</artifactId>
<version>0.0.7</version>
</dependency>
// at least once in your application
WindowsDataProtectionLoader.loadLibrary();
// protect some data
byte[] dataToProtect = "some super secret data".getBytes(StandardCharsets.UTF_8);
byte[] entropy = "some entropy".getBytes(StandardCharsets.UTF_8);
byte[] protectedData = WindowsDataProtection.encrypt(dataToProtect, entropy, true);
// ... later
byte[] unprotectedData = WindowsDataProtection.decrypt(protectedData, entropy);
String originalSecret = new String(unprotectedData, StandardCharsets.UTF_8);
This library loads native code in the form of a Windows DLL.
DLL loading is first attempted using the JNI path. If the DLL is not found on the JNI path, it's extracted from the jar to a local temporary folder and loaded from there. To avoid having the DLL extracted to a temporary folder, manually extract the DLL from the jar file to the desired location on your JNI path and then use the library.
From the commandline:
mvn clean package
Due to the platform-dependent nature of the build, releases must be done from a Windows machine.
Note that build will fail if sources are on a shared folder; if necessary, copy Git repository to a drive such as C:
From the Windows command-line:
mvn -Possrh -Psign -DpushChanges=false -DlocalCheckout=true -Darguments=-Dgpg.passphrase=thesecret release:clean release:prepare
mvn -Possrh -Psign -DpushChanges=false -DlocalCheckout=true -Darguments=-Dgpg.passphrase=thesecret release:perform
Then push changes:
git push
Search for the staging repository, close and relase it: https://oss.sonatype.org/#stagingRepositories
Copyright (c) 2017 Tasktop Technologies
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.