示例#1
0
def main():
    """Wrapper function to decrypt a ciphertext file using the
    Bethencourt2007cae CP-ABE Scheme.

    """

    parser = argparse.ArgumentParser(
        description="Decrypts a given ciphertext, with name <fname>.cpabe,"
        " using the provided decryption key.")

    parser.add_argument('--mpk',
                        required=True,
                        dest='mpk',
                        type=str,
                        help="The name of the Public Parameters." +
                        " Default: %(default)s")

    parser.add_argument('--ctxt',
                        required=True,
                        dest='ctxt',
                        type=str,
                        help="The name of the file containing the" +
                        " ciphertext to be decrypted.")

    parser.add_argument('--dkey',
                        required=True,
                        dest='dkey',
                        type=str,
                        help="The name of the file containing the" +
                        " decryption key")

    args = parser.parse_args()

    if not args.ctxt.endswith(".cpabe"):
        print("Ciphertext needs to end with .cpabe")
        sys.exit(-1)

    ptxt_fname = args.ctxt.replace(".cpabe", ".prime")

    group = PairingGroup('SS512')

    mpk = read_key_from_file(args.mpk, group)

    dkey = read_key_from_file(args.dkey, group)

    try:
        raw = cpabe_decrypt(group, mpk, dkey, io.open(args.ctxt, 'rb'))
    except PebelDecryptionException as e:
        print("Unable to decrypt ciphertext: {}".format(e))
        sys.exit(-1)
    else:
        with io.open(ptxt_fname, 'wb') as ptxt:
            for b in raw:
                ptxt.write(bytes([b]))
                ptxt.flush()
