def generate_keypair(keysize, id, output):
    """Generate a paillier private key.

    Output as JWK to given output file. Use "-" to output the private key to
    stdout. See the extract command to extract the public component of the
    private key.

    Note:
        The default ID text includes the current time.
    """
    log("Generating a paillier keypair with keysize of {}".format(keysize))
    pub, priv = phe.generate_paillier_keypair(n_length=keysize)

    log("Keys generated")

    date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    jwk_public = {
        'kty': "DAJ",
        'alg': "PAI-GN1",
        "key_ops": ["encrypt"],
        'n': phe.util.int_to_base64(pub.n),
        'kid': "Paillier public key generated by pheutil on {}".format(date)
    }

    jwk_private = {
        'kty': "DAJ",
        'key_ops': ["decrypt"],
        'p': phe.util.int_to_base64(priv.p),
        'q': phe.util.int_to_base64(priv.q),
        'pub': jwk_public,
        'kid': "Paillier private key generated by pheutil on {}".format(date)
    }

    json.dump(jwk_private, output)
    output.write('\n')

    log("Private key written to {}".format(output.name))
def generate_keypair ( keysize , id , output ) : log ( "Generating a paillier keypair with keysize of {}" . format ( keysize ) ) pub , priv = phe . generate_paillier_keypair ( n_length = keysize ) log ( "Keys generated" ) date = datetime . datetime . now ( ) . strftime ( "%Y-%m-%d %H:%M:%S" ) jwk_public = { 'kty' : "DAJ" , 'alg' : "PAI-GN1" , "key_ops" : [ "encrypt" ] , 'n' : phe . util . int_to_base64 ( pub . n ) , 'kid' : "Paillier public key generated by pheutil on {}" . format ( date ) } jwk_private = { 'kty' : "DAJ" , 'key_ops' : [ "decrypt" ] , 'p' : phe . util . int_to_base64 ( priv . p ) , 'q' : phe . util . int_to_base64 ( priv . q ) , 'pub' : jwk_public , 'kid' : "Paillier private key generated by pheutil on {}" . format ( date ) } json . dump ( jwk_private , output ) output . write ( '\n' ) log ( "Private key written to {}" . format ( output . name ) )
Generate a paillier private key.

    Output as JWK to given output file. Use "-" to output the private key to
    stdout. See the extract command to extract the public component of the
    private key.

    Note:
        The default ID text includes the current time.