示例#1
0
    def test_tools_crypto_check_encryption(self):
        """Test check encryption (compare clear and encrypted values)"""

        salt_or_pepper = bytes('salt_or_pepper', 'utf-8')

        encrypted_data = encrypt('yolo')
        assert check_encryption('yolo', encrypted_data)
        assert not check_encryption('yoloooo', encrypted_data)

        encrypted_data = encrypt('yolo', salt=salt_or_pepper)
        assert check_encryption('yolo', encrypted_data)
        assert not check_encryption('yoloooo', encrypted_data)
示例#2
0
 def password(self, value):
     """Set password with a clear value which is immediatly hashed."""
     try:
         if value is not None:
             self._password = crypto.encrypt(value)
         else:
             # erase the old password
             self._password = None
     except (TypeError, ValueError) as exc:
         raise ValueError('Invalid password: {}'.format(str(exc)))
示例#3
0
    def test_tools_crypto_encrypt(self):
        """Test encryption"""

        salt_or_pepper = bytes('salt_or_pepper', 'utf-8')

        expected_encryption = (
            '$28$73616c745f6f725f70657070657252e6043b53a09e2725a8e12b04f60b83e'
            'b9bdd4544184b5ccc98b9dc878d5c0865a26743da91822882db461162326775d3'
            '68b7f570a3461a12e8bac699426e0e')

        encrypted_data = encrypt('yolo', salt=salt_or_pepper)
        assert encrypted_data == expected_encryption