use of com.amazonaws.services.kms.model.NotFoundException in project cerberus by Nike-Inc.
the class AuthenticationService method encrypt.
/**
* Encrypts the data provided using KMS based on the provided region and key id.
*
* @param regionName Region where key is located
* @param keyId Key id
* @param data Data to be encrypted
* @return encrypted data
*/
private byte[] encrypt(final String regionName, final String keyId, final byte[] data) {
Region region;
try {
region = Region.getRegion(Regions.fromName(regionName));
} catch (IllegalArgumentException iae) {
throw ApiException.newBuilder().withApiErrors(DefaultApiError.AUTH_IAM_ROLE_AWS_REGION_INVALID).withExceptionCause(iae).build();
}
final AWSKMSClient kmsClient = kmsClientFactory.getClient(region);
try {
final EncryptResult encryptResult = kmsClient.encrypt(new EncryptRequest().withKeyId(keyId).withPlaintext(ByteBuffer.wrap(data)));
return encryptResult.getCiphertextBlob().array();
} catch (NotFoundException | KMSInvalidStateException keyNotUsableException) {
throw new KeyInvalidForAuthException(String.format("Failed to encrypt token using KMS key with id: %s", keyId), keyNotUsableException);
} catch (AmazonClientException ace) {
String msg = String.format("Unexpected error communicating with AWS KMS for region %s.", regionName);
throw ApiException.newBuilder().withApiErrors(CustomApiError.createCustomApiError(DefaultApiError.INTERNAL_SERVER_ERROR, msg)).withExceptionCause(ace).withExceptionMessage(msg).build();
}
}
use of com.amazonaws.services.kms.model.NotFoundException in project di-authentication-api by alphagov.
the class KmsKeyExtension method keyExists.
protected boolean keyExists(String keyAlias) {
try {
var request = new DescribeKeyRequest().withKeyId(keyAlias);
kms.describeKey(request);
return true;
} catch (NotFoundException ignored) {
return false;
}
}
use of com.amazonaws.services.kms.model.NotFoundException in project aws-sdk-android by aws-amplify.
the class NotFoundExceptionUnmarshaller method unmarshall.
@Override
public AmazonServiceException unmarshall(JsonErrorResponse error) throws Exception {
NotFoundException e = (NotFoundException) super.unmarshall(error);
e.setErrorCode("NotFoundException");
return e;
}
Aggregations