packagecom.example.app;importcom.infisical.sdk.InfisicalClient;importcom.infisical.sdk.schema.*;publicclassExample{publicstaticvoidmain(String[] args){// Create a new Infisical ClientClientSettings settings =newClientSettings(); settings.setClientID("MACHINE_IDENTITY_CLIENT_ID"); settings.setClientSecret("MACHINE_IDENTITY_CLIENT_SECRET"); settings.setCacheTTL(Long.valueOf(300));// 300 seconds, 5 minutesInfisicalClient client =newInfisicalClient(settings);// Create the options for fetching the secretGetSecretOptions options =newGetSecretOptions(); options.setSecretName("TEST"); options.setEnvironment("dev"); options.setProjectID("PROJECT_ID");// Fetch the sercret with the provided optionsGetSecretResponseSecret secret = client.getSecret(options);// Print the valueSystem.out.println(secret.getSecretValue());// Important to avoid memory leaks!// If you intend to use the client throughout your entire application, you can omit this line. client.close();}}
This example demonstrates how to use the Infisical Java SDK in a Java application. The application retrieves a secret named TEST from the dev environment of the PROJECT_ID project.
We do not recommend hardcoding your Machine Identity Tokens. Setting it as an environment variable would be best.
The Infisical Java SDK is hosted on the GitHub Packages Apache Maven registry. Because of this you need to configure your environment properly so it’s able to pull dependencies from the GitHub registry. Please check this guide from GitHub on how to achieve this.
Our package is located here. Please follow the installation guide on the page.
To reduce the number of API requests, the SDK temporarily stores secrets it retrieves. By default, a secret remains cached for 5 minutes after it’s first fetched. Each time it’s fetched again, this 5-minute timer resets. You can adjust this caching duration by setting the “cacheTTL” option when creating the client.
tag (getTag()) (string): A base64-encoded, 128-bit authentication tag.
iv (getIv()) (string): A base64-encoded, 96-bit initialization vector.
ciphertext (getCipherText()) (string): A base64-encoded, encrypted ciphertext.