FTI_Video_Service/src/bswabe/Bswabe.java
/*
	 * Pick a random group element and encrypt it under the specified access
	 * policy. The resulting ciphertext is returned and the Element given as an
	 * argument (which need not be initialized) is set to the random group
	 * element.
	 * 
	 * After using this function, it is normal to extract the random data in m
	 * using the pbc functions element_length_in_bytes and element_to_bytes and
	 * use it as a key for hybrid encryption.
	 * 
	 * The policy is specified as a simple string which encodes a postorder
	 * traversal of threshold tree defining the access policy. As an example,
	 * 
	 * "foo bar fim 2of3 baf 1of2"
	 * 
	 * specifies a policy with two threshold gates and four leaves. It is not
	 * possible to specify an attribute with whitespace in it (although "_" is
	 * allowed).
	 * 
	 * Numerical attributes and any other fancy stuff are not supported.
	 * 
	 * Returns null if an error occured, in which case a description can be
	 * retrieved by calling bswabe_error().
	 */
Pick a random group element and encrypt it under the specified access
policy. The resulting ciphertext is returned and the Element given as an
argument (which need not be initialized) is set to the random group
element.

After using this function, it is normal to extract the random data in m
using the pbc functions element_length_in_bytes and element_to_bytes and
use it as a key for hybrid encryption.

The policy is specified as a simple string which encodes a postorder
traversal of threshold tree defining the access policy. As an example.

"foo bar fim 2of3 baf 1of2"

specifies a policy with two threshold gates and four leaves. It is not
possible to specify an attribute with whitespace in it (although "_" is
allowed).

Numerical attributes and any other fancy stuff are not supported.

Returns null if an error occured, in which case a description can be
retrieved by calling bswabe_error().
Pick a random group element and encrypt it under the specified access policy . The resulting ciphertext is returned and the Element given as an argument ( which need not be initialized ) is set to the random group element . After using this function it is normal to extract the random data in m using the pbc functions element_length_in_bytes and element_to_bytes and use it as a key for hybrid encryption . The policy is specified as a simple string which encodes a postorder traversal of threshold tree defining the access policy . As an example . " foo bar fim 2of3 baf 1of2 " specifies a policy with two threshold gates and four leaves . It is not possible to specify an attribute with whitespace in it ( although " _ " is allowed ) . Numerical attributes and any other fancy stuff are not supported . Returns null if an error occured in which case a description can be retrieved by calling bswabe_error () .
public static BswabeCphKey enc(BswabePub pub, String policy)
			throws Exception {
		BswabeCphKey keyCph = new BswabeCphKey();
		BswabeCph cph = new BswabeCph();
		Element s, m;
		/* initialize */
		Pairing pairing = pub.p;
		s = pairing.getZr().newElement();
		m = pairing.getGT().newElement();
		cph.cs = pairing.getGT().newElement();
		cph.c = pairing.getG1().newElement();
		cph.p = parsePolicyPostfix(policy);
		/* compute */
		m.setToRandom();
		s.setToRandom();
		cph.cs = pub.g_hat_alpha.duplicate();
		cph.cs.powZn(s); /* num_exps++; */
		cph.cs.mul(m); /* num_muls++; */
		cph.c = pub.h.duplicate();
		cph.c.powZn(s); /* num_exps++; */
		fillPolicy(cph.p, pub, s);
		keyCph.cph = cph;
		keyCph.key = m;
		return keyCph;
	}
public static BswabeCphKey enc ( BswabePub pub , String policy ) throws Exception { BswabeCphKey keyCph = new BswabeCphKey ( ) ; BswabeCph cph = new BswabeCph ( ) ; Element s , m ; /* initialize */ Pairing pairing = pub . p ; s = pairing . getZr ( ) . newElement ( ) ; m = pairing . getGT ( ) . newElement ( ) ; cph . cs = pairing . getGT ( ) . newElement ( ) ; cph . c = pairing . getG1 ( ) . newElement ( ) ; cph . p = parsePolicyPostfix ( policy ) ; /* compute */ m . setToRandom ( ) ; s . setToRandom ( ) ; cph . cs = pub . g_hat_alpha . duplicate ( ) ; cph . cs . powZn ( s ) ; /* num_exps++; */ cph . cs . mul ( m ) ; /* num_muls++; */ cph . c = pub . h . duplicate ( ) ; cph . c . powZn ( s ) ; /* num_exps++; */ fillPolicy ( cph . p , pub , s ) ; keyCph . cph = cph ; keyCph . key = m ; return keyCph ; }
Pick a random group element and encrypt it under the specified access
 policy.
Pick a random group element and encrypt it under the specified access policy .