Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXCEPTION : Length of the data to decrypt is invalid. #8

Closed
SaddamBInSyed opened this issue Dec 3, 2014 · 8 comments
Closed

EXCEPTION : Length of the data to decrypt is invalid. #8

SaddamBInSyed opened this issue Dec 3, 2014 · 8 comments

Comments

@SaddamBInSyed
Copy link

var decBytes = Dukpt.Decrypt(bdk, ksn, BigInt.FromHex( TRACK ).GetBytes());

where TRACK data is 70 characters length. and i am getting exception in

public static BigInteger Transform() function.

exactly in this line - return BigInt.FromBytes(crypto.TransformFinalBlock(data, 0, data.Length));

Kindly help me to solve this issue.

@sgbj
Copy link
Owner

sgbj commented Dec 4, 2014

For better assistance, please provide a full stack trace of the error, and if at all possible the track that you're attempting to decrypt. Does this error always occur, even for other cards? If so, then this implementation of DUKPT may be incompatible with the swiper you're using.

@SaddamBInSyed
Copy link
Author

Hi sgbj,

Here the full description of what i am trying..

Decryption of a three track ABA card with the original encryption format.
SecureMag Reader with default settings
Original encryption format can be recognized because the high bit of the fourth byte
underlined (00) is 0.

027D01003F48236B252A343236362A2A2A2A2A2A2A2A393939395E42555348204A
522F47454F52474520572E4D525E2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2
A2A2A2A2A2A2A2A2A2A2A2A2A2A3F2A3B343236362A2A2A2A2A2A2A2A3939
39393D2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A3F2A3B3333333333333333333337
363736373630373037303737363736373633333333333333333333373637363736303730
373037373637363736333333333333333333333736373637363037303730373736373637
3633333333333333333333373637363736303730373F32863E9E3DA28E455B28F7736
B77E47A64EDDA3BF03A06E44F31D1818C0BCD7A353FB1AD70EFD30FFC3DA08
A4FBC9372E57E8B40848BAEAA3FE724B3550E2F4B223E6BF264BEAE9E39142B6
48CDB51FB8DAF8EA5B63913D29419B67582FCCCE9B372660F03668CC453216D9
449C6B67EF33418AC88F65E1DB7ED4D10973F99DFC8463FF6DF113B6226C4898A
9D355057ECAF11A5598F02CA3162994901190000000001399F03

STX, Length (LSB, MSB), card type, track status, length track 1, length track 2, length
track 3

02 7D01 00 3F 48 23 6B
The above broken down and interpreted
02—STX character
7D—low byte of total length
01—high byte of total length
00—card type byte (interpretation old format ABA card)
3F—3 tracks of data all good
48—track 1 clear/mask data length
23—track 2 clear/mask data length
6B— track 3 clear/mask data length

Track 1 data masked (length 0x48)
252A343236362A2A2A2A2A2A2A2A393939395E42555348204A522F47454F5247452
0572E4D525E2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2
A2A2A2A2A2A2A3F2A

Track 2 data in hex masked (length 0x23)
3B343236362A2A2A2A2A2A2A2A393939393D2A2A2A2A2A2A2A2A2A2A2A2A2
A2A2A3F2A

Track 3 data unencrypted (length 0x6B)
3B333333333333333333333736373637363037303730373736373637363333333333333
333333337363736373630373037303737363736373633333333333333333333373637363
73630373037303737363736373633333333333333333333373637363736303730373F32

Track 1 & 2 encrypted length 0x48+0x23 rounded up to 8 bytes =0x6B -> 0x70 (112
decimal)
863E9E3DA28E455B28F7736B77E47A64EDDA3BF03A06E44F31D1818C0BCD7A3
53FB1AD70EFD30FFC3DA08A4FBC9372E57E8B40848BAEAA3FE724B3550E2F4B
223E6BF264BEAE9E39142B648CDB51FB8DAF8EA5B63913D29419B67582FCCCE
9B372660F03668CC453216D9449C6B67EF3

Track 1 hashed
3418AC88F65E1DB7ED4D10973F99DFC8463FF6DF
Track 2 hashed
113B6226C4898A9D355057ECAF11A5598F02CA31
KSN
62994901190000000001
LRC, checksum and ETX
39 9F 03

