简体   繁体   English

3DES和DUKPT的Java实现,用于通过键盘仿真解密信用卡读取器数据?

[英]Java implementation of 3DES and DUKPT for decryption of credit card reader data through keyboard emulation?

We have an online key-in interface, and are support credit card swipe capability. 我们有一个在线键入界面,并且支持信用卡刷卡功能。 In the industry today, the card reader should encrypt the information before encoding it to ASCII, and then it is up to server-side to decrypt. 在当今的行业中,读卡器应该先对信息进行加密,然后再将其编码为ASCII,然后由服务器端进行解密。 (so the local machine never sees the card info) (因此本地计算机永远不会看到卡信息)

I am using MagTek card reader in keyboard emulation mode, and have it with the ANSI standard key injected for testing purposes. 我在键盘仿真模式下使用MagTek读卡器,并插入了ANSI标准密钥以进行测试。 Once decode & decryption successful, we'll get our own key registered with MagTek and order some production-use readers. 解码成功后,我们将在MagTek中注册自己的密钥,并订购一些生产用读卡器。

I know this decryption has been implemented before in C# and other languages, but need something in Java, or perhaps some other CLI-accessible program that can be included with a Java webapp. 我知道这种解密以前是用C#和其他语言实现的,但是需要Java或Java Webapp附带的其他一些可通过CLI访问的程序。 I am about to proceed with porting some C# code to Java, but first need to set up a C# environment. 我将继续将一些C#代码移植到Java,但首先需要设置一个C#环境。 (I've never done this before.) (我以前从未做过。)

Once I've ensured the C# version works well, then I know I can eliminate any errors during porting with my usual debugging techniques. 一旦确保C#版本运行良好,便知道可以使用常规调试技术消除移植期间的任何错误。

Before I go through all of this, if there is an easier way please let me know. 在进行所有这些操作之前,如果有更简单的方法,请告诉我。 I would think this has already been done in Java, but perhaps not... 我认为这已经在Java中完成,但也许还没有...

Partial answer, CW for anyone to add to. 部分答案,任何人都可以添加的CW。

First, it's not clear (to me) if you want to run on PCs or similar where the swipe devices are, possibly downloaded (like applet or webstart), or to just get the encrypted swipe data (in a webform?) and send it to your server to decrypt. 首先,(对我而言)尚不清楚,是要在可能下载了滑动设备的PC或类似设备上运行(例如applet或webstart),还是要获取加密的滑动数据(在Web表单中?)并发送它到您的服务器解密。 I suggest the latter makes PCI DSS compliance easier. 我建议后者使PCI DSS合规性更容易。

Java crypto certainly does 3DES , under the name DESede (case-insensitive, like all JCA Cipher names). Java crypto当然使用名称为DESede的3DES (不区分大小写,就像所有JCA Cipher名称一样)。 One slightly unobvious point: the implementation in SunJCE only handles full 24-byte keys. 一点不太明显的观点:SunJCE中的实现仅处理完整的24字节密钥。 DUKPT uses "2-key 3DES", so you need to copy "left" to bytes 0-7, "right" to 8-15, and "left" again to 16-23. DUKPT使用“ 2-key 3DES”,因此您需要将“ left”复制到字节0-7,将“ right”复制到字节8-15,再将“ left”复制到字节16-23。 If you use BouncyCastle (as my shop does) it can take a 16-byte key and do the copy internally, which is slightly more convenient. 如果您使用BouncyCastle(就像我的商店一样),则可以使用一个16字节的密钥并在内部进行复制,这稍微方便些。 (A symmetric key in Java is a byte array in a thin wrapper class, usually javax.crypto.spec.SecretKeySpec .) (Java中的对称密钥是瘦包装器类中的字节数组,通常是javax.crypto.spec.SecretKeySpec 。)

If you're not familiar with Java crypto in general, the pattern is that you obtain an "instance" of a particular algorithm or mode from a "provider" (you can specify one or let Java choose automatically; several are builtin and more can be added, like "bcprov" from www.BouncyCastle.org) using a generic API class Cipher , Signature , MessageDigest , etc, then initialize that instance with needed parameters (such as key or IV, and direction), then call methods to take input data and return output either in separate (possibly multiple) steps or in a simple combined doFinal (which is fine for your case). 如果您一般不熟悉Java加密,则模式是从“提供者”获得特定算法或模式的“实例”(您可以指定一个或让Java自动选择;内置几个,或者更多使用通用API类CipherSignatureMessageDigest等被添加,例如来自www.BouncyCastle.org的“ bcprov”,然后使用所需的参数(例如key或IV和direction)初始化该实例,然后调用要采用的方法输入数据并以单独(可能是多个)步骤或以简单的组合doFinal (适合您的情况)返回输出。 The JCA manual http://docs.oracle.com/javase/8/docs/technotes/guides/security/crypto/CryptoSpec.html#Cipher and javadoc for the applicable API class javax.crypto.Cipher (at http://docs.oracle.com/javase/8/docs/api/index.html and also automatically displayed in leading IDEs) has quite full details on this. 适用于API类javax.crypto.Cipher的JCA手册http://docs.oracle.com/javase/8/docs/technotes/guides/security/crypto/CryptoSpec.html#Cipher和javadoc(位于http:// docs.oracle.com/javase/8/docs/api/index.html并自动显示在领先的IDE中)对此有相当详细的信息。

I haven't seen any open/free implementation of DUKPT but that doesn't prove there isn't one. 我还没有看到DUKPT的任何开放/免费实现,但这并没有证明没有。 It is straightforward, though a bit tedious, to just code the steps from X9.24, if no one offers better. 如果没有人提供更好的代码,那么对X9.24中的步骤进行编码虽然很繁琐,但却很简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM