use of org.apache.accumulo.core.spi.crypto.AESCryptoService in project accumulo by apache.
the class CryptoTest method simpleGCMTest.
@Test
public void simpleGCMTest() throws Exception {
AccumuloConfiguration conf = getAccumuloConfig(ConfigMode.CRYPTO_ON);
CryptoService cs = new AESCryptoService();
cs.init(conf.getAllPropertiesWithPrefix(Property.INSTANCE_CRYPTO_PREFIX));
CryptoEnvironment encEnv = new CryptoEnvironmentImpl(Scope.RFILE, null);
FileEncrypter encrypter = cs.getFileEncrypter(encEnv);
byte[] params = encrypter.getDecryptionParameters();
assertNotNull(params);
ByteArrayOutputStream out = new ByteArrayOutputStream();
DataOutputStream dataOut = new DataOutputStream(out);
CryptoUtils.writeParams(params, dataOut);
OutputStream encrypted = encrypter.encryptStream(dataOut);
assertNotNull(encrypted);
DataOutputStream cipherOut = new DataOutputStream(encrypted);
cipherOut.writeUTF(MARKER_STRING);
cipherOut.close();
dataOut.close();
encrypted.close();
out.close();
byte[] cipherText = out.toByteArray();
// decrypt
ByteArrayInputStream in = new ByteArrayInputStream(cipherText);
FileDecrypter decrypter = getFileDecrypter(cs, Scope.RFILE, new DataInputStream(in));
DataInputStream decrypted = new DataInputStream(decrypter.decryptStream(in));
String plainText = decrypted.readUTF();
decrypted.close();
in.close();
assertEquals(MARKER_STRING, new String(plainText));
}
use of org.apache.accumulo.core.spi.crypto.AESCryptoService in project accumulo by apache.
the class CryptoTest method testAESCryptoServiceWALDisabled.
/**
* AESCryptoService is configured but only for reading
*/
@Test
public void testAESCryptoServiceWALDisabled() throws Exception {
AESCryptoService cs = new AESCryptoService();
// make sure we can read encrypted
byte[] encryptedBytes = encrypt(cs, Scope.WAL, ConfigMode.CRYPTO_ON);
String stringEncryptedBytes = Arrays.toString(encryptedBytes);
String stringifiedMarkerBytes = getStringifiedBytes(null, MARKER_STRING, MARKER_INT);
assertNotEquals(stringEncryptedBytes, stringifiedMarkerBytes);
decrypt(encryptedBytes, Scope.WAL, ConfigMode.CRYPTO_ON_DISABLED);
// make sure we don't encrypt when disabled
byte[] plainBytes = encrypt(cs, Scope.WAL, ConfigMode.CRYPTO_ON_DISABLED);
String stringPlainBytes = Arrays.toString(plainBytes);
assertNotEquals(stringEncryptedBytes, stringPlainBytes);
decrypt(plainBytes, Scope.WAL, ConfigMode.CRYPTO_ON_DISABLED);
}
use of org.apache.accumulo.core.spi.crypto.AESCryptoService in project accumulo by apache.
the class CryptoTest method testAESCryptoServiceRFILEDisabled.
/**
* AESCryptoService is configured but only for reading
*/
@Test
public void testAESCryptoServiceRFILEDisabled() throws Exception {
AESCryptoService cs = new AESCryptoService();
// make sure we can read encrypted
byte[] encryptedBytes = encrypt(cs, Scope.RFILE, ConfigMode.CRYPTO_ON);
String stringEncryptedBytes = Arrays.toString(encryptedBytes);
String stringifiedMarkerBytes = getStringifiedBytes(null, MARKER_STRING, MARKER_INT);
assertNotEquals(stringEncryptedBytes, stringifiedMarkerBytes);
decrypt(encryptedBytes, Scope.RFILE, ConfigMode.CRYPTO_ON_DISABLED);
// make sure we don't encrypt when disabled
byte[] plainBytes = encrypt(cs, Scope.RFILE, ConfigMode.CRYPTO_ON_DISABLED);
String stringPlainBytes = Arrays.toString(plainBytes);
assertNotEquals(stringEncryptedBytes, stringPlainBytes);
decrypt(plainBytes, Scope.RFILE, ConfigMode.CRYPTO_ON_DISABLED);
}
use of org.apache.accumulo.core.spi.crypto.AESCryptoService in project accumulo by apache.
the class CryptoTest method testAESCryptoServiceRFILE.
@Test
public void testAESCryptoServiceRFILE() throws Exception {
AESCryptoService cs = new AESCryptoService();
byte[] resultingBytes = encrypt(cs, Scope.RFILE, ConfigMode.CRYPTO_ON);
String stringifiedBytes = Arrays.toString(resultingBytes);
String stringifiedMarkerBytes = getStringifiedBytes(null, MARKER_STRING, MARKER_INT);
assertNotEquals(stringifiedBytes, stringifiedMarkerBytes);
decrypt(resultingBytes, Scope.RFILE, ConfigMode.CRYPTO_ON);
}
use of org.apache.accumulo.core.spi.crypto.AESCryptoService in project accumulo by apache.
the class CryptoTest method testAESCryptoServiceWAL.
@Test
public void testAESCryptoServiceWAL() throws Exception {
AESCryptoService cs = new AESCryptoService();
byte[] resultingBytes = encrypt(cs, Scope.WAL, ConfigMode.CRYPTO_ON);
String stringifiedBytes = Arrays.toString(resultingBytes);
String stringifiedMarkerBytes = getStringifiedBytes(null, MARKER_STRING, MARKER_INT);
assertNotEquals(stringifiedBytes, stringifiedMarkerBytes);
decrypt(resultingBytes, Scope.WAL, ConfigMode.CRYPTO_ON);
}
Aggregations