Beispiel #1
0
        private ByteArray GenerateExAuthMAC2(ByteArray command, ByteArray terminalCryptogram)
        {
            ByteArray input = command.Extract(0, 5) + terminalCryptogram + new ByteArray("80 00 00");

            ByteArray mac_key_left  = _sessionKeys.SignKey.MSB(8); //MSB mac key
            ByteArray mac_key_right = _sessionKeys.SignKey.LSB(8);
            ByteArray iv            = new ByteArray(8, 0x00);

            //ByteArray result = input.EncodeAsData(SessionKeys.SignKey, new ByteArray(8), PaddingMode.None, CipherMode.CBC);
            //ByteArray result = input.EncodeAsData(mac_key_left + mac_key_right, iv, PaddingMode.None, CipherMode.CBC);
            //ByteArray result_comp = result.LSB(8);

            ByteArray apdu_left  = input.MSB(8);
            ByteArray apdu_right = input.LSB(8);

            ByteArray result1 = apdu_left.SimpleEncodeAsData(mac_key_left, iv, PaddingMode.None, CipherMode.CBC);
            ByteArray result2 = result1.XOR(apdu_right);
            ByteArray result3 = result2.SimpleEncodeAsData(mac_key_left, iv, PaddingMode.None, CipherMode.CBC);
            ByteArray result4 = result3.SimpleDecodeAsData(mac_key_right, iv, PaddingMode.None, CipherMode.CBC);
            ByteArray result5 = result4.SimpleEncodeAsData(mac_key_left, iv, PaddingMode.None, CipherMode.CBC);

            Logger.Log("[JavaCard] Wyliczanie MAC dla APDU {0} (kolejne wyniki algorytmu DES)\n{1}\n{2}\n{3}\n{4}\n{5}", input, result1, result2, result3, result4, result5);

            return(result5);
        }
Beispiel #2
0
        private ByteArray GenerateTerminalCryptogram(ByteArray terminalRandom, ByteArray cardRandom)
        {
            ByteArray padding = new ByteArray("80 00 00 00 00 00 00 00");

            //ByteArray input = cardRandom + terminalRandom + padding;
            //ByteArray result = input.EncodeAsData(SessionKeys.AuthEncKey, new ByteArray(8, 0x00), PaddingMode.None, CipherMode.CBC);
            //return result.LSB(8);

            ByteArray key_left  = _sessionKeys.AuthEncKey.MSB(8); //MSB mac key
            ByteArray key_right = _sessionKeys.AuthEncKey.LSB(8);
            ByteArray iv        = new ByteArray(8, 0x00);

            ByteArray result1  = cardRandom.SimpleEncodeAsData(key_left, iv, PaddingMode.None, CipherMode.CBC);
            ByteArray result2  = result1.SimpleDecodeAsData(key_right, iv, PaddingMode.None, CipherMode.CBC);
            ByteArray result3  = result2.SimpleEncodeAsData(key_left, iv, PaddingMode.None, CipherMode.CBC);
            ByteArray result4  = result3.XOR(terminalRandom);
            ByteArray result5  = result4.SimpleEncodeAsData(key_left, iv, PaddingMode.None, CipherMode.CBC);
            ByteArray result6  = result5.SimpleDecodeAsData(key_right, iv, PaddingMode.None, CipherMode.CBC);
            ByteArray result7  = result6.SimpleEncodeAsData(key_left, iv, PaddingMode.None, CipherMode.CBC);
            ByteArray result8  = result7.XOR(padding);
            ByteArray result9  = result8.SimpleEncodeAsData(key_left, iv, PaddingMode.None, CipherMode.CBC);
            ByteArray result10 = result9.SimpleDecodeAsData(key_right, iv, PaddingMode.None, CipherMode.CBC);
            ByteArray result11 = result10.SimpleEncodeAsData(key_left, iv, PaddingMode.None, CipherMode.CBC);

            Logger.Log("[JavaCard] Wyliczanie terminal Cryptogram (kolejne wyniki algorytmu DES)\n{0}\n{1}\n{2}\n{3}\n{4}\n{5}\n{6}\n{7}\n{8}\n{9}\n{10}", result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11);

            return(result11);
        }