Пример #1
0
def main(args):
    if len(args) != 4 or args[1] not in ['dec', 'enc']:
        print 'Usage: crypt.py enc <plaintext> <passphrase>'
        print '       crypt.py dec <encrypted> <passphrase>'
        return

    op = args[1]
    key = args[3]

    if op == 'enc':
        plain = args[2]
        try:
            print CryptoUtil.encrypt(plain, key)
        except KeyLengthError, ex:
            print ex
Пример #2
0
def send_purchase_to_supervisor(supervisor_connection, purchase_message,
                                keypair, supervisor_public_key):
    # Encrypt purchase message with supervisor's public key
    encrypted_purchase_message = CryptoUtil.encrypt(purchase_message.encode(),
                                                    supervisor_public_key)
    # Sign purchase message with our private key
    signature = CryptoUtil.sign(purchase_message.encode(), keypair)

    NetworkUtil.send_message(supervisor_connection, encrypted_purchase_message)
    NetworkUtil.send_message(supervisor_connection, signature)

    confirmation = NetworkUtil.receive_message(supervisor_connection)
    return encrypted_purchase_message, signature, confirmation
Пример #3
0
def reencrypt_and_resign_purchase_message_to_department(
        department_connection, customer_signature, purchase_message,
        department_public_key):
    # Resend customer signature to deparmtent
    NetworkUtil.send_message(department_connection, customer_signature)

    # Re-encrypt purchase message using the department's public key, generate our own signature and send both to
    # the department
    encrypted_purchase_message = CryptoUtil.encrypt(purchase_message.encode(),
                                                    department_public_key)
    supervisor_signature = CryptoUtil.sign(purchase_message.encode(), keypair)
    NetworkUtil.send_message(department_connection, encrypted_purchase_message)
    NetworkUtil.send_message(department_connection, supervisor_signature)
Пример #4
0
def main(args):

    if len(args) != 2 or args[1] not in ['decrypt','encrypt','enc','dec']:
        usage()

    op = args[1]

    if op in ['enc', 'encrypt']:
        key = getpass.getpass('Please enter the encryption key: ')
        plaintext = getpass.getpass('Please enter the plaintext you wish to encrypt: ')
        try:
            encrypted_value = CryptoUtil.encrypt(plaintext, key)
            print "Encrypted Value: " + encrypted_value
        except KeyLengthError, ex:
            print ex
Пример #5
0
def main(args):

    if len(args) != 2 or args[1] not in ['decrypt', 'encrypt', 'enc', 'dec']:
        usage()

    op = args[1]

    if op in ['enc', 'encrypt']:
        key = getpass.getpass('Please enter the encryption key: ')
        plaintext = getpass.getpass(
            'Please enter the plaintext you wish to encrypt: ')
        try:
            encrypted_value = CryptoUtil.encrypt(plaintext, key)
            print "Encrypted Value: " + encrypted_value
        except KeyLengthError, ex:
            print ex
Пример #6
0
if __name__ == "__main__":
    # Connect to department and customer
    department_connection, customer_connection = listen_for_department_and_customer(
    )
    # Generate our key pair and and get the public keys of others
    keypair, department_public_key, customer_public_key = exchange_public_keys(
        department_connection, customer_connection)

    while True:
        confirmation, customer_signature, purchase_message, encrypted_purchase_message = handle_customer_purchase_message_and_confirm(
            customer_connection, keypair, customer_public_key)

        if confirmation == 'y':
            # Tell customer that order is confirmed
            confirmation_msg = CryptoUtil.encrypt(
                "Order was confirmed".encode(), customer_public_key)
            NetworkUtil.send_message(customer_connection, confirmation_msg)

            reencrypt_and_resign_purchase_message_to_department(
                department_connection, customer_signature, purchase_message,
                department_public_key)
        else:
            # Rejected order
            confirmation_msg = CryptoUtil.encrypt(
                "Order was rejected".encode(), customer_public_key)
            NetworkUtil.send_message(customer_connection, confirmation_msg)

        # Show all the received messages (encrypted)
        presentation = input(
            "Show the all sending and receiving messages? (y/n)")
        if (presentation == 'y'):