@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getCiphertextBlob() == null) ? 0 : getCiphertextBlob().hashCode()); hashCode = prime * hashCode + ((getKeyId() == null) ? 0 : getKeyId().hashCode()); return hashCode; }
public EncryptResult unmarshall(JsonUnmarshallerContext context) throws Exception { EncryptResult encryptResult = new EncryptResult(); if (context.testExpression("CiphertextBlob", targetDepth)) { context.nextToken(); encryptResult.setCiphertextBlob(context.getUnmarshaller(java.nio.ByteBuffer.class).unmarshall(context)); encryptResult.setKeyId(context.getUnmarshaller(String.class).unmarshall(context));
byte[] keyBlob = copyAllBytesFrom(encryptResult.getCiphertextBlob()); return new KMSSecuredCEK(keyBlob, matdesc); } else {
/** * <p> * The ID of the key used during encryption. * </p> * * @param keyId * The ID of the key used during encryption. * @return Returns a reference to this object so that method calls can be chained together. */ public EncryptResult withKeyId(String keyId) { setKeyId(keyId); return this; }
/** * <p> * The encrypted plaintext. When you use the HTTP API or the AWS CLI, the value is Base64-encdoded. Otherwise, it is * not encoded. * </p> * <p> * The AWS SDK for Java performs a Base64 encoding on this field before sending this request to the AWS service. * Users of the SDK should not perform Base64 encoding on this field. * </p> * <p> * Warning: ByteBuffers returned by the SDK are mutable. Changes to the content or position of the byte buffer will * be seen by all objects that have a reference to this object. It is recommended to call ByteBuffer.duplicate() or * ByteBuffer.asReadOnlyBuffer() before using or reading from the buffer. This behavior will be changed in a future * major version of the SDK. * </p> * * @param ciphertextBlob * The encrypted plaintext. When you use the HTTP API or the AWS CLI, the value is Base64-encdoded. * Otherwise, it is not encoded. * @return Returns a reference to this object so that method calls can be chained together. */ public EncryptResult withCiphertextBlob(java.nio.ByteBuffer ciphertextBlob) { setCiphertextBlob(ciphertextBlob); return this; }
.withRequestMetricCollector(req.getRequestMetricCollector()); final EncryptResult encryptResult = kms.encrypt(encryptRequest); final byte[] keyBlob = copyAllBytesFrom(encryptResult.getCiphertextBlob()); return new KMSSecuredCEK(keyBlob, matdesc); } else {
/** * <p> * The ID of the key used during encryption. * </p> * * @param keyId * The ID of the key used during encryption. * @return Returns a reference to this object so that method calls can be chained together. */ public EncryptResult withKeyId(String keyId) { setKeyId(keyId); return this; }
/** * <p> * The encrypted plaintext. When you use the HTTP API or the AWS CLI, the value is Base64-encdoded. Otherwise, it is * not encoded. * </p> * <p> * The AWS SDK for Java performs a Base64 encoding on this field before sending this request to the AWS service. * Users of the SDK should not perform Base64 encoding on this field. * </p> * <p> * Warning: ByteBuffers returned by the SDK are mutable. Changes to the content or position of the byte buffer will * be seen by all objects that have a reference to this object. It is recommended to call ByteBuffer.duplicate() or * ByteBuffer.asReadOnlyBuffer() before using or reading from the buffer. This behavior will be changed in a future * major version of the SDK. * </p> * * @param ciphertextBlob * The encrypted plaintext. When you use the HTTP API or the AWS CLI, the value is Base64-encdoded. * Otherwise, it is not encoded. * @return Returns a reference to this object so that method calls can be chained together. */ public EncryptResult withCiphertextBlob(java.nio.ByteBuffer ciphertextBlob) { setCiphertextBlob(ciphertextBlob); return this; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof EncryptResult == false) return false; EncryptResult other = (EncryptResult) obj; if (other.getCiphertextBlob() == null ^ this.getCiphertextBlob() == null) return false; if (other.getCiphertextBlob() != null && other.getCiphertextBlob().equals(this.getCiphertextBlob()) == false) return false; if (other.getKeyId() == null ^ this.getKeyId() == null) return false; if (other.getKeyId() != null && other.getKeyId().equals(this.getKeyId()) == false) return false; return true; }
public EncryptResult unmarshall(JsonUnmarshallerContext context) throws Exception { EncryptResult encryptResult = new EncryptResult(); AwsJsonReader reader = context.getReader(); reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("CiphertextBlob")) { encryptResult.setCiphertextBlob(ByteBufferJsonUnmarshaller.getInstance() .unmarshall(context)); } else if (name.equals("KeyId")) { encryptResult.setKeyId(StringJsonUnmarshaller.getInstance() .unmarshall(context)); } else { reader.skipValue(); } } reader.endObject(); return encryptResult; }
@Override public String encrypt(final String text) { Assert.hasText(kmsKeyId, "kmsKeyId must not be blank"); if (text == null || text.isEmpty()) { return EMPTY_STRING; } else { final EncryptRequest encryptRequest = new EncryptRequest().withKeyId(kmsKeyId) // .withPlaintext(ByteBuffer.wrap(text.getBytes())); final ByteBuffer encryptedBytes = kms.encrypt(encryptRequest).getCiphertextBlob(); return extractString(encryptedBytes, new KmsTextEncryptorOptions(OutputMode.BASE64)); } }
/** * <p> * The ID of the key used during encryption. * </p> * * @param keyId * The ID of the key used during encryption. * @return Returns a reference to this object so that method calls can be chained together. */ public EncryptResult withKeyId(String keyId) { setKeyId(keyId); return this; }
/** * <p> * The encrypted plaintext. When you use the HTTP API or the AWS CLI, the value is Base64-encoded. Otherwise, it is * not encoded. * </p> * <p> * The AWS SDK for Java performs a Base64 encoding on this field before sending this request to the AWS service. * Users of the SDK should not perform Base64 encoding on this field. * </p> * <p> * Warning: ByteBuffers returned by the SDK are mutable. Changes to the content or position of the byte buffer will * be seen by all objects that have a reference to this object. It is recommended to call ByteBuffer.duplicate() or * ByteBuffer.asReadOnlyBuffer() before using or reading from the buffer. This behavior will be changed in a future * major version of the SDK. * </p> * * @param ciphertextBlob * The encrypted plaintext. When you use the HTTP API or the AWS CLI, the value is Base64-encoded. Otherwise, * it is not encoded. * @return Returns a reference to this object so that method calls can be chained together. */ public EncryptResult withCiphertextBlob(java.nio.ByteBuffer ciphertextBlob) { setCiphertextBlob(ciphertextBlob); return this; }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getCiphertextBlob() != null) sb.append("CiphertextBlob: ").append(getCiphertextBlob()).append(","); if (getKeyId() != null) sb.append("KeyId: ").append(getKeyId()); sb.append("}"); return sb.toString(); }
public EncryptResult unmarshall(JsonUnmarshallerContext context) throws Exception { EncryptResult encryptResult = new EncryptResult(); AwsJsonReader reader = context.getReader(); reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("CiphertextBlob")) { encryptResult.setCiphertextBlob(ByteBufferJsonUnmarshaller.getInstance() .unmarshall(context)); } else if (name.equals("KeyId")) { encryptResult.setKeyId(StringJsonUnmarshaller.getInstance() .unmarshall(context)); } else { reader.skipValue(); } } reader.endObject(); return encryptResult; }
@Override public byte[] encrypt(final byte[] plaintext, final byte[] associatedData) throws GeneralSecurityException { try { EncryptRequest req = new EncryptRequest().withKeyId(keyArn).withPlaintext(ByteBuffer.wrap(plaintext)); if (associatedData != null && associatedData.length != 0) { req = req.addEncryptionContextEntry("associatedData", BinaryUtils.toHex(associatedData)); } return kmsClient.encrypt(req).getCiphertextBlob().array(); } catch (AmazonServiceException e) { throw new GeneralSecurityException("encryption failed", e); } }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getCiphertextBlob() == null) ? 0 : getCiphertextBlob().hashCode()); hashCode = prime * hashCode + ((getKeyId() == null) ? 0 : getKeyId().hashCode()); return hashCode; }
public EncryptResult unmarshall(JsonUnmarshallerContext context) throws Exception { EncryptResult encryptResult = new EncryptResult(); AwsJsonReader reader = context.getReader(); reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("CiphertextBlob")) { encryptResult.setCiphertextBlob(ByteBufferJsonUnmarshaller.getInstance() .unmarshall(context)); } else if (name.equals("KeyId")) { encryptResult.setKeyId(StringJsonUnmarshaller.getInstance() .unmarshall(context)); } else { reader.skipValue(); } } reader.endObject(); return encryptResult; }
private String kmsEncrypt(String value) { String kmsKeyId = context.getSecrets().getSecret("aws.emr.kms_key_id"); EncryptResult result = kms.encrypt(new EncryptRequest().withKeyId(kmsKeyId).withPlaintext(UTF_8.encode(value))); return base64(result.getCiphertextBlob()); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof EncryptResult == false) return false; EncryptResult other = (EncryptResult) obj; if (other.getCiphertextBlob() == null ^ this.getCiphertextBlob() == null) return false; if (other.getCiphertextBlob() != null && other.getCiphertextBlob().equals(this.getCiphertextBlob()) == false) return false; if (other.getKeyId() == null ^ this.getKeyId() == null) return false; if (other.getKeyId() != null && other.getKeyId().equals(this.getKeyId()) == false) return false; return true; } }