def test_save_and_load_from_seedhex_file(self):
        sign_key_save = SigningKey.from_credentials("alice", "password",
                                                    ScryptParams())
        sign_key_save.save_seedhex_file(TEST_FILE_PATH)

        sign_key_load = SigningKey.from_seedhex_file(TEST_FILE_PATH)
        self.assertEqual(sign_key_save.sk, sign_key_load.sk)
Exemple #2
0
    def test_encrypt_seal(self):
        sign_key = SigningKey.from_credentials("alice", "password",
                                               ScryptParams())
        public_key = PublicKey(sign_key.pubkey)

        message = "Hello world with utf-8 chars like éàè !"
        encrypted_message = public_key.encrypt_seal(bytes(message, 'utf-8'))
        decrypted_message = sign_key.decrypt_seal(encrypted_message)
        self.assertEqual(message, decrypted_message.decode('utf-8'))
    def test_get_verified_data(self):
        sign_key = SigningKey.from_credentials("alice", "password", ScryptParams())

        message = "Hello world with utf-8 chars like éàè !"
        # Sign the message, the signed string is the message itself plus the
        # signature
        signed_message = sign_key.sign(bytes(message, 'utf-8'))  # type: bytes

        # Verify the message!
        verifier = VerifyingKey(sign_key.pubkey)
        verified_message = verifier.get_verified_data(signed_message)
        self.assertEqual(message, verified_message.decode('utf-8'))
Exemple #4
0
def auth_by_scrypt(ctx):
    salt = getpass("Please enter your Scrypt Salt (Secret identifier): ")
    password = getpass("Please enter your Scrypt password (masked): ")

    if ctx.obj["AUTH_SCRYPT_PARAMS"]:
        n, r, p = ctx.obj["AUTH_SCRYPT_PARAMS"].split(",")

        if n.isnumeric() and r.isnumeric() and p.isnumeric():
            n, r, p = int(n), int(r), int(p)
            if n <= 0 or n > 65536 or r <= 0 or r > 512 or p <= 0 or p > 32:
                message_exit(
                    "Error: the values of Scrypt parameters are not good")
            scrypt_params = ScryptParams(n, r, p)
        else:
            message_exit("one of n, r or p is not a number")
    else:
        scrypt_params = None

    try:
        return SigningKey.from_credentials(salt, password, scrypt_params)
    except ValueError as error:
        message_exit(error)
 def test_from_credentials(self):
     sign_key = SigningKey.from_credentials("alice", "password",
                                            ScryptParams())
     verify_key = VerifyingKey(sign_key.pubkey)
     self.assertEqual(verify_key.vk, sign_key.vk)