2016-05-17 278 views
0

我有一個Magtek uDynamo並試圖解密軌道1.我已經閱讀了下面的內容並理解了一點,但不知道如何實際解密數據。該供應商表示使用ANSI測試密鑰進行解密,但我無法找到任何相關信息。我有KSN,會話和序列號。我也嘗試了一些我發現的Java代碼,但它似乎不起作用。它返回null或可能我把錯誤的BDK。我只是使用了我在某處閱讀的序列號。我在Android上執行此操作。最好我希望代碼在服務器上運行,而不是在設備上運行,因此它會隨HTTPS一起在線上加密。根據ANSI X9.24第1部分標準解密3DES DUKPT

How ciphertext was generated in card reader using DUKPT encryption?

3DES-DUKPT (CBC) decryption confirmation

https://github.com/yinheli/dukpt/blob/master/src/main/java/com/yinheli/tool/DukptDecrypt.java

更新 我期待解密按照ANSI X9.24部分3DES DUKPT 1標準

我使用這個https://github.com/camcima/dukpt-php/tree/e8fceb4df8757e7e097c435221b4e93e097d3c9f

我不得不更新文件,並確保我得到最新的phpseclib,它運行但數據出來像C 4A fr (Wb f 7z n: w 9 , f7 ,m = z CRW

我必須缺少一些東西。我試過不同的模式,我試圖尋找編碼。如果您有解決方案或想法,請告訴我。此外他們的測試數據不工作,所以我不知道的區別是

代碼,我的根在運行的index.php礦和他們之間是什麼:

include 'vendor/autoload.php'; 

use DUKPT\DerivedKey; 
use DUKPT\KeySerialNumber; 
use DUKPT\Utility; 

$encryptedHexData = 'de8bfe769dca885cf3cc312135fe2cccfacf176235f4bdee773d1865334315ed2aefcab613f1884b5d63051703d5a0e2bd5d1988eeabe641bd5d1988eeabe641'; 
$ksn = '0117e00027'; 
$bdk = 'ABCDEFFEDCBA'; 

$key = new KeySerialNumber($ksn); 
$encryptionKey = DerivedKey::calculateDataEncryptionRequestKey($key, $bdk); 
$actual = Utility::hex2bin(Utility::removePadding(Utility::tripleDesDecrypt($encryptedHexData, $encryptionKey, true))); 


echo $encryptionKey.'<br />'; 

echo $actual.'<br /><br />'; 
+0

[這篇博客](https://www.parthenonsoftware.com/blog/how-to-decrypt-magnetic-stripe-scanner-data-with-dukpt)在過去幫助我。 –

+0

我剛剛嘗試了這個http://57f4dad48e7a4f7cd171c654226feb5a.proxysheep.com/questions/32536045/how-to-decode-dukpt-cbc-mode-in-java,但是如何獲得信用卡號碼,謝謝 – user1054513

+0

你現在指的是如何傳遞一個track1? Track1在[wiki](https://en.wikipedia.org/wiki/Magnetic_stripe_card)中有描述 –

回答

0

有了正確的BDK和KSN所有你現在需要做的就是嘗試不同的模式。

現在你正在使用DerivedKey::calculateDataEncryptionRequestKey($key, $bdk);

你需要嘗試其他模式找出哪一個設備使用。這是我用來爲我的設備找到正確結果的代碼。

include 'vendor/autoload.php'; 

use DUKPT\DerivedKey; 
use DUKPT\KeySerialNumber; 
use DUKPT\Utility; 

$encryptedHexData = 'C25C1D1197D31CAA87285D59A892047426D9182EC11353C051ADD6D0F072A6CB3436560B3071FC1FD11D9F7E74886742D9BEE0CFD1EA1064C213BB55278B2F12'; 
$ksn = 'FFFFE00008'; 
$bdk = 'ABCDEFFEDCBA'; 

$key = new KeySerialNumber($ksn); 

$encryptionKey = DerivedKey::calculatePinEncryptionKey($key, $bdk); 
$decryptedOutput = Utility::hex2bin(Utility::tripleDesDecrypt($encryptedHexData, $encryptionKey, true)); 
echo '<br /><br />Pin Encryption Key: '.$encryptionKey; 
echo '<br />Decrypted Output: '.$decryptedOutput; 

$encryptionKey = DerivedKey::calculateMacRequestKey($key, $bdk); 
$decryptedOutput = Utility::hex2bin(Utility::tripleDesDecrypt($encryptedHexData, $encryptionKey, true)); 
echo '<br /><br />Mac Request Key: '.$encryptionKey; 
echo '<br />Decrypted Output: '.$decryptedOutput; 

$encryptionKey = DerivedKey::calculateMacResponseKey($key, $bdk); 
$decryptedOutput = Utility::hex2bin(Utility::tripleDesDecrypt($encryptedHexData, $encryptionKey, true)); 
echo '<br /><br />Mac Response Key: '.$encryptionKey; 
echo '<br />Decrypted Output: '.$decryptedOutput; 

$encryptionKey = DerivedKey::calculateDataEncryptionRequestKey($key, $bdk); 
$decryptedOutput = Utility::hex2bin(Utility::tripleDesDecrypt($encryptedHexData, $encryptionKey, true)); 
echo '<br /><br />Data Encryption Request Key: '.$encryptionKey; 
echo '<br />Decrypted Output: '.$decryptedOutput; 

$encryptionKey = DerivedKey::calculateDataEncryptionResponseKey($key, $bdk); 
$decryptedOutput = Utility::hex2bin(Utility::tripleDesDecrypt($encryptedHexData, $encryptionKey, true)); 
echo '<br /><br />Data Encryption Response Key: '.$encryptionKey; 
echo '<br />Decrypted Output: '.$decryptedOutput; 

因此,對於此BDK和KSN,下面是結果輸出。

Pin Encryption Key: 27F66D5244FF621EAA6F6120EDEB427F 
Decrypted Output: %B5452300551227189^HOGAN/PAUL ^000000725000000? 

Mac Request Key: 27F66D5244FF9DE1AA6F6120EDEBBD80 
Decrypted Output: W����U�P�TfB/`����þ&��f��3y;�U�Zy��UK�[��s�;�>�[�b 

Mac Response Key: 27F66D52BBFF62E1AA6F612012EB4280 
Decrypted Output: b�K2a�S0��9�Mb-����*L�J���� ��s�\���H�����=���e�]�,���Hwq� 

Data Encryption Request Key: C39B2778B058AC376FB18DC906F75CBA 
Decrypted Output: RA]�ԅⱰQ���'v}b��h��St�����?� lu/�ٵ�P��!���6�� � 

Data Encryption Response Key: 846E267CB822197406DA2B161191C6E4 
Decrypted Output: ��,�B^FZ�� ςs�c���*E�4��0��ǂ}����6`-P�b�ʞ̳aصĬ�&���+��