Ejemplo n.º 1
0
 public Pointer set(OCPUser user, byte[] bytes) throws Exception {
   // 1) Create all the data objects
   Key[] keys = new Key[user.getBackupNbr()];
   for (int i = 0; i < user.getBackupNbr(); i++) {
     byte[] bkp = new byte[1];
     bkp[0] = (byte) i;
     byte[] bkpBytes = ByteUtil.concat(bkp, bytes);
     byte[] ciphertext = user.crypt(bkpBytes);
     Data data = new Data(this, user, ciphertext);
     keys[i] = set(data);
   }
   // 2) create the pointer link
   Pointer pointer = makePointer(user, keys);
   // 3 ) add the pointer to the user index.
   user.add(this, pointer);
   return pointer;
 }
Ejemplo n.º 2
0
  public byte[] getBytes(OCPUser user, Pointer pointer) throws Exception {
    // 1) retrieve the key list from pointer
    Key[] keys = getKeys(user, pointer);
    // 2) from each key retrieve the object
    if (keys.length != user.getBackupNbr()) {
      throw new Exception("nbr of keys different from user backup nbr.");
    }
    byte[] result = null;
    // TODO : check if all bkp are identical and repair if necessary
    for (int i = 0; i < keys.length; i++) {
      Data data = (Data) get(keys[i]);
      if (data != null) {
        byte[] ciphertext = data.getContent();
        byte[] cleartext = user.decrypt(ciphertext);
        result = ByteUtil.sub(cleartext, 1);

        break;
      }
    }
    return result;
  }