List of usage examples for com.amazonaws.services.dynamodbv2.document Item withBinary
public Item withBinary(String attrName, ByteBuffer val)
From source file:ws.salient.aws.dynamodb.DynamoDBStore.java
License:Apache License
public Item encrypt(Item item, SecretKeySpec key, String... attributes) { try {//from w w w . jav a 2s.c o m if (key != null) { Cipher cipher = Cipher.getInstance(transformation); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] iv = cipher.getIV(); for (String attribute : attributes) { byte[] value = item.getBinary(attribute); item.withBinary(attribute, cipher.doFinal(value)); } item.withMap("cipher", new LinkedHashMap()); item.getMap("cipher").put("transformation", transformation); item.getMap("cipher").put("iv", iv); } return item; } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException ex) { throw new RuntimeException(ex); } }
From source file:ws.salient.aws.dynamodb.DynamoDBStore.java
License:Apache License
public Item decrypt(Item item, SecretKeySpec key, String... attributes) { try {/*from www .j ava2 s . c o m*/ if (key != null) { String transformation = (String) item.getMap("cipher").get("transformation"); byte[] iv = (byte[]) item.getMap("cipher").get("iv"); Cipher cipher = Cipher.getInstance(transformation); cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv)); for (String attribute : attributes) { byte[] value = item.getBinary(attribute); item.withBinary(attribute, cipher.doFinal(value)); } } return item; } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException ex) { throw new RuntimeException(ex); } }