use of com.aliyuncs.kms.model.v20160120.DecryptResponse in project gapic-generator-java by googleapis.
the class SyncDecryptCryptokeynameBytestring method syncDecryptCryptokeynameBytestring.
public static void syncDecryptCryptokeynameBytestring() throws Exception {
// It may require modifications to work in your environment.
try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
CryptoKeyName name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
ByteString ciphertext = ByteString.EMPTY;
DecryptResponse response = keyManagementServiceClient.decrypt(name, ciphertext);
}
}
use of com.aliyuncs.kms.model.v20160120.DecryptResponse in project gapic-generator-java by googleapis.
the class SyncDecryptStringBytestring method syncDecryptStringBytestring.
public static void syncDecryptStringBytestring() throws Exception {
// It may require modifications to work in your environment.
try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
String name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString();
ByteString ciphertext = ByteString.EMPTY;
DecryptResponse response = keyManagementServiceClient.decrypt(name, ciphertext);
}
}
use of com.aliyuncs.kms.model.v20160120.DecryptResponse in project gcp-ingestion by mozilla.
the class KeyStore method loadAllKeys.
private void loadAllKeys() throws IOException {
final Map<String, PrivateKey> tempKeys = new HashMap<>();
Schema schema;
try {
byte[] data = Resources.toByteArray(Resources.getResource("keystore-metadata.schema.json"));
schema = JSONSchemaStore.readSchema(data);
} catch (IOException e) {
throw new IOException("Error reading keystore metadata schema file", e);
}
// required to validate Jackson objects
JsonValidator validator = new JsonValidator();
ArrayNode metadata;
try (InputStream inputStream = BeamFileInputStream.open(this.metadataLocation)) {
byte[] data = IOUtils.toByteArray(inputStream);
metadata = Json.readArrayNode(data);
validator.validate(schema, metadata);
} catch (IOException e) {
throw new IOException("Error reading keystore metadata schema.", e);
}
for (JsonNode element : metadata) {
String privateKeyId = element.get("private_key_id").textValue();
String privateKeyUri = element.get("private_key_uri").textValue();
String kmsResourceId = element.get("kms_resource_id").textValue();
try (InputStream inputStream = BeamFileInputStream.open(privateKeyUri)) {
byte[] keyData = IOUtils.toByteArray(inputStream);
PublicJsonWebKey key;
if (kmsEnabled) {
try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
DecryptResponse response = client.decrypt(kmsResourceId, ByteString.copyFrom(keyData));
key = PublicJsonWebKey.Factory.newPublicJwk(response.getPlaintext().toStringUtf8());
}
} else {
key = PublicJsonWebKey.Factory.newPublicJwk(new String(keyData, StandardCharsets.UTF_8));
}
tempKeys.put(privateKeyId, key.getPrivateKey());
} catch (IOException e) {
throw new IOException("Error reading key specified by metadata.", e);
} catch (JoseException e) {
throw new RuntimeException(e);
}
}
keys = tempKeys;
}
Aggregations