def test_create_signed_cleartext(self):
        # signing key of issuer
        bob_signing_key = SigningKey.from_credentials("bob", "password")

        # message
        message = """
Hello world !

Héhé ;-)

This is a utf-8 message...

       """
        # create encrypted and signed ascii armor message
        signed_cleartext_aa_message = AsciiArmor.create(message, None, [bob_signing_key])

        # split in lines for check up
        aa_message_lines = signed_cleartext_aa_message.splitlines()

        # check before message
        self.assertEqual(aa_message_lines[0], BEGIN_MESSAGE_HEADER)
        self.assertEqual("", aa_message_lines[1].strip())

        # check after message
        self.assertEqual(aa_message_lines[10], BEGIN_SIGNATURE_HEADER)
        self.assertTrue(aa_message_lines[11].startswith("Version:"))
        self.assertEqual("", aa_message_lines[12].strip())
        self.assertEqual(aa_message_lines[14], END_SIGNATURE_HEADER)

        # parse ascii armor message
        result = AsciiArmor.parse(signed_cleartext_aa_message, None, [bob_signing_key.pubkey])

        # check result
        self.assertEqual(message + "\n", result['message']['content'])
        self.assertTrue(message + "\n", result['signatures'][0]['valid'])
    def test_create_encrypted(self):
        # pubkey of recipient
        alice_signing_key = SigningKey.from_credentials("alice", "password")

        # message
        message = """
Hello world !

Héhé ;-)

This is a utf-8 message...

       """
        # create encrypted and signed ascii armor message
        encrypted_aa_message = AsciiArmor.create(message, alice_signing_key.pubkey)

        # split in lines for check up
        aa_message_lines = encrypted_aa_message.splitlines()

        # check before message
        self.assertEqual(aa_message_lines[0], BEGIN_MESSAGE_HEADER)
        self.assertTrue(aa_message_lines[1].startswith("Version:"))
        self.assertEqual("", aa_message_lines[2].strip())

        # check after message
        self.assertEqual(aa_message_lines[4], END_MESSAGE_HEADER)

        # parse ascii armor message
        result = AsciiArmor.parse(encrypted_aa_message, alice_signing_key)

        # check result
        self.assertEqual(message + "\n", result['message']['content'])
    def test_create_encrypted(self):
        # pubkey of recipient
        alice_signing_key = SigningKey.from_credentials("alice", "password")

        # message
        message = """
Hello world !

Héhé ;-)

This is a utf-8 message...

       """
        # create encrypted and signed ascii armor message
        encrypted_aa_message = AsciiArmor.create(message,
                                                 alice_signing_key.pubkey)

        # split in lines for check up
        aa_message_lines = encrypted_aa_message.splitlines()

        # check before message
        self.assertEqual(aa_message_lines[0], BEGIN_MESSAGE_HEADER)
        self.assertTrue(aa_message_lines[1].startswith("Version:"))
        self.assertEqual("", aa_message_lines[2].strip())

        # check after message
        self.assertEqual(aa_message_lines[4], END_MESSAGE_HEADER)

        # parse ascii armor message
        result = AsciiArmor.parse(encrypted_aa_message, alice_signing_key)

        # check result
        self.assertEqual(message + "\n", result["message"]["content"])
    def test_create_signed_cleartext(self):
        # signing key of issuer
        bob_signing_key = SigningKey.from_credentials("bob", "password")

        # message
        message = """
Hello world !

Héhé ;-)

This is a utf-8 message...

       """
        # create encrypted and signed ascii armor message
        signed_cleartext_aa_message = AsciiArmor.create(
            message, None, [bob_signing_key])

        # split in lines for check up
        aa_message_lines = signed_cleartext_aa_message.splitlines()

        # check before message
        self.assertEqual(aa_message_lines[0], BEGIN_MESSAGE_HEADER)
        self.assertEqual("", aa_message_lines[1].strip())

        # check after message
        self.assertEqual(aa_message_lines[10], BEGIN_SIGNATURE_HEADER)
        self.assertTrue(aa_message_lines[11].startswith("Version:"))
        self.assertEqual("", aa_message_lines[12].strip())
        self.assertEqual(aa_message_lines[14], END_SIGNATURE_HEADER)

        # parse ascii armor message
        result = AsciiArmor.parse(signed_cleartext_aa_message, None,
                                  [bob_signing_key.pubkey])

        # check result
        self.assertEqual(message + "\n", result["message"]["content"])
        self.assertTrue(message + "\n", result["signatures"][0]["valid"])
