Exemplo n.º 1
0
  protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
      throws IllegalBlockSizeException, BadPaddingException {
    if (inputLen != 0) {
      buffer.write(input, inputOffset, inputLen);
    }

    try {
      byte[] buf = buffer.toByteArray();

      buffer.reset();

      return cipher.processBlock(buf, 0, buf.length);
    } catch (InvalidCipherTextException e) {
      throw new BadPaddingException(e.getMessage());
    }
  }
  protected byte[] encrypt(CipherParameters publicKey, Element... ids) {
    byte[] ciphertext = new byte[0];
    try {
      PredicateOnlyEncryptionScheme engine = new UHIBELW11PredicateOnlyEngine();
      engine.init(
          true, new UHIBELW11EncryptionParameters((UHIBELW11PublicKeyParameters) publicKey, ids));
      ciphertext = engine.process();

      assertNotNull(ciphertext);
      assertNotSame(0, ciphertext.length);
    } catch (InvalidCipherTextException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    return ciphertext;
  }