Esempio n. 1
0
        private Boolean CheckCardCryptogram(ByteArray cardCryptogram, ByteArray terminalRandom, ByteArray cardRandom)
        {
            //ByteArray input = terminalRandom + cardRandom + new ByteArray("80 00 00 00 00 00 00 00");
            //ByteArray result = input.EncodeAsData(SessionKeys.AuthEncKey, new ByteArray(8), PaddingMode.None, CipherMode.CBC);
            //return cardCryptogram.Equals(result.LSB(8));


            ByteArray padding   = new ByteArray("80 00 00 00 00 00 00 00");
            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  = terminalRandom.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(cardRandom);
            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(cardCryptogram.Equals(result11));
        }