示例#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));
    }
示例#3
0
  @Override
  public void setup(Context context) {
    Configuration conf = context.getConfiguration();
    crypto = new Rand();
    crypto.init(conf.get("key"));

    pattern = Pattern.compile(conf.get(PATTERN));
  }
示例#4
0
  /* decrypt, then compute
   */
  @Override
  public void map(BytesWritable key, BytesWritable val, Context context)
      throws IOException, InterruptedException {
    byte[] iv = key.copyBytes();
    byte[] ct = val.copyBytes();
    // String[] ss = new String(crypto.decrypt_word_rnd(ct, iv)).split("\\s+");

    String text = new String(crypto.decrypt_word_rnd(ct, iv));
    Matcher matcher = pattern.matcher(text);

    while (matcher.find()) {
      context.write(new Text(matcher.group(0)), new LongWritable(1));
    }
  }
 @Override
 public void setup(Context context) {
   Configuration conf = context.getConfiguration();
   crypto = new Rand();
   crypto.init(conf.get("key"));
 }