com.amazonaws.services.kms.model.GenerateRandomRequest Java Examples
The following examples show how to use
com.amazonaws.services.kms.model.GenerateRandomRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractFernetKeyRotator.java From fernet-java8 with Apache License 2.0 | 6 votes |
/** * This seeds the random number generator using KMS if and only it hasn't already been seeded. * * This requires the permission: <code>kms:GenerateRandom</code> */ protected void seed() { if (!seeded.get()) { synchronized (random) { if (!seeded.get()) { getLogger().debug("Seeding random number generator"); final GenerateRandomRequest request = new GenerateRandomRequest(); request.setNumberOfBytes(512); final GenerateRandomResult result = getKms().generateRandom(request); final ByteBuffer randomBytes = result.getPlaintext(); final byte[] bytes = new byte[randomBytes.remaining()]; randomBytes.get(bytes); random.setSeed(bytes); seeded.set(true); getLogger().debug("Seeded random number generator"); } } } }
Example #2
Source File: AbstractFernetKeyRotatorTest.java From fernet-java8 with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { initMocks(this); final GenerateRandomResult randomResult = mock(GenerateRandomResult.class); given(randomResult.getPlaintext()).willReturn(ByteBuffer.allocate(1024)); given(kms.generateRandom(any(GenerateRandomRequest.class))).willReturn(randomResult); rotator = new AbstractFernetKeyRotator(mapper, secretsManager, kms, random) { protected void testSecret(String secretId, String clientRequestToken) { } protected void createSecret(String secretId, String clientRequestToken) { getRandom().nextLong(); } }; rotator = spy(rotator); }
Example #3
Source File: AbstractFernetKeyRotatorTest.java From fernet-java8 with Apache License 2.0 | 6 votes |
@Test public final void verifySeedOnlyRunsOnce() { // given final GenerateRandomResult randomResult = new GenerateRandomResult(); final byte[] bytes = new byte[512]; Arrays.fill(bytes, (byte)17); randomResult.setPlaintext(ByteBuffer.wrap(bytes)); given(kms.generateRandom(any(GenerateRandomRequest.class))).willReturn(randomResult); // when rotator.seed(); rotator.seed(); // then verify(random, times(1)).setSeed(bytes); }
Example #4
Source File: KmsKeyFactory.java From aws-athena-query-federation with Apache License 2.0 | 5 votes |
/** * @return A key that satisfies the specification defined in BlockCrypto */ public EncryptionKey create() { GenerateDataKeyResult dataKeyResult = kmsClient.generateDataKey( new GenerateDataKeyRequest() .withKeyId(masterKeyId) .withKeySpec(DataKeySpec.AES_128)); GenerateRandomRequest randomRequest = new GenerateRandomRequest() .withNumberOfBytes(AesGcmBlockCrypto.NONCE_BYTES); GenerateRandomResult randomResult = kmsClient.generateRandom(randomRequest); return new EncryptionKey(dataKeyResult.getPlaintext().array(), randomResult.getPlaintext().array()); }
Example #5
Source File: MultiFernetKeyRotatorTest.java From fernet-java8 with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { initMocks(this); rotator.setMaxActiveKeys(2); final GenerateRandomResult value = mock(GenerateRandomResult.class); given(value.getPlaintext()).willReturn(ByteBuffer.allocate(1024)); given(kms.generateRandom(any(GenerateRandomRequest.class))).willReturn(value); }
Example #6
Source File: KMSRandomGenerator.java From strongbox with Apache License 2.0 | 4 votes |
public byte[] generateRandom(Integer numberOfBytes) { GenerateRandomRequest request = new GenerateRandomRequest(); request.withNumberOfBytes(numberOfBytes); GenerateRandomResult result = client.generateRandom(request); return result.getPlaintext().array(); }
Example #7
Source File: MockKMSClient.java From aws-encryption-sdk-java with Apache License 2.0 | 4 votes |
@Override public GenerateRandomResult generateRandom(GenerateRandomRequest arg0) throws AmazonServiceException, AmazonClientException { throw new java.lang.UnsupportedOperationException(); }