示例#5
0
    # prompt hidden user entry
    salt = getpass.getpass("Enter your passphrase (salt): ")

    # prompt hidden user entry
    password = getpass.getpass("Enter your password: "******"Enter your message (Ctrl-D below last line to end):")
    message = sys.stdin.read()

    print("Message signed by puplic key : {pubkey}".format(pubkey=signing_key.pubkey))

    comment = "generated by Duniterpy {0}".format(__version__)
    # Dash escape the message and sign it
    aa_cleartext_message = AsciiArmor.create(
        message, None, [signing_key], None, signatures_comment=comment
    )

    # Save cleartext ascii armor message in a file
    with open(CLEARTEXT_AA_MESSAGE_PATH, "w") as file_handler:
        file_handler.write(aa_cleartext_message)

    print(
        "Cleartext Ascii Armor Message saved in file ./{0}".format(
            CLEARTEXT_AA_MESSAGE_PATH
        )
    )
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

from duniterpy.key import AsciiArmor

# CONFIG #######################################

CLEARTEXT_AA_MESSAGE_PATH = "/tmp/duniter_cleartext_aa_message.txt"

################################################

if __name__ == "__main__":
    # Ask public key of the issuer
    pubkeyBase58 = input("Enter public key of the message issuer: ")

    # Load cleartext ascii armor message from a file
    with open(CLEARTEXT_AA_MESSAGE_PATH, "r") as file_handler:
        ascii_armor_block = file_handler.read()

    print("Cleartext Ascii Armor Message loaded from file ./{0}".format(
        CLEARTEXT_AA_MESSAGE_PATH))

    result = AsciiArmor.parse(ascii_armor_block, None, [pubkeyBase58])
    print("------------- MESSAGE ------------\n" +
          result["message"]["content"] + "----------------------------------")
    print(result)
CLEARTEXT_AA_MESSAGE_PATH = '/tmp/duniter_cleartext_aa_message.txt'

################################################

if __name__ == '__main__':
    # prompt hidden user entry
    salt = getpass.getpass("Enter your passphrase (salt): ")

    # prompt hidden user entry
    password = getpass.getpass("Enter your password: "******"Enter your message (Ctrl-D below last line to end):")
    message = sys.stdin.read()

    print("Message signed by puplic key : {pubkey}".format(pubkey=signing_key.pubkey))

    comment = "generated by Duniterpy {0}".format(__version__)
    # Dash escape the message and sign it
    aa_cleartext_message = AsciiArmor.create(message, None, [signing_key], None, signatures_comment=comment)

    # Save cleartext ascii armor message in a file
    with open(CLEARTEXT_AA_MESSAGE_PATH, 'w') as file_handler:
        file_handler.write(aa_cleartext_message)

    print("Cleartext Ascii Armor Message saved in file ./{0}".format(CLEARTEXT_AA_MESSAGE_PATH))
from duniterpy.key import AsciiArmor

# CONFIG #######################################

CLEARTEXT_AA_MESSAGE_PATH = '/tmp/duniter_cleartext_aa_message.txt'

################################################

