예제 #1
0
    def _encrypt_with_simple_padding(self, message):
        """
        Encrypts passwords the way we used to
        """
        secret_key_bytes = settings.SECRET_KEY.encode('ascii')
        aes_key = simple_pad(secret_key_bytes, AES_BLOCK_SIZE)[:AES_KEY_MAX_LEN]
        aes = AES.new(aes_key, AES.MODE_ECB)

        message_bytes = message.encode('utf8')
        plaintext_bytes = simple_pad(message_bytes, AES_BLOCK_SIZE)
        ciphertext_bytes = aes.encrypt(plaintext_bytes)
        b64ciphertext_bytes = b64encode(ciphertext_bytes)
        return b64ciphertext_bytes.decode('ascii')
예제 #2
0
 def test_ascii_bytestring_default_char(self):
     padded = simple_pad(b'xyzzy', 8)
     self.assertEqual(padded, b'xyzzy   ')
예제 #3
0
 def test_nonascii(self):
     """
     pad should pad a string according to its size in bytes, not its length in letters.
     """
     padded = simple_pad(b'xy\xc5\xba\xc5\xbay', 8, b'*')
     self.assertEqual(padded, b'xy\xc5\xba\xc5\xbay*')
예제 #4
0
 def test_assertion(self):
     with self.assertRaises(AssertionError):
         simple_pad('xyzzy', 8, b'*')