hosseinmd / data-crypto

DES, 3DES (Triple DES) and Pin Block
7 stars 7 forks source link

Possibly wrong digit in `pinBlockFormat0` #10

Open fangyibkk opened 3 years ago

fangyibkk commented 3 years ago

Hello there. I'm trying out this sample.

pinBlockFormat0('000456789012345','8482' )
// expecting 0484C79876FEDCBA

but it turns out to be not that value

I think

const preparedPAN = PAN.slice(3, 15).padStart(16, "0");

might possibly be

const preparedPAN = PAN.slice(4, 16).padStart(16, "0");

or just shorthand slice(-12)

Please help me check if I misunderstood something. Thanks and cheers.

References: http://icma.com/wp-content/uploads/2015/07/PinBlockFormats_SE1-15CM.pdf https://en.wikipedia.org/wiki/ISO_9564#PIN_length

superarts commented 1 year ago

Yea I think so too, and there's another problem: PAN isn't necessarily always 16 digits. According to EFTlab:

2. Prepare PAN – take 12 rightmost digits of the primary account number (excluding the check digit)

And in their example, they were using 19 digits PAN. Similar problems exist in pinBlockFormat3 too.

I think it might be possible that the 16th digit was considered to be the "check digit", however, I cannot find any information regarding the check digit in PAN. Also, ETFLab's example seems to treat 876543210987 as the "12 rightmost digits of the primary account number", which doesn't contain the check digit.

PIN blocks: PIN block encrypt operation finished
****************************************
PAN:            43219876543210987
PIN:            1234
PAD:            N/A
Format:         Format 3 (ISO-3)
—————————————-
Clear PIN block:3412ACC9B98CDF43

Questions above should be clarified from ISO PDFs but unfortunately I don't have access to them yet.

hosseinmd commented 1 year ago

I agree, but I don't have time. Code base is simple, please make PR.

superarts commented 1 year ago

Thanks for comfirming! @fangyibkk I have a different implementation of PIN block ISO-0, 1, 2, 3, feel free to try it out: https://www.superarts.org/KTPinBlock/