HADOOP-10713. Refactor CryptoCodec#generateSecureRandom to take a byte[]. (wang via yliu)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/fs-encryption@1604537 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
97583dbb0a
commit
f43f0999d9
@ -25,6 +25,9 @@ fs-encryption (Unreleased)
|
|||||||
HADOOP-10662. NullPointerException in CryptoInputStream while wrapped
|
HADOOP-10662. NullPointerException in CryptoInputStream while wrapped
|
||||||
stream is not ByteBufferReadable. Add tests using normal stream. (Yi Liu)
|
stream is not ByteBufferReadable. Add tests using normal stream. (Yi Liu)
|
||||||
|
|
||||||
|
HADOOP-10713. Refactor CryptoCodec#generateSecureRandom to take a byte[].
|
||||||
|
(wang via yliu)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
@ -81,9 +81,10 @@ public static CryptoCodec getInstance(Configuration conf) {
|
|||||||
public abstract void calculateIV(byte[] initIV, long counter, byte[] IV);
|
public abstract void calculateIV(byte[] initIV, long counter, byte[] IV);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate secure random.
|
* Generate a number of secure, random bytes suitable for cryptographic use.
|
||||||
* @param bytes length of the secure random
|
* This method needs to be thread-safe.
|
||||||
* @return byte[] the secure random
|
*
|
||||||
|
* @param bytes byte array to populate with random data
|
||||||
*/
|
*/
|
||||||
public abstract byte[] generateSecureRandom(int bytes);
|
public abstract void generateSecureRandom(byte[] bytes);
|
||||||
}
|
}
|
||||||
|
@ -79,10 +79,8 @@ public Decryptor createDecryptor() throws GeneralSecurityException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] generateSecureRandom(int bytes) {
|
public void generateSecureRandom(byte[] bytes) {
|
||||||
final byte[] data = new byte[bytes];
|
random.nextBytes(bytes);
|
||||||
random.nextBytes(data);
|
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class JCEAESCTRCipher implements Encryptor, Decryptor {
|
private static class JCEAESCTRCipher implements Encryptor, Decryptor {
|
||||||
|
@ -49,8 +49,10 @@ public void testSecureRandom() throws Exception {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkSecureRandom(int len) {
|
private void checkSecureRandom(int len) {
|
||||||
byte[] rand = codec.generateSecureRandom(len);
|
byte[] rand = new byte[len];
|
||||||
byte[] rand1 = codec.generateSecureRandom(len);
|
byte[] rand1 = new byte[len];
|
||||||
|
codec.generateSecureRandom(rand);
|
||||||
|
codec.generateSecureRandom(rand1);
|
||||||
|
|
||||||
Assert.assertEquals(len, rand.length);
|
Assert.assertEquals(len, rand.length);
|
||||||
Assert.assertEquals(len, rand1.length);
|
Assert.assertEquals(len, rand1.length);
|
||||||
|
Loading…
Reference in New Issue
Block a user