List of usage examples for org.apache.commons.lang3 RandomUtils nextBytes
public static byte[] nextBytes(final int count)
Creates an array of random bytes.
From source file:mb.impostor.bytearray.RandByteArray.java
public byte[] randDataGen(String type, int count) { byte[] randbuf; if (type.compareToIgnoreCase("NRandom") == 0) { randbuf = RandomUtils.nextBytes(new Random().nextInt(count)); return randbuf; } else if (type.compareToIgnoreCase("Random") == 0) { randbuf = RandomUtils.nextBytes(count); return randbuf; } else if (type.compareToIgnoreCase("RandString") == 0) { String s = RandomStringUtils.randomAlphanumeric(count); return s.getBytes(); } else {/* w w w . ja v a 2 s. co m*/ return null; } }
From source file:ServerMultipart.java
private static void multipartUpload(ServerSideMultipartManager multipart) { String uploadObject = "/" + mantaUsername + "/stor/multipart"; // We catch network errors and handle them here try {/* ww w .j av a2 s.c o m*/ ServerSideMultipartUpload upload = multipart.initiateUpload(uploadObject); MantaMultipartUploadPart part1 = multipart.uploadPart(upload, 1, RandomUtils.nextBytes(5242880)); MantaMultipartUploadPart part2 = multipart.uploadPart(upload, 2, RandomUtils.nextBytes(1000000)); // Complete the process by instructing Manta to assemble the final object from its parts MantaMultipartUploadTuple[] parts = new MantaMultipartUploadTuple[] { part1, part2 }; Stream<MantaMultipartUploadTuple> partsStream = Arrays.stream(parts); multipart.complete(upload, partsStream); System.out.println(uploadObject + " is now assembled!"); } catch (IOException e) { // This catch block is for general network failures // For example, ServerSideMultipartUpload.initiateUpload can throw an IOException ContextedRuntimeException exception = new ContextedRuntimeException( "A network error occurred when doing a multipart upload to Manta."); exception.setContextValue("path", uploadObject); throw exception; } }
From source file:cherry.goods.crypto.NullCryptoTest.java
@Test public void testEncodeDecode() { NullCrypto crypto = new NullCrypto(); for (int i = 0; i < 100; i++) { byte[] plain = RandomUtils.nextBytes(1024); byte[] enc = crypto.encrypt(plain); assertThat(enc, is(plain));/*w w w.j av a2 s. c om*/ byte[] dec = crypto.decrypt(enc); assertThat(dec, is(enc)); } }
From source file:cherry.goods.crypto.NullSignatureTest.java
@Test public void testSignVerify() { NullSignature signature = new NullSignature(); for (int i = 0; i < 100; i++) { byte[] plain = RandomUtils.nextBytes(1024); byte[] signed = signature.sign(plain); assertThat(signed, is(plain));//w w w .j a v a 2s . c o m assertTrue(signature.verify(plain, signed)); } }
From source file:ch.cyberduck.core.io.FileBufferTest.java
@Test public void testTruncate() throws Exception { final FileBuffer buffer = new FileBuffer(); assertEquals(0L, buffer.length(), 0L); final byte[] chunk = RandomUtils.nextBytes(100); buffer.write(chunk, 0L);//from ww w . ja va2 s . c o m assertEquals(100L, buffer.length(), 0L); buffer.truncate(1L); assertEquals(1L, buffer.length(), 0L); final byte[] read = new byte[1]; assertEquals(1, buffer.read(read, 0L)); assertEquals(chunk[0], read[0]); assertEquals(1L, buffer.length(), 0L); }
From source file:cherry.goods.crypto.AESDeterministicCryptoTest.java
@Test public void testDefault() throws Exception { AESDeterministicCrypto crypto = new AESDeterministicCrypto(); crypto.setSecretKeyBytes(RandomUtils.nextBytes(16)); crypto.setInitVectorBytes(RandomUtils.nextBytes(16)); for (int i = 0; i < 100; i++) { byte[] plain = RandomUtils.nextBytes(1024); byte[] enc = crypto.encrypt(plain); byte[] dec = crypto.decrypt(enc); assertThat(dec, is(plain));/* w ww . j a v a 2 s . c o m*/ } }
From source file:cherry.foundation.crypto.AESCryptoSupportTest.java
@Test public void testDefault() throws Exception { AESCryptoSupport crypto = new AESCryptoSupport(); crypto.setSecretKeyResource(new InMemoryResource(RandomUtils.nextBytes(16))); crypto.afterPropertiesSet();// w w w .jav a 2 s . c o m for (int i = 0; i < 100; i++) { byte[] plain = RandomUtils.nextBytes(1024); byte[] enc = crypto.encrypt(plain); byte[] dec = crypto.decrypt(enc); assertThat(dec, is(plain)); } }
From source file:cherry.foundation.crypto.RSASignatureSupportTest.java
@Test public void testSignVerify() throws Exception { RSASignatureSupport impl = createCrypto(); for (int i = 0; i < 100; i++) { byte[] plain = RandomUtils.nextBytes(245); byte[] signed = impl.sign(plain); assertNotEquals(plain, signed);/*from w ww . j a v a2 s .com*/ assertTrue(impl.verify(plain, signed)); } }
From source file:cherry.goods.crypto.AESCryptoTest.java
@Test public void testDefault() throws Exception { AESCrypto crypto = new AESCrypto(); crypto.setSecretKeyBytes(RandomUtils.nextBytes(16)); for (int i = 0; i < 100; i++) { byte[] plain = RandomUtils.nextBytes(1024); byte[] enc = crypto.encrypt(plain); byte[] dec = crypto.decrypt(enc); assertThat(dec, is(plain));/*ww w. j a va 2s .c om*/ } }
From source file:cherry.foundation.crypto.AESDeterministicCryptoSupportTest.java
@Test public void testDefault() throws Exception { AESDeterministicCryptoSupport crypto = new AESDeterministicCryptoSupport(); crypto.setSecretKeyResource(new InMemoryResource(RandomUtils.nextBytes(16))); crypto.setInitVectorResource(new InMemoryResource(RandomUtils.nextBytes(16))); crypto.afterPropertiesSet();/*from ww w . j a v a 2 s.c o m*/ for (int i = 0; i < 100; i++) { byte[] plain = RandomUtils.nextBytes(1024); byte[] enc = crypto.encrypt(plain); byte[] dec = crypto.decrypt(enc); assertThat(dec, is(plain)); } }