本文整理汇总了Java中com.amazonaws.services.kms.model.EncryptRequest类的典型用法代码示例。如果您正苦于以下问题:Java EncryptRequest类的具体用法?Java EncryptRequest怎么用?Java EncryptRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EncryptRequest类属于com.amazonaws.services.kms.model包,在下文中一共展示了EncryptRequest类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: encryptDataKey
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
@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_.encrypt(
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);
}
}
开发者ID:awslabs,项目名称:aws-encryption-sdk-java,代码行数:23,代码来源:KmsMasterKey.java
示例2: generateDataKey
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
@Override
public GenerateDataKeyResult generateDataKey(GenerateDataKeyRequest req) throws AmazonServiceException,
AmazonClientException {
byte[] pt;
if (req.getKeySpec() != null) {
if (req.getKeySpec().contains("256")) {
pt = new byte[32];
} else if (req.getKeySpec().contains("128")) {
pt = new byte[16];
} else {
throw new java.lang.UnsupportedOperationException();
}
} else {
pt = new byte[req.getNumberOfBytes()];
}
rnd.nextBytes(pt);
ByteBuffer ptBuff = ByteBuffer.wrap(pt);
EncryptResult encryptResult = encrypt0(new EncryptRequest().withKeyId(req.getKeyId()).withPlaintext(ptBuff)
.withEncryptionContext(req.getEncryptionContext()));
String arn = retrieveArn(req.getKeyId());
return new GenerateDataKeyResult().withKeyId(arn).withCiphertextBlob(encryptResult.getCiphertextBlob())
.withPlaintext(ptBuff);
}
开发者ID:awslabs,项目名称:aws-encryption-sdk-java,代码行数:24,代码来源:MockKMSClient.java
示例3: encrypt
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
@Override
public Observable<Encrypted> encrypt(VertxContext<Server> vertxContext, byte[] plainBytes) {
SfsVertx sfsVertx = vertxContext.vertx();
Context context = sfsVertx.getOrCreateContext();
return Observable.defer(() -> {
byte[] cloned = Arrays.copyOf(plainBytes, plainBytes.length);
return RxHelper.executeBlocking(context, sfsVertx.getBackgroundPool(), () -> {
try {
EncryptRequest req =
new EncryptRequest()
.withKeyId(keyId)
.withPlaintext(ByteBuffer.wrap(cloned));
ByteBuffer buffer = kms.encrypt(req).getCiphertextBlob();
byte[] b = new byte[buffer.remaining()];
buffer.get(b);
return new Encrypted(b, String.format("xppsaws:%s", keyId));
} finally {
Arrays.fill(cloned, (byte) 0);
}
});
});
}
开发者ID:pitchpoint-solutions,项目名称:sfs,代码行数:23,代码来源:AwsKms.java
示例4: setUp
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
mockKms = mock(AWSKMS.class);
textEncryptor = new KmsTextEncryptor(mockKms, KMS_KEY_ID);
expectedEncryptRequest = new EncryptRequest();
expectedEncryptRequest.setKeyId(KMS_KEY_ID);
expectedEncryptRequest.setPlaintext(wrap(PLAINTEXT.getBytes()));
encryptResult = new EncryptResult();
encryptResult.setCiphertextBlob(wrap(CIPHER_TEXT.getBytes()));
when(mockKms.encrypt(any(EncryptRequest.class))).thenReturn(encryptResult);
expectedDecryptRequest = new DecryptRequest();
expectedDecryptRequest.setCiphertextBlob(wrap(CIPHER_TEXT.getBytes()));
decryptResult = new DecryptResult();
decryptResult.setPlaintext(wrap(PLAINTEXT.getBytes()));
when(mockKms.decrypt(any(DecryptRequest.class))).thenReturn(decryptResult);
}
开发者ID:zalando,项目名称:spring-cloud-config-aws-kms,代码行数:21,代码来源:KmsTextEncryptorTest.java
示例5: generateDataKey
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
@Override
public GenerateDataKeyResult generateDataKey(GenerateDataKeyRequest req)
throws AmazonServiceException, AmazonClientException {
byte[] pt;
if (req.getKeySpec() != null) {
if (req.getKeySpec().contains("256")) {
pt = new byte[32];
} else if (req.getKeySpec().contains("128")) {
pt = new byte[16];
} else {
throw new UnsupportedOperationException();
}
} else {
pt = new byte[req.getNumberOfBytes()];
}
rnd.nextBytes(pt);
ByteBuffer ptBuff = ByteBuffer.wrap(pt);
EncryptResult encryptResult = encrypt(new EncryptRequest().withKeyId(req.getKeyId())
.withPlaintext(ptBuff).withEncryptionContext(req.getEncryptionContext()));
return new GenerateDataKeyResult().withKeyId(req.getKeyId())
.withCiphertextBlob(encryptResult.getCiphertextBlob()).withPlaintext(ptBuff);
}
开发者ID:awslabs,项目名称:aws-dynamodb-encryption-java,代码行数:24,代码来源:FakeKMS.java
示例6: testEncryptDecrypt
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
@Test
public void testEncryptDecrypt() throws Exception {
DecryptResult mockDecryptResult = mock(DecryptResult.class);
EncryptResult mockEncryptResult = mock(EncryptResult.class);
when(mockKms.decrypt(isA(DecryptRequest.class)))
.thenReturn(mockDecryptResult);
when(mockKms.encrypt(isA(EncryptRequest.class)))
.thenReturn(mockEncryptResult);
Aead aead = new AwsKmsAead(mockKms, keyId);
byte[] aad = Random.randBytes(20);
for (int messageSize = 0; messageSize < 75; messageSize++) {
byte[] message = Random.randBytes(messageSize);
when(mockDecryptResult.getPlaintext()).thenReturn(ByteBuffer.wrap(message));
when(mockEncryptResult.getCiphertextBlob()).thenReturn(ByteBuffer.wrap(message));
byte[] ciphertext = aead.encrypt(message, aad);
byte[] decrypted = aead.decrypt(ciphertext, aad);
assertArrayEquals(message, decrypted);
}
}
开发者ID:google,项目名称:tink,代码行数:21,代码来源:AwsKmsAeadTest.java
示例7: testEncrypt_shouldThrowExceptionIfRequestFailed
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
@Test
public void testEncrypt_shouldThrowExceptionIfRequestFailed() throws Exception {
AmazonServiceException exception = mock(AmazonServiceException.class);
when(mockKms.encrypt(isA(EncryptRequest.class)))
.thenThrow(exception);
Aead aead = new AwsKmsAead(mockKms, keyId);
byte[] aad = Random.randBytes(20);
byte[] message = Random.randBytes(20);
try {
aead.encrypt(message, aad);
fail("Expected GeneralSecurityException");
} catch (GeneralSecurityException e) {
// expected.
}
}
开发者ID:google,项目名称:tink,代码行数:17,代码来源:AwsKmsAeadTest.java
示例8: testDecrypt_shouldThrowExceptionIfRequestFailed
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
@Test
public void testDecrypt_shouldThrowExceptionIfRequestFailed() throws Exception {
EncryptResult mockEncryptResult = mock(EncryptResult.class);
when(mockKms.encrypt(isA(EncryptRequest.class)))
.thenReturn(mockEncryptResult);
AmazonServiceException exception = mock(AmazonServiceException.class);
when(mockKms.decrypt(isA(DecryptRequest.class)))
.thenThrow(exception);
Aead aead = new AwsKmsAead(mockKms, keyId);
byte[] aad = Random.randBytes(20);
byte[] message = Random.randBytes(20);
when(mockEncryptResult.getCiphertextBlob()).thenReturn(ByteBuffer.wrap(message));
byte[] ciphertext = aead.encrypt(message, aad);
try {
aead.decrypt(ciphertext, aad);
fail("Expected GeneralSecurityException");
} catch (GeneralSecurityException e) {
// expected.
}
}
开发者ID:google,项目名称:tink,代码行数:22,代码来源:AwsKmsAeadTest.java
示例9: encrypt
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
/**
* 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 (AmazonClientException ace) {
throw ApiException.newBuilder()
.withApiErrors(DefaultApiError.INTERNAL_SERVER_ERROR)
.withExceptionCause(ace)
.withExceptionMessage(
String.format("Unexpected error communicating with AWS KMS for region %s.", regionName))
.build();
}
}
开发者ID:Nike-Inc,项目名称:cerberus-management-service,代码行数:36,代码来源:AuthenticationService.java
示例10: encrypt0
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
private EncryptResult encrypt0(EncryptRequest req) throws AmazonServiceException, AmazonClientException {
final byte[] cipherText = new byte[512];
rnd.nextBytes(cipherText);
DecryptResult dec = new DecryptResult();
dec.withKeyId(req.getKeyId()).withPlaintext(req.getPlaintext().asReadOnlyBuffer());
ByteBuffer ctBuff = ByteBuffer.wrap(cipherText);
results_.put(new DecryptMapKey(ctBuff, req.getEncryptionContext()), dec);
String arn = retrieveArn(req.getKeyId());
return new EncryptResult().withCiphertextBlob(ctBuff).withKeyId(arn);
}
开发者ID:awslabs,项目名称:aws-encryption-sdk-java,代码行数:13,代码来源:MockKMSClient.java
示例11: encrypt
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
/**
* Using the given AWS Key, encrypt the given bytes
*
* @param awsKeyId unique identifier for the customer master key
* @param clearBytes the unencrypted bytes to encrypt
* @return the encrypted bytes
*/
public static byte[] encrypt(String awsKeyId, Map<String, String> encryptionContext, byte[] clearBytes) {
EncryptRequest encryptRequest = new EncryptRequest();
encryptRequest.setKeyId(awsKeyId);
encryptRequest.setPlaintext(ByteBuffer.wrap(clearBytes));
encryptRequest.setEncryptionContext(encryptionContext);
AWSKMSClient client = new AWSKMSClient();
EncryptResult encryptResult = client.encrypt(encryptRequest);
return encryptResult.getCiphertextBlob().array();
}
开发者ID:gravieinc,项目名称:aws-crypto-tools-java,代码行数:19,代码来源:AwsKmsUtil.java
示例12: encrypt
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
@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(ByteBuffer.wrap(Base64.encode(encryptedBytes.array())));
}
}
开发者ID:zalando,项目名称:spring-cloud-config-aws-kms,代码行数:16,代码来源:KmsTextEncryptor.java
示例13: encrypt
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
@Override
public EncryptResult encrypt(EncryptRequest req) throws AmazonServiceException,
AmazonClientException {
final byte[] cipherText = new byte[512];
rnd.nextBytes(cipherText);
DecryptResult dec = new DecryptResult();
dec.withKeyId(req.getKeyId()).withPlaintext(req.getPlaintext().asReadOnlyBuffer());
ByteBuffer ctBuff = ByteBuffer.wrap(cipherText);
results_.put(new DecryptMapKey(ctBuff, req.getEncryptionContext()), dec);
return new EncryptResult().withCiphertextBlob(ctBuff).withKeyId(req.getKeyId());
}
开发者ID:awslabs,项目名称:aws-dynamodb-encryption-java,代码行数:14,代码来源:FakeKMS.java
示例14: encrypt
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
@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);
}
}
开发者ID:google,项目名称:tink,代码行数:15,代码来源:AwsKmsAead.java
示例15: encrypt
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
public EncryptResult encrypt(EncryptRequest request) {
// Default AWS limit was 1200 shared as of Aug 2017
return execute("KmsEncryptDecrypt", "KmsEncrypt", () -> client.encrypt(request));
}
开发者ID:Nike-Inc,项目名称:cerberus-management-service,代码行数:5,代码来源:HystrixKmsClient.java
示例16: testGrantTokenPassthrough_usingMKsetCall
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
@Test
public void testGrantTokenPassthrough_usingMKsetCall() throws Exception {
MockKMSClient client = spy(new MockKMSClient());
RegionalClientSupplier supplier = mock(RegionalClientSupplier.class);
when(supplier.getClient(any())).thenReturn(client);
String key1 = client.createKey().getKeyMetadata().getArn();
String key2 = client.createKey().getKeyMetadata().getArn();
KmsMasterKeyProvider mkp0 = KmsMasterKeyProvider.builder()
.withDefaultRegion("us-west-2")
.withCustomClientFactory(supplier)
.withKeysForEncryption(key1, key2)
.build();
KmsMasterKey mk1 = mkp0.getMasterKey(key1);
KmsMasterKey mk2 = mkp0.getMasterKey(key2);
mk1.setGrantTokens(singletonList("foo"));
mk2.setGrantTokens(singletonList("foo"));
MasterKeyProvider<?> mkp = buildMultiProvider(mk1, mk2);
byte[] ciphertext = new AwsCrypto().encryptData(mkp, new byte[0]).getResult();
ArgumentCaptor<GenerateDataKeyRequest> gdkr = ArgumentCaptor.forClass(GenerateDataKeyRequest.class);
verify(client, times(1)).generateDataKey(gdkr.capture());
assertEquals(key1, gdkr.getValue().getKeyId());
assertEquals(1, gdkr.getValue().getGrantTokens().size());
assertEquals("foo", gdkr.getValue().getGrantTokens().get(0));
ArgumentCaptor<EncryptRequest> er = ArgumentCaptor.forClass(EncryptRequest.class);
verify(client, times(1)).encrypt(er.capture());
assertEquals(key2, er.getValue().getKeyId());
assertEquals(1, er.getValue().getGrantTokens().size());
assertEquals("foo", er.getValue().getGrantTokens().get(0));
new AwsCrypto().decryptData(mkp, ciphertext);
ArgumentCaptor<DecryptRequest> decrypt = ArgumentCaptor.forClass(DecryptRequest.class);
verify(client, times(1)).decrypt(decrypt.capture());
assertEquals(1, decrypt.getValue().getGrantTokens().size());
assertEquals("foo", decrypt.getValue().getGrantTokens().get(0));
verify(supplier, atLeastOnce()).getClient("us-west-2");
verifyNoMoreInteractions(supplier);
}
开发者ID:awslabs,项目名称:aws-encryption-sdk-java,代码行数:51,代码来源:KMSProviderBuilderMockTests.java
示例17: testGrantTokenPassthrough_usingMKPWithers
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
@Test
public void testGrantTokenPassthrough_usingMKPWithers() throws Exception {
MockKMSClient client = spy(new MockKMSClient());
RegionalClientSupplier supplier = mock(RegionalClientSupplier.class);
when(supplier.getClient(any())).thenReturn(client);
String key1 = client.createKey().getKeyMetadata().getArn();
String key2 = client.createKey().getKeyMetadata().getArn();
KmsMasterKeyProvider mkp0 = KmsMasterKeyProvider.builder()
.withDefaultRegion("us-west-2")
.withCustomClientFactory(supplier)
.withKeysForEncryption(key1, key2)
.build();
MasterKeyProvider<?> mkp = mkp0.withGrantTokens("foo");
byte[] ciphertext = new AwsCrypto().encryptData(mkp, new byte[0]).getResult();
ArgumentCaptor<GenerateDataKeyRequest> gdkr = ArgumentCaptor.forClass(GenerateDataKeyRequest.class);
verify(client, times(1)).generateDataKey(gdkr.capture());
assertEquals(key1, gdkr.getValue().getKeyId());
assertEquals(1, gdkr.getValue().getGrantTokens().size());
assertEquals("foo", gdkr.getValue().getGrantTokens().get(0));
ArgumentCaptor<EncryptRequest> er = ArgumentCaptor.forClass(EncryptRequest.class);
verify(client, times(1)).encrypt(er.capture());
assertEquals(key2, er.getValue().getKeyId());
assertEquals(1, er.getValue().getGrantTokens().size());
assertEquals("foo", er.getValue().getGrantTokens().get(0));
mkp = mkp0.withGrantTokens(Arrays.asList("bar"));
new AwsCrypto().decryptData(mkp, ciphertext);
ArgumentCaptor<DecryptRequest> decrypt = ArgumentCaptor.forClass(DecryptRequest.class);
verify(client, times(1)).decrypt(decrypt.capture());
assertEquals(1, decrypt.getValue().getGrantTokens().size());
assertEquals("bar", decrypt.getValue().getGrantTokens().get(0));
verify(supplier, atLeastOnce()).getClient("us-west-2");
verifyNoMoreInteractions(supplier);
}
开发者ID:awslabs,项目名称:aws-encryption-sdk-java,代码行数:48,代码来源:KMSProviderBuilderMockTests.java
示例18: encrypt
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
@Override
public EncryptResult encrypt(EncryptRequest req) throws AmazonServiceException, AmazonClientException {
// We internally delegate to encrypt, so as to avoid mockito detecting extra calls to encrypt when spying on the
// MockKMSClient, we put the real logic into a separate function.
return encrypt0(req);
}
开发者ID:awslabs,项目名称:aws-encryption-sdk-java,代码行数:7,代码来源:MockKMSClient.java
示例19: kmsEncrypt
import com.amazonaws.services.kms.model.EncryptRequest; //导入依赖的package包/类
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());
}
开发者ID:treasure-data,项目名称:digdag,代码行数:7,代码来源:EmrOperatorFactory.java
注:本文中的com.amazonaws.services.kms.model.EncryptRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论