Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ public static void main(String[] args) throws InterruptedException, IllegalArgum

// Let's create a self-signed certificate valid for 1 year. If the certificate already exists in the key vault,
// then a new version of the certificate is created.
// Subject Alternative Names (SANs) can include emails, DNS names, IP addresses, and URIs.
CertificatePolicy policy = new CertificatePolicy("Self", "CN=SelfSignedJavaPkcs12")
.setSubjectAlternativeNames(new SubjectAlternativeNames().setEmails(Arrays.asList("wow@gmail.com")))
.setSubjectAlternativeNames(new SubjectAlternativeNames()
.setEmails(Arrays.asList("wow@gmail.com"))
.setIpAddresses(Arrays.asList("10.0.0.1", "2001:db8::1"))
.setUniformResourceIdentifiers(Arrays.asList("https://mydomain.com")))
.setKeyReusable(true)
.setKeyType(CertificateKeyType.EC)
.setKeyCurveName(CertificateKeyCurveName.P_256)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public static void main(String[] args) throws InterruptedException, IllegalArgum

System.out.printf("Secret is returned with name %s and value %s \n", bankSecret.getName(), bankSecret.getValue());

// For certificate-backed secrets, we can retrieve the secret value in a different format using outContentType.
// For example, to get the value in PEM format instead of the default PKCS#12 format:
// KeyVaultSecret pemSecret = secretClient.getSecret("MyCertSecret", null, "application/x-pem-file");
Comment on lines +50 to +52
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The outContentType snippet uses a different secret name ("MyCertSecret") than the rest of the sample and is commented out, which makes it harder to follow when reading the sample top-to-bottom. Consider using a clearly named placeholder variable (e.g., CERT_SECRET_NAME) and explicitly noting that this call only works for certificate-backed (PFX) secrets; otherwise the service may reject the request.

Copilot uses AI. Check for mistakes.

// After one year, the bank account is still active, we need to update the expiry time of the secret.
// The update method can be used to update the expiry attribute of the secret. It cannot be used to update the
// value of the secret.
Expand All @@ -63,6 +67,16 @@ public static void main(String[] args) throws InterruptedException, IllegalArgum
.setProperties(new SecretProperties()
.setExpiresOn(OffsetDateTime.now().plusYears(1))));

// For secrets created after June 1, 2025, the service may populate the previous version identifier
// when applicable. This is primarily useful for certificate-backed secrets to track version history,
// and it may be null for other secrets.
KeyVaultSecret latestSecret = secretClient.getSecret("BankAccountPassword");
String previousVersion = latestSecret.getProperties().getPreviousVersion();

if (previousVersion != null) {
System.out.printf("Secret's previous version is %s \n", previousVersion);
}

// The bank account was closed, need to delete its credentials from the key vault.
SyncPoller<DeletedSecret, Void> deletedBankSecretPoller =
secretClient.beginDeleteSecret("BankAccountPassword");
Expand Down
Loading