示例#2
0
def main():
    """Wrapper function to decrypt a ciphertext file using the
    Bethencourt2007cae CP-ABE Scheme.

    """

    parser = argparse.ArgumentParser(
        description="Decrypts a given ciphertext, with name <fname>.cpabe,"
        " using the provided decryption key.")

    parser.add_argument('--mpk',
                        required=True,
                        dest='mpk',
                        type=str,
                        help="The name of the Public Parameters."+
                        " Default: %(default)s")

    parser.add_argument('--ctxt',
                        required=True,
                        dest='ctxt',
                        type=str,
                        help= "The name of the file containing the" +
                        " ciphertext to be decrypted.")

    parser.add_argument('--dkey',
                        required=True,
                        dest='dkey',
                        type=str,
                        help="The name of the file containing the" +
                        " decryption key")

    args = parser.parse_args()

    if not args.ctxt.endswith(".cpabe"):
        print("Ciphertext needs to end with .cpabe")
        sys.exit(-1)

    ptxt_fname = args.ctxt.replace(".cpabe", ".prime")

    group = PairingGroup('SS512')

    mpk = read_key_from_file(args.mpk, group)

    dkey = read_key_from_file(args.dkey, group)

    try:
        #ctxt = io.open(args.ctxt, 'rb').readlines()
        raw = cpabe_decrypt(group, mpk, dkey, io.open(args.ctxt, 'rb'))
    except PebelDecryptionException as e:
        print("Unable to decrypt ciphertext: {}".format(e))
        sys.exit(-1)
    else:
        with io.open(ptxt_fname, 'wb') as ptxt:
            ptxt.write(raw)
            '''
示例#3
0
def main():
    """Wrapper function to generate decryption keys for the
    Bethencourt2007cae CP-ABE Scheme.
    """
    parser = argparse.ArgumentParser(
        description="Generates decryption keys from a set of attributes" +
        " for the BSW2007cae CP-ABE Scheme.")
    parser.add_argument('--mpk',
                        required=True,
                        dest='mpk',
                        type=str,
                        help="The name of the Public Parameters." +
                        " Default: %(default)s")
    parser.add_argument('--msk',
                        required=True,
                        dest='msk',
                        type=str,
                        help="The name of the Master Secret Key." +
                        " Default: %(default)s")
    parser.add_argument('--dkey-out',
                        default="bob.cp.dkey",
                        dest='dkey',
                        type=str,
                        help="The name of the file in which to store" +
                        " the decryption key. Default: %(default)s")
    parser.add_argument(
        'attributes',
        nargs=argparse.REMAINDER,
        help="The attributes used to construct the secret key.")

    args = parser.parse_args()
    group = PairingGroup('SS512')
    msk = read_key_from_file(args.msk, group)
    mpk = read_key_from_file(args.mpk, group)

    attributes = [a.upper() for a in args.attributes]

    dec_key = cpabe_keygen(group, msk, mpk, attributes)

    write_key_to_file(args.dkey, dec_key, group)
示例#4
0
def main():
    """Wrapper function to generate decryption keys for the
    Bethencourt2007cae CP-ABE Scheme.
    """
    parser = argparse.ArgumentParser(
        description="Generates decryption keys from a set of attributes" +
        " for the BSW2007cae CP-ABE Scheme.")
    parser.add_argument('--mpk',
                        required=True,
                        dest='mpk',
                        type=str,
                        help="The name of the Public Parameters." +
                        " Default: %(default)s")
    parser.add_argument('--msk',
                        required=True,
                        dest='msk',
                        type=str,
                        help="The name of the Master Secret Key." +
                        " Default: %(default)s")
    parser.add_argument('--dkey-out',
                        default="bob.cp.dkey",
                        dest='dkey',
                        type=str,
                        help="The name of the file in which to store" +
                        " the decryption key. Default: %(default)s")
    parser.add_argument('attributes',
                        nargs=argparse.REMAINDER,
                        help="The attributes used to construct the secret key.")

    args = parser.parse_args()
    group = PairingGroup('SS512')
    msk = read_key_from_file(args.msk, group)
    mpk = read_key_from_file(args.mpk, group)

    attributes = [a.upper() for a in args.attributes]

    dec_key = cpabe_keygen(group, msk, mpk, attributes)

    write_key_to_file(args.dkey, dec_key, group)
示例#5
0
def main():
    """Wrapper function to generate decryption keys for the
    Lewko2008rsw KP-ABE Scheme."""

    parser = argparse.ArgumentParser(
        description="Generates decryption keys from a policy" + " for the Lewko2008rsw KP-ABE Scheme."
    )
    parser.add_argument(
        "--mpk",
        required=True,
        dest="mpk",
        type=str,
        help="The name of the Public Parameters." + " Default: %(default)s",
    )
    parser.add_argument(
        "--msk",
        required=True,
        dest="msk",
        type=str,
        help="The name of the Master Secret Key." + " Default: %(default)s",
    )
    parser.add_argument(
        "--dkey-out",
        default="bob.kp.dkey",
        dest="dkey",
        type=str,
        help="The name of the file in which to store" + " the decryption key. Default: %(default)s",
    )
    parser.add_argument("policy", help="The policy used to construct the secret key.")

    args = parser.parse_args()
    group = PairingGroup("MNT224")
    msk = read_key_from_file(args.msk, group)
    mpk = read_key_from_file(args.mpk, group)

    dec_key = kpabe_keygen(group, msk, mpk, args.policy)

    write_key_to_file(args.dkey, dec_key, group)
示例#6
0
def main():
    """Wrapper function to generate decryption keys for the
    Lewko2008rsw KP-ABE Scheme."""

    parser = argparse.ArgumentParser(
        description="Generates decryption keys from a policy" +
        " for the Lewko2008rsw KP-ABE Scheme.")
    parser.add_argument('--mpk',
                        required=True,
                        dest='mpk',
                        type=str,
                        help="The name of the Public Parameters." +
                        " Default: %(default)s")
    parser.add_argument('--msk',
                        required=True,
                        dest='msk',
                        type=str,
                        help="The name of the Master Secret Key." +
                        " Default: %(default)s")
    parser.add_argument('--dkey-out',
                        default="bob.kp.dkey",
                        dest='dkey',
                        type=str,
                        help="The name of the file in which to store" +
                        " the decryption key. Default: %(default)s")
    parser.add_argument('policy',
                        help="The policy used to construct the secret key.")

    args = parser.parse_args()
    group = PairingGroup('MNT224')
    msk = read_key_from_file(args.msk, group)
    mpk = read_key_from_file(args.mpk, group)

    dec_key = kpabe_keygen(group, msk, mpk, args.policy)

    write_key_to_file(args.dkey, dec_key, group)
示例#7
0
def main():
    """Wrapper function to encrypt a file using the
    Lewko2008rsw KP-ABE Scheme.
    """

    parser = argparse.ArgumentParser(
        description="Encrypts a named file under a given set of attributes"
        " using the Lewko2008rsw KP-ABE Scheme."
        )

    parser.add_argument('--mpk',
                        required=True,
                        dest='mpk',
                        type=str,
                        help="The name of the public parameters"
                        " Default: %(default)s"
        )

    parser.add_argument('--ptxt',
                        required=True,
                        dest='ptxt',
                        type=str,
                        help="A file containing the plaintext to be encrypted."
        )

    parser.add_argument('attributes',
                        nargs=argparse.REMAINDER,
                        help="The attributes used to encrypt the plain-text"
        )

    args = parser.parse_args()

    group = PairingGroup('MNT224')

    mpk = read_key_from_file(args.mpk, group)

    ctxt = kpabe_encrypt(group, mpk, io.open(args.ptxt, 'rb'), args.attributes)

    ctxt_fname = "".join([args.ptxt, ".kpabe"])

    with io.open(ctxt_fname, 'wb') as ctxt_file:
        for b in ctxt:
            ctxt_file.write(bytes(b))
示例#8
0
def main():
    """Wrapper function to encrypt a file using the
    Lewko2008rsw KP-ABE Scheme.
    """

    parser = argparse.ArgumentParser(
        description="Encrypts a named file under a given set of attributes"
        " using the Lewko2008rsw KP-ABE Scheme."
        )

    parser.add_argument('--mpk',
                        required=True,
                        dest='mpk',
                        type=str,
                        help="The name of the public parameters"
                        " Default: %(default)s"
        )

    parser.add_argument('--ptxt',
                        required=True,
                        dest='ptxt',
                        type=str,
                        help="A file containing the plaintext to be encrypted."
        )

    parser.add_argument('attributes',
                        nargs=argparse.REMAINDER,
                        help="The attributes used to encrypt the plain-text"
        )

    args = parser.parse_args()

    group = PairingGroup('MNT224')

    mpk = read_key_from_file(args.mpk, group)

    ctxt = kpabe_encrypt(group, mpk, io.open(args.ptxt, 'rb'), args.attributes)

    ctxt_fname = "".join([args.ptxt, ".kpabe"])

    with io.open(ctxt_fname, 'wb') as ctxt_file:
        for b in ctxt:
            ctxt_file.write(bytes([b]))
示例#9
0
def main():
    """Wrapper function to encrypt a file using the Bethencourt2007cae
    CP-ABE Scheme.

    """

    parser = argparse.ArgumentParser(
        description="Encrypts a named file under a given policy using the" +
        " BSW2007cae CP-ABE Scheme.")

    parser.add_argument('--mpk',
                        required=True,
                        dest='mpk',
                        type=str,
                        help="The name of the Public Parameters." +
                        " Default: %(default)s")

    parser.add_argument(
        '--ptxt',
        required=True,
        dest='ptxt',
        type=str,
        help="A file containing the plaintext to be encrypted.")

    parser.add_argument('policy',
                        help="The policy used to encrypt the plaintext under.")

    args = parser.parse_args()

    group = PairingGroup('SS512')

    mpk = read_key_from_file(args.mpk, group)

    ctxt = cpabe_encrypt(group, mpk, io.open(args.ptxt, 'rb'), args.policy)

    ctxt_fname = "".join([args.ptxt, ".cpabe"])

    with io.open(ctxt_fname, 'wb') as ctxt_file:
        ctxt_file.write(ctxt)
        '''
示例#10
0
def main():
    """Wrapper function to encrypt a file using the Bethencourt2007cae
    CP-ABE Scheme.

    """

    parser = argparse.ArgumentParser(
        description="Encrypts a named file under a given policy using the" +
        " BSW2007cae CP-ABE Scheme.")

    parser.add_argument('--mpk',
                        required=True,
                        dest='mpk',
                        type=str,
                        help="The name of the Public Parameters."+
                        " Default: %(default)s")

    parser.add_argument('--ptxt',
                        required=True,
                        dest='ptxt',
                        type=str,
                        help="A file containing the plaintext to be encrypted.")

    parser.add_argument('policy',
                        help="The policy used to encrypt the plaintext under.")

    args = parser.parse_args()

    group = PairingGroup('SS512')

    mpk = read_key_from_file(args.mpk, group)

    ctxt = cpabe_encrypt(group, mpk, io.open(args.ptxt,'rb'), args.policy)

    ctxt_fname = "".join([args.ptxt, ".cpabe"])

    with io.open(ctxt_fname, 'wb') as ctxt_file:
        for b in ctxt:
            ctxt_file.write(bytes([b]))