EncryptRequest encryptRequest = new EncryptRequest() .withEncryptionContext(matdesc) .withKeyId(materials.getCustomerMasterKeyId()) .withPlaintext(ByteBuffer.wrap(cek.getEncoded())) .withGeneralProgressListener(req.getGeneralProgressListener()) .withRequestMetricCollector(req.getRequestMetricCollector())
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getKeyId() == null) ? 0 : getKeyId().hashCode()); hashCode = prime * hashCode + ((getPlaintext() == null) ? 0 : getPlaintext().hashCode()); hashCode = prime * hashCode + ((getEncryptionContext() == null) ? 0 : getEncryptionContext().hashCode()); hashCode = prime * hashCode + ((getGrantTokens() == null) ? 0 : getGrantTokens().hashCode()); return hashCode; }
/** * <p> * A list of grant tokens. * </p> * <p> * For more information, see <a * href="http://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#grant_token">Grant Tokens</a> in the * <i>AWS Key Management Service Developer Guide</i>. * </p> * * @param grantTokens * A list of grant tokens.</p> * <p> * For more information, see <a * href="http://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#grant_token">Grant Tokens</a> in * the <i>AWS Key Management Service Developer Guide</i>. * @return Returns a reference to this object so that method calls can be chained together. */ public EncryptRequest withGrantTokens(java.util.Collection<String> grantTokens) { setGrantTokens(grantTokens); return this; }
@Override public DataKey<KmsMasterKey> encryptDataKey(final CryptoAlgorithm algorithm, final Map<String, String> encryptionContext, final DataKey<?> dataKey) { final SecretKey key = dataKey.getKey(); if (!key.getFormat().equals("RAW")) { throw new IllegalArgumentException("Only RAW encoded keys are supported"); } try { final EncryptResult encryptResult = kms_.get().encrypt(updateUserAgent( new EncryptRequest() .withKeyId(id_) .withPlaintext(ByteBuffer.wrap(key.getEncoded())) .withEncryptionContext(encryptionContext) .withGrantTokens(grantTokens_))); final byte[] edk = new byte[encryptResult.getCiphertextBlob().remaining()]; encryptResult.getCiphertextBlob().get(edk); return new DataKey<>(dataKey.getKey(), edk, encryptResult.getKeyId().getBytes(StandardCharsets.UTF_8), this); } catch (final AmazonServiceException asex) { throw new AwsCryptoException(asex); } }
@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 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)); } }
if (getGrantTokens() == null) { this.grantTokens = new java.util.ArrayList<String>(grantTokens.length);
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()); }
if (getGrantTokens() == null) { this.grantTokens = new java.util.ArrayList<String>(grantTokens.length);
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof EncryptRequest == false) return false; EncryptRequest other = (EncryptRequest) obj; if (other.getKeyId() == null ^ this.getKeyId() == null) return false; if (other.getKeyId() != null && other.getKeyId().equals(this.getKeyId()) == false) return false; if (other.getPlaintext() == null ^ this.getPlaintext() == null) return false; if (other.getPlaintext() != null && other.getPlaintext().equals(this.getPlaintext()) == false) return false; if (other.getEncryptionContext() == null ^ this.getEncryptionContext() == null) return false; if (other.getEncryptionContext() != null && other.getEncryptionContext().equals(this.getEncryptionContext()) == false) return false; if (other.getGrantTokens() == null ^ this.getGrantTokens() == null) return false; if (other.getGrantTokens() != null && other.getGrantTokens().equals(this.getGrantTokens()) == false) return false; return true; }
final EncryptRequest encryptRequest = new EncryptRequest() .withEncryptionContext(matdesc) .withKeyId(materials.getCustomerMasterKeyId()) .withPlaintext(ByteBuffer.wrap(cek.getEncoded())); encryptRequest .withGeneralProgressListener(req.getGeneralProgressListener()) .withRequestMetricCollector(req.getRequestMetricCollector()); final EncryptResult encryptResult = kms.encrypt(encryptRequest);
setGrantTokens(new com.amazonaws.internal.SdkInternalList<String>(grantTokens.length));
if (getGrantTokens() == null) { this.grantTokens = new java.util.ArrayList<String>(grantTokens.length);
/** * 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 (getKeyId() != null) sb.append("KeyId: ").append(getKeyId()).append(","); if (getPlaintext() != null) sb.append("Plaintext: ").append("***Sensitive Data Redacted***").append(","); if (getEncryptionContext() != null) sb.append("EncryptionContext: ").append(getEncryptionContext()).append(","); if (getGrantTokens() != null) sb.append("GrantTokens: ").append(getGrantTokens()); sb.append("}"); return sb.toString(); }
EncryptRequest encryptRequest = new EncryptRequest() .withEncryptionContext(matdesc) .withKeyId(materials.getCustomerMasterKeyId()) .withPlaintext(ByteBuffer.wrap(cek.getEncoded())) .withGeneralProgressListener(req.getGeneralProgressListener()) .withRequestMetricCollector(req.getRequestMetricCollector())
/** * <p> * A list of grant tokens. * </p> * <p> * For more information, see <a href= * "http://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#grant_token" * >Grant Tokens</a> in the <i>AWS Key Management Service Developer * Guide</i>. * </p> * <p> * Returns a reference to this object so that method calls can be chained * together. * * @param grantTokens <p> * A list of grant tokens. * </p> * <p> * For more information, see <a href= * "http://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#grant_token" * >Grant Tokens</a> in the <i>AWS Key Management Service * Developer Guide</i>. * </p> * @return A reference to this updated object so that method calls can be * chained together. */ public EncryptRequest withGrantTokens(java.util.Collection<String> grantTokens) { setGrantTokens(grantTokens); return this; }
/** * Marshall the given parameter object. */ public void marshall(EncryptRequest encryptRequest, ProtocolMarshaller protocolMarshaller) { if (encryptRequest == null) { throw new SdkClientException("Invalid argument passed to marshall(...)"); } try { protocolMarshaller.marshall(encryptRequest.getKeyId(), KEYID_BINDING); protocolMarshaller.marshall(encryptRequest.getPlaintext(), PLAINTEXT_BINDING); protocolMarshaller.marshall(encryptRequest.getEncryptionContext(), ENCRYPTIONCONTEXT_BINDING); protocolMarshaller.marshall(encryptRequest.getGrantTokens(), GRANTTOKENS_BINDING); } catch (Exception e) { throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e); } }
final EncryptRequest encryptRequest = new EncryptRequest() .withEncryptionContext(matdesc) .withKeyId(materials.getCustomerMasterKeyId()) .withPlaintext(ByteBuffer.wrap(cek.getEncoded())); encryptRequest .withGeneralProgressListener(req.getGeneralProgressListener()) .withRequestMetricCollector(req.getRequestMetricCollector()); final EncryptResult encryptResult = kms.encrypt(encryptRequest);
/** * <p> * A list of grant tokens. * </p> * <p> * For more information, see <a * href="http://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#grant_token">Grant Tokens</a> in the * <i>AWS Key Management Service Developer Guide</i>. * </p> * * @param grantTokens * A list of grant tokens.</p> * <p> * For more information, see <a * href="http://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#grant_token">Grant Tokens</a> in * the <i>AWS Key Management Service Developer Guide</i>. * @return Returns a reference to this object so that method calls can be chained together. */ public EncryptRequest withGrantTokens(java.util.Collection<String> grantTokens) { setGrantTokens(grantTokens); return this; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getKeyId() == null) ? 0 : getKeyId().hashCode()); hashCode = prime * hashCode + ((getPlaintext() == null) ? 0 : getPlaintext().hashCode()); hashCode = prime * hashCode + ((getEncryptionContext() == null) ? 0 : getEncryptionContext().hashCode()); hashCode = prime * hashCode + ((getGrantTokens() == null) ? 0 : getGrantTokens().hashCode()); return hashCode; }