Masked Data:

Track 1 data masked in ASCII:
%4266_9999^BUSH JR/GEORGE
W.MR^_
***********************?

Track 2 data masked in ASCII:
;4266*******9999=*************?

Track 3 data unencrypted in ASCII:
;33333333337676760707077676763333333333767676070707767676333333333376767
607070776767633333333337676760707?2

Key Value: F8 2A 7A 0D 7C 67 46 F1 96 18 9A FB 54 2C 65 A3

KSN: 62 99 49 01 19 00 00 00 00 01

Decrypted Data in ASCII:
%B4266841088889999^BUSH JR/GEORGE
W.MR^0809101100001100000000046000000?!;4266841088889999=080910110000046
?0
;33333333337676760707077676763333333333767676070707767676333333333376767
607070776767633333333337676760707?2

Decrypted Data in Hex:
2542343236363834313038383838393939395E42555348204A522F47454F52474520572
E4D525E303830393130313130303030313130303030303030303034363030303030303F
213B343236363834313038383838393939393D3038303931303131303030303034363F3
00000000000

Thats all.

In your DUKPT Tdes Decrypt code (which i downloaded here)
How to pass the value for TRACK argument..
that is ,

        var bdk = "0123456789ABCDEFFEDCBA9876543210";
        var ksn = "FFFF9876543210E00008";
        var track = " HERE WHICH TRACK I HAVE TO GIVE HERE EITHER TOTAL TRACK CODE              OR TRACK1 DATA";
        var decBytes = Dukpt.Decrypt(bdk, ksn, BigInt.FromHex(track).GetBytes());

If i pass the above track1data in this code , i got exception says EXCEPTION : Length of the data to decrypt is invalid as sme as previous question.

Waiting for your valuable reply

Thanks..

@ichoes
Copy link
Collaborator

ichoes commented Dec 5, 2014

Hi SaddamBInSyed,
For securemag you need to modify the code to use the securemag standard.
here is the link for the solution.
#7
#7

In track you can put either track1 or track2, If your card reader is not
set to enhanced mode, you will get track1 and track 2 combined.

*The code will decryrt it fine, you need to parse it after decryption. *

On Fri, Dec 5, 2014 at 11:11 AM, SaddamBInSyed notifications@github.com
wrote:

Hi sgbj,

Here the full description of what i am trying..

Decryption of a three track ABA card with the original encryption format.
SecureMag Reader with default settings
Original encryption format can be recognized because the high bit of the
fourth byte
underlined (00) is 0.

027D01003F48236B252A343236362A2A2A2A2A2A2A2A393939395E42555348204A
522F47454F52474520572E4D525E2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2
A2A2A2A2A2A2A2A2A2A2A2A2A2A3F2A3B343236362A2A2A2A2A2A2A2A3939
39393D2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A3F2A3B3333333333333333333337
363736373630373037303737363736373633333333333333333333373637363736303730
373037373637363736333333333333333333333736373637363037303730373736373637
3633333333333333333333373637363736303730373F32863E9E3DA28E455B28F7736
B77E47A64EDDA3BF03A06E44F31D1818C0BCD7A353FB1AD70EFD30FFC3DA08
A4FBC9372E57E8B40848BAEAA3FE724B3550E2F4B223E6BF264BEAE9E39142B6
48CDB51FB8DAF8EA5B63913D29419B67582FCCCE9B372660F03668CC453216D9
449C6B67EF33418AC88F65E1DB7ED4D10973F99DFC8463FF6DF113B6226C4898A
9D355057ECAF11A5598F02CA3162994901190000000001399F03

STX, Length (LSB, MSB), card type, track status, length track 1, length
track 2, length
track 3

02 7D01 00 3F 48 23 6B
The above broken down and interpreted
02—STX character
7D—low byte of total length
01—high byte of total length
00—card type byte (interpretation old format ABA card)
3F—3 tracks of data all good
48—track 1 clear/mask data length
23—track 2 clear/mask data length
6B— track 3 clear/mask data length

