Example #1
0
 @Override
 public void reduce(Text key, Iterable<LongWritable> vals, Context context)
     throws IOException, InterruptedException {
   int s = 0;
   for (LongWritable lw : vals) s += lw.get();
   String pt = key.toString() + " " + s;
   byte[] iv = crypto.randomBytes(AES_BLOCK_SIZE);
   byte[] ct = crypto.encrypt_word_rnd(pt, iv);
   context.write(new BytesWritable(iv), new BytesWritable(ct));
 }
    @Override
    public void map(Text key, Text value, Context context)
        throws IOException, InterruptedException {
      byte[] randomIV = crypto.randomBytes(AES_BLOCK_SIZE);

      byte[] pt = new byte[KEY_LENGTH + VALUE_LENGTH];
      System.arraycopy(key.copyBytes(), 0, pt, 0, KEY_LENGTH);
      System.arraycopy(value.copyBytes(), 0, pt, KEY_LENGTH, VALUE_LENGTH);
      // byte[] ct = crypto.encrypt_word_rnd(value.toString(), randomIV);
      byte[] ct = crypto.encrypt_word_cbc(pt, randomIV);
      System.out.println("ct size = " + ct.length);
      context.write(new BytesWritable(randomIV), new BytesWritable(ct));
    }