if __name__ == '__main__':
    # Ask public key of the issuer
    pubkeyBase58 = input("Enter public key of the message issuer: ")

    # Load cleartext ascii armor message from a file
    with open(CLEARTEXT_AA_MESSAGE_PATH, 'r') as file_handler:
        ascii_armor_block = file_handler.read()

    print("Cleartext Ascii Armor Message loaded from file ./{0}".format(CLEARTEXT_AA_MESSAGE_PATH))

    result = AsciiArmor.parse(ascii_armor_block, None, [pubkeyBase58])
    print('------------- MESSAGE ------------\n' + result['message']['content'] + '----------------------------------')
    print(result)
示例#9
0
from duniterpy.key import AsciiArmor, SigningKey

# CONFIG #######################################

ENCRYPTED_AA_MESSAGE_PATH = "/tmp/duniter_aa_encrypted_message.txt"

################################################

if __name__ == "__main__":
    # Ask public key of the recipient
    pubkeyBase58 = input("Enter public key of the message issuer: ")

    # prompt hidden user entry
    salt = getpass.getpass("Enter your passphrase (salt): ")

    # prompt hidden user entry
    password = getpass.getpass("Enter your password: "******"r") as file_handler:
        ascii_armor_block = file_handler.read()

    print("Encrypted Ascii Armor Message loaded from file {0}".format(
        ENCRYPTED_AA_MESSAGE_PATH))

    print(AsciiArmor.parse(ascii_armor_block, signing_key, [pubkeyBase58]))
import getpass

from duniterpy.key import AsciiArmor, SigningKey

# CONFIG #######################################

ENCRYPTED_AA_MESSAGE_PATH = '/tmp/duniter_aa_encrypted_message.txt'

################################################

if __name__ == '__main__':
    # Ask public key of the recipient
    pubkeyBase58 = input("Enter public key of the message issuer: ")

    # prompt hidden user entry
    salt = getpass.getpass("Enter your passphrase (salt): ")

    # prompt hidden user entry
    password = getpass.getpass("Enter your password: "******"Encrypted Ascii Armor Message loaded from file {0}".format(ENCRYPTED_AA_MESSAGE_PATH))

    print(AsciiArmor.parse(ascii_armor_block, signing_key, [pubkeyBase58]))
    # prompt hidden user entry
    password = getpass.getpass("Enter your password: "******"Enter your message: ")

    print("Message signed by puplic key : {pubkey}".format(pubkey=signing_key.pubkey))

    comment = "generated by Duniterpy {0}".format(__version__)
    # Encrypt the message, only the recipient secret key will be able to decrypt the message
    encrypted_message = AsciiArmor.create(
        message,
        pubkeyBase58,
        [signing_key],
        message_comment=comment,
        signatures_comment=comment,
    )

    # Save encrypted message in a file
    with open(ENCRYPTED_AA_MESSAGE_PATH, "w") as file_handler:
        file_handler.write(encrypted_message)

    print(
        "Encrypted Ascii Armor Message saved in file {0}".format(
            ENCRYPTED_AA_MESSAGE_PATH
        )
    )
################################################

if __name__ == '__main__':
    # Ask public key of the recipient
    pubkeyBase58 = input("Enter public key of the message recipient: ")

    # prompt hidden user entry
    salt = getpass.getpass("Enter your passphrase (salt): ")

    # prompt hidden user entry
    password = getpass.getpass("Enter your password: "******"Enter your message: ")

    print("Message signed by puplic key : {pubkey}".format(pubkey=signing_key.pubkey))

    comment = "generated by Duniterpy {0}".format(__version__)
    # Encrypt the message, only the recipient secret key will be able to decrypt the message
    encrypted_message = AsciiArmor.create(message, pubkeyBase58, [signing_key], message_comment=comment,
                                          signatures_comment=comment)

    # Save encrypted message in a file
    with open(ENCRYPTED_AA_MESSAGE_PATH, 'w') as file_handler:
        file_handler.write(encrypted_message)

    print("Encrypted Ascii Armor Message saved in file {0}".format(ENCRYPTED_AA_MESSAGE_PATH))