Example usage for com.amazonaws.services.dynamodbv2.document Item withBinary

List of usage examples for com.amazonaws.services.dynamodbv2.document Item withBinary

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.document Item withBinary.

Prototype

public Item withBinary(String attrName, ByteBuffer val) 

Source Link

Document

Sets the value of the specified attribute in the current item to the given value.

Usage

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);
    }
}