def get_encrypted_pin(self, clear_pin, card_number): """ Get PIN block in ISO 0 format, encrypted with the terminal key """ if not self.terminal_key: print('Terminal key is not set') return '' if self.pinblock_format == '01': try: pinblock = bytes.fromhex(get_pinblock(clear_pin, card_number)) #print('PIN block: {}'.format(raw2str(pinblock))) except TypeError: return '' encrypted_pinblock = self.tpk_cipher.encrypt(pinblock) return raw2str(encrypted_pinblock) else: print('Unsupported PIN Block format') return ''
def test_get_pinblock_invalid_data(self): self.assertEqual(get_pinblock('IDDQD', 'BBPE'), '')
def test_get_pinblock_length_5(self): self.assertEqual(get_pinblock('92389', '4000001234562'), '0592789fffedcba9')
def test_get_pinblock_length_4(self): self.assertEqual(get_pinblock('1234', '8998811234567890'), '0412bceedcba9876')
def test_get_pinblock_cardnumber_passed_as_int(self): self.assertEqual(get_pinblock('1234', 4000001234562000), '041234fedcba9dff')
def test_get_pinblock_pin_passed_as_int(self): self.assertEqual(get_pinblock(1234, '4000001234562000'), '041234fedcba9dff')
def test_get_pinblock_empty_pan(self): self.assertEqual(get_pinblock('1234', ''), None)
def test_get_pinblock_empty_pin(self): self.assertEqual(get_pinblock('', '4000001234562000'), None)