Esempio n. 1
0
  public boolean enc(String pubfile, String policy, String inputfile, String encfile)
      throws Exception {
    CpabeEncryptedFile encFile;
    BswabePub pub;
    BswabeCph cph;
    BswabeCphKey keyCph;
    byte[] plt, aesBuf, pub_byte;
    Element m;

    /* get BswabePub from pubfile */
    pub_byte = Common.suckFile(pubfile);
    pub = new BswabePub();
    pub.initFromBuffer(pub_byte);

    /* encrypt */
    keyCph = Bswabe.enc(pub, policy);
    cph = keyCph.cph;
    m = keyCph.key;

    if (cph == null) {
      return false;
    }

    /* write file to encrypted */
    plt = Common.suckFile(inputfile);
    aesBuf = AESCoder.encrypt(m.toBytes(), plt);

    encFile = new CpabeEncryptedFile(cph, aesBuf);
    Common.spitFile(encfile, encFile.serialize());

    return true;
  }