Search in sources :

Example 1 with KeyOperationAttestation

use of com.google.cloud.kms.v1.KeyOperationAttestation in project java-docs-samples by GoogleCloudPlatform.

the class GetKeyVersionAttestation method getKeyVersionAttestation.

// Get the attestations for a key version
public void getKeyVersionAttestation(String projectId, String locationId, String keyRingId, String keyId, String keyVersionId) throws IOException {
    // safely clean up any remaining background resources.
    try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
        // Build the name from the project, location, key ring, and keyId.
        CryptoKeyVersionName keyVersionName = CryptoKeyVersionName.of(projectId, locationId, keyRingId, keyId, keyVersionId);
        // Get the key version.
        CryptoKeyVersion keyVersion = client.getCryptoKeyVersion(keyVersionName);
        // will be nil.
        if (!keyVersion.hasAttestation()) {
            System.out.println("no attestation");
            return;
        }
        // Print the attestation, base64-encoded.
        KeyOperationAttestation attestation = keyVersion.getAttestation();
        String format = attestation.getFormat().toString();
        byte[] content = attestation.getContent().toByteArray();
        System.out.printf("%s: %s", format, Base64.getEncoder().encodeToString(content));
    }
}
Also used : CryptoKeyVersionName(com.google.cloud.kms.v1.CryptoKeyVersionName) KeyOperationAttestation(com.google.cloud.kms.v1.KeyOperationAttestation) CryptoKeyVersion(com.google.cloud.kms.v1.CryptoKeyVersion) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient)

Example 2 with KeyOperationAttestation

use of com.google.cloud.kms.v1.KeyOperationAttestation in project java-kms by googleapis.

the class GetKeyVersionAttestation method getKeyVersionAttestation.

// Get the attestations for a key version
public void getKeyVersionAttestation(String projectId, String locationId, String keyRingId, String keyId, String keyVersionId) throws IOException {
    // safely clean up any remaining background resources.
    try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
        // Build the name from the project, location, key ring, and keyId.
        CryptoKeyVersionName keyVersionName = CryptoKeyVersionName.of(projectId, locationId, keyRingId, keyId, keyVersionId);
        // Get the key version.
        CryptoKeyVersion keyVersion = client.getCryptoKeyVersion(keyVersionName);
        // will be nil.
        if (!keyVersion.hasAttestation()) {
            System.out.println("no attestation");
            return;
        }
        // Print the attestation, base64-encoded.
        KeyOperationAttestation attestation = keyVersion.getAttestation();
        String format = attestation.getFormat().toString();
        byte[] content = attestation.getContent().toByteArray();
        System.out.printf("%s: %s", format, Base64.getEncoder().encodeToString(content));
    }
}
Also used : CryptoKeyVersionName(com.google.cloud.kms.v1.CryptoKeyVersionName) KeyOperationAttestation(com.google.cloud.kms.v1.KeyOperationAttestation) CryptoKeyVersion(com.google.cloud.kms.v1.CryptoKeyVersion) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient)

Aggregations

CryptoKeyVersion (com.google.cloud.kms.v1.CryptoKeyVersion)2 CryptoKeyVersionName (com.google.cloud.kms.v1.CryptoKeyVersionName)2 KeyManagementServiceClient (com.google.cloud.kms.v1.KeyManagementServiceClient)2 KeyOperationAttestation (com.google.cloud.kms.v1.KeyOperationAttestation)2