Track 1 data masked (length 0x48)
252A343236362A2A2A2A2A2A2A2A393939395E42555348204A522F47454F5247452
0572E4D525E2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2
A2A2A2A2A2A2A3F2A

Track 2 data in hex masked (length 0x23)
3B343236362A2A2A2A2A2A2A2A393939393D2A2A2A2A2A2A2A2A2A2A2A2A2
A2A2A3F2A

Track 3 data unencrypted (length 0x6B)
3B333333333333333333333736373637363037303730373736373637363333333333333
333333337363736373630373037303737363736373633333333333333333333373637363
73630373037303737363736373633333333333333333333373637363736303730373F32

Track 1 & 2 encrypted length 0x48+0x23 rounded up to 8 bytes =0x6B -> 0x70
(112
decimal)
863E9E3DA28E455B28F7736B77E47A64EDDA3BF03A06E44F31D1818C0BCD7A3
53FB1AD70EFD30FFC3DA08A4FBC9372E57E8B40848BAEAA3FE724B3550E2F4B
223E6BF264BEAE9E39142B648CDB51FB8DAF8EA5B63913D29419B67582FCCCE
9B372660F03668CC453216D9449C6B67EF3

Track 1 hashed
3418AC88F65E1DB7ED4D10973F99DFC8463FF6DF
Track 2 hashed
113B6226C4898A9D355057ECAF11A5598F02CA31
KSN
62994901190000000001
LRC, checksum and ETX
39 9F 03

Masked Data:

Track 1 data masked in ASCII:
%
4266_9999^BUSH JR/GEORGE W.MR
http://W.MR^_
***********************?

Track 2 data masked in ASCII:
;4266*******9999=*************?

Track 3 data unencrypted in ASCII:
;33333333337676760707077676763333333333767676070707767676333333333376767
607070776767633333333337676760707?2

Key Value: F8 2A 7A 0D 7C 67 46 F1 96 18 9A FB 54 2C 65 A3

KSN: 62 99 49 01 19 00 00 00 00 01

Decrypted Data in ASCII:
%B4266841088889999^BUSH JR/GEORGE
W.MR^0809101100001100000000046000000?!;4266841088889999=080910110000046
?0
;33333333337676760707077676763333333333767676070707767676333333333376767
607070776767633333333337676760707?2

Decrypted Data in Hex:
2542343236363834313038383838393939395E42555348204A522F47454F52474520572
E4D525E303830393130313130303030313130303030303030303034363030303030303F
213B343236363834313038383838393939393D3038303931303131303030303034363F3
00000000000

Thats all.

In your DUKPT Tdes Decrypt code (which i downloaded here)
How to pass the value for TRACK argument..
that is ,

    var bdk = "0123456789ABCDEFFEDCBA9876543210";
    var ksn = "FFFF9876543210E00008";
    var track = " HERE WHICH TRACK I HAVE TO GIVE HERE EITHER TOTAL TRACK CODE              OR TRACK1 DATA";
    var decBytes = Dukpt.Decrypt(bdk, ksn, BigInt.FromHex(track).GetBytes());

If i pass the above track1data in this code , i got exception says
EXCEPTION : Length of the data to decrypt is invalid as sme as previous
question.

Waiting for your valuable reply

Thanks..


Reply to this email directly or view it on GitHub
#8 (comment).

Rafael Gonzalez
Developer
www.emobilepos.com

@SaddamBInSyed
Copy link
Author

@ Ichoes Thank you very much for valuable reply.

I will try this and come back..

@SaddamBInSyed
Copy link
Author

@ichoes
can you send me the full implementation code.

It would be nice if u can do so.

My mail id : saddam.2290@gmail.com

@SaddamBInSyed
Copy link
Author

Hi ichoes,
I have copied the CreateSessionKey() from your post and while running
I go the exception says "Specified key is not a valid size for this algorithm"

in transform() function

pls help me

@SaddamBInSyed
Copy link
Author

Worked nicely.

Thanks all for your support....

Bye

@SaddamBInSyed
Copy link
Author

Hi ..

I have successfully done the decrypt and encrypt operation. now i need the CVV number for to disply into the GUI.

How can i get the CVV number for IDTech SecureMag Reader..

Kindly help me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants