dotenvx-java
星标1
分支0
更新时间2026年3月5日 09:30
Dotenvx Java SDK - decrypt your .env and properties files, encrypt JSON fields etc.
安装
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
SKILL.md
readonly菜单
Dotenvx Java SDK - decrypt your .env and properties files, encrypt JSON fields etc.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | dotenvx-java |
| description | Dotenvx Java SDK - decrypt your .env and properties files, encrypt JSON fields etc. |
Add the following dependency to your pom.xml:
<dependency>
<groupId>org.mvnsearch</groupId>
<artifactId>dotenvx-java</artifactId>
<version>0.2.4</version>
</dependency>
And use Dotenvx.load() to .env file in your Java application:
import io.github.cdimascio.dotenv.Dotenv;
import io.github.cdimascio.dotenv.Dotenvx;
Dotenv dotenv = Dotenvx.load();
final String hello = dotenv.get("HELLO");
Tips: you can use Dotenvx.configure() to customize the loading of the .env file and private key.
If you want to use a properties file, please use DotenvxPropertiesBuilder, example:
@Test
public void testLoadProperties() {
final Properties properties = new DotenvxPropertiesBuilder().filename("classpath:application.properties").load();
System.out.println(properties.get("hello"));
}
dotenvx-java loads private key from the following sources in order:
$HOME/.dotenvx/.env.keys.jsonDOTENV_PRIVATE_KEY environment variable.env.keys file in working directory$HOME/.env.keys fileYou can integrate Jackson with Dotenvx to protect some sensitive fields, such as SSN, email or phone number.
ObjectMapper getDotenvxObjectMapper() {
SimpleModule simpleModule = new SimpleModule();
simpleModule.addSerializer(new DotenvxGlobalJsonSerializer(publicKey));
return JsonMapper.builder().addModules(simpleModule).build();
}
@Test
public void testJsonSerialize() throws IOException {
Map<String, String> info = new HashMap<>();
info.put("email", "private:demo@example.com");
info.put("nick", "Jackie");
final String jsonText = objectMapper.writeValueAsString(info);
System.out.println(jsonText);
}
If a text value prefixed with private:, and the value will be encrypted.