PIN Data problem

46 views
Skip to first unread message

ricmoore

unread,
Nov 14, 2006, 5:38:50 AM11/14/06
to jPOS Users
Hi Guys,
Am having problem while decryting an encryted PIN block

I have the Key = 385BA420FD26F4D5
I have a Pin Block from Field 52=7C28BD4AAD9E50C4

I receive this error why trying to decrypt. My question is what
determine the length of the result of encryttion or decrytion.

If I used 16hex key to encryt 16hex data what should be the length. Any
document of this will be appreciated.

The PIN Data above was encryted using 16Hex key

Please help

javax.crypto.BadPaddingException: Given final block not properly padded
at com.sun.crypto.provider.SunJCE_h.b(DashoA12275)
at com.sun.crypto.provider.SunJCE_h.b(DashoA12275)
at com.sun.crypto.provider.DESCipher.engineDoFinal(DashoA12275)
at javax.crypto.Cipher.doFinal(DashoA12275)

Alejandro Revilla

unread,
Nov 14, 2006, 6:06:25 AM11/14/06
to jpos-...@googlegroups.com
>
> Any document of this will be appreciated.
>
This is book is excellent: http://www.cl.cam.ac.uk/~rja14/book.html

You can download the free PDF but I highly recommend to buy the printed
one, the book is pure gold and it has a very understandable explanation
of DES and other encryption algorithms.

Then you've got the classic Applied Cryptography by Bruce Schneier which
is also very enjoyable and a must read.

BTW, DES is a block cipher, when you decrypt a block of 8 bytes you are
going to get 8 bytes of cleartext. The fact that you are representing
the block in hex using 16 bytes is probably some source for confusion,
you may want to convert them to byte[] using ISOUtil.hex2byte(String)
before attempting to decrypt.


ricmoore

unread,
Nov 14, 2006, 7:16:44 AM11/14/06
to jPOS Users
I still don't understand what you mean.

Can I decrypt this


I have the Key = 385BA420FD26F4D5
I have a Pin Block from Field 52=7C28BD4AAD9E50C4

If yes can u help with code

Regards

On Nov 14, 12:06 pm, Alejandro Revilla <a...@jpos.org> wrote:
> > Any document of this will be appreciated.This is book is excellent:http://www.cl.cam.ac.uk/~rja14/book.html

Mark Salter

unread,
Nov 14, 2006, 8:13:29 AM11/14/06
to jPOS Users
On Nov 14, 12:16 pm, "ricmoore" <richard.omon...@gmail.com> wrote:
> I still don't understand what you mean.

Please excuse me leaping in here...

So you read through all of the really helpful references provided by
Alejandro and still don't understand, or is it his reference to your
potential hex/binary misunderstanding that is confusing you?

>
> Can I decrypt this
> I have the Key = 385BA420FD26F4D5
> I have a Pin Block from Field 52=7C28BD4AAD9E50C4

Do you know the PIN block algorithm (or format) that this PIN block was
made using?

Your key length (8 bytes) indicates DES rather than triple DES, but
this might not be the case.

> If yes can u help with code

Some made the PIN block, so the answer is "yes" we should be able to
undo the encryption given the keys and format.

> > On Nov 14, 12:06 pm, Alejandro Revilla <a...@jpos.org> wrote:
> > BTW, DES is a block cipher, when you decrypt a block of 8 bytes you are
> > going to get 8 bytes of cleartext. The fact that you are representing
> > the block in hex using 16 bytes is probably some source for confusion,
> > you may want to convert them to byte[] using ISOUtil.hex2byte(String)

> > before attempting to decrypt.- Hide quoted text -- Show quoted text -

Cryptographic functions will use binary data, hence you may need to
convert. Alejandro mentions this because a function will not complain
if it is expecting binary data of length 16 bytes and you provide 16
bytes of character data that /actually/ represents 8 binary bytes.

--
Mark

ricmoore

unread,
Nov 14, 2006, 9:50:55 AM11/14/06
to jPOS Users
The algorithm is DES

if i encryt 16Hex with 16Hex values what we be the length of the result

what is the convention


On Nov 14, 2:13 pm, "Mark Salter" <marksal...@dsl.pipex.com> wrote:
> On Nov 14, 12:16 pm, "ricmoore" <richard.omon...@gmail.com> wrote:
>

> > I still don't understand what you mean.Please excuse me leaping in here...


>
> So you read through all of the really helpful references provided by
> Alejandro and still don't understand, or is it his reference to your
> potential hex/binary misunderstanding that is confusing you?
>
>
>
> > Can I decrypt this
> > I have the Key = 385BA420FD26F4D5

> > I have a Pin Block from Field 52=7C28BD4AAD9E50C4Do you know the PIN block algorithm (or format) that this PIN block was


> made using?
>
> Your key length (8 bytes) indicates DES rather than triple DES, but
> this might not be the case.
>

> > If yes can u help with codeSome made the PIN block, so the answer is "yes" we should be able to


> undo the encryption given the keys and format.
>
> > > On Nov 14, 12:06 pm, Alejandro Revilla <a...@jpos.org> wrote:
> > > BTW, DES is a block cipher, when you decrypt a block of 8 bytes you are
> > > going to get 8 bytes of cleartext. The fact that you are representing
> > > the block in hex using 16 bytes is probably some source for confusion,
> > > you may want to convert them to byte[] using ISOUtil.hex2byte(String)

> > > before attempting to decrypt.- Hide quoted text -- Show quoted text -Cryptographic functions will use binary data, hence you may need to

ricmoore

unread,
Nov 14, 2006, 9:51:37 AM11/14/06
to jPOS Users
PIN Block format is FORMAT0

On Nov 14, 2:13 pm, "Mark Salter" <marksal...@dsl.pipex.com> wrote:

> On Nov 14, 12:16 pm, "ricmoore" <richard.omon...@gmail.com> wrote:
>

> > I still don't understand what you mean.Please excuse me leaping in here...


>
> So you read through all of the really helpful references provided by
> Alejandro and still don't understand, or is it his reference to your
> potential hex/binary misunderstanding that is confusing you?
>
>
>
> > Can I decrypt this
> > I have the Key = 385BA420FD26F4D5

> > I have a Pin Block from Field 52=7C28BD4AAD9E50C4Do you know the PIN block algorithm (or format) that this PIN block was


> made using?
>
> Your key length (8 bytes) indicates DES rather than triple DES, but
> this might not be the case.
>

> > If yes can u help with codeSome made the PIN block, so the answer is "yes" we should be able to


> undo the encryption given the keys and format.
>
> > > On Nov 14, 12:06 pm, Alejandro Revilla <a...@jpos.org> wrote:
> > > BTW, DES is a block cipher, when you decrypt a block of 8 bytes you are
> > > going to get 8 bytes of cleartext. The fact that you are representing
> > > the block in hex using 16 bytes is probably some source for confusion,
> > > you may want to convert them to byte[] using ISOUtil.hex2byte(String)

> > > before attempting to decrypt.- Hide quoted text -- Show quoted text -Cryptographic functions will use binary data, hence you may need to

Andy Orrock

unread,
Nov 14, 2006, 10:11:25 AM11/14/06
to jpos-...@googlegroups.com
I don't get your goal here.

You say:

"if i encryt 16Hex with 16Hex values what we be the length of the result"

That seems to imply you want to do a PIN translation. Are you looking to
decrypt or translate?

BTW: reading you terse notes, I have no idea if...

- you're using hardware or software.

- that's the clear key or the MFK-encrypted cryptogram.

- you're Master Session or DUKPT (I guess Master Session).

Have you read this...

http://www.aci.net/Kalliste/des.htm

...or the other info supplied by Alejandro?

ricmoore

unread,
Nov 14, 2006, 10:11:32 AM11/14/06
to jPOS Users
Yes Mark
the key is 385BA420FD26F4D5
The PIN Data:7C28BD4AAD9E50C4
The Block Format is FORMAT0
Algorithm is DES

I need to get something here

On Nov 14, 2:13 pm, "Mark Salter" <marksal...@dsl.pipex.com> wrote:

> On Nov 14, 12:16 pm, "ricmoore" <richard.omon...@gmail.com> wrote:
>

> > I still don't understand what you mean.Please excuse me leaping in here...


>
> So you read through all of the really helpful references provided by
> Alejandro and still don't understand, or is it his reference to your
> potential hex/binary misunderstanding that is confusing you?
>
>
>
> > Can I decrypt this
> > I have the Key = 385BA420FD26F4D5

> > I have a Pin Block from Field 52=7C28BD4AAD9E50C4Do you know the PIN block algorithm (or format) that this PIN block was


> made using?
>
> Your key length (8 bytes) indicates DES rather than triple DES, but
> this might not be the case.
>

> > If yes can u help with codeSome made the PIN block, so the answer is "yes" we should be able to


> undo the encryption given the keys and format.
>
> > > On Nov 14, 12:06 pm, Alejandro Revilla <a...@jpos.org> wrote:
> > > BTW, DES is a block cipher, when you decrypt a block of 8 bytes you are
> > > going to get 8 bytes of cleartext. The fact that you are representing
> > > the block in hex using 16 bytes is probably some source for confusion,
> > > you may want to convert them to byte[] using ISOUtil.hex2byte(String)

> > > before attempting to decrypt.- Hide quoted text -- Show quoted text -Cryptographic functions will use binary data, hence you may need to

chhil

unread,
Nov 14, 2006, 10:12:01 AM11/14/06
to jpos-...@googlegroups.com

Need to know your pinblock format.
Need to know your pin working key. Was the key you provided used for encrypting the pinblock? I tried decrypting it and got a string of hex characters. If the pinblocks were OEM1 or ISO-0 I could have figured out the pin by looking at it, but this wasn't the case.

http://jpos.org/wiki/HSM_basics there is a url that has the various alogorithms that can be used to form a pinblock..

Procedure would be to decrypt the pinblock with the pin working key and then reverse engineer the clear pinblock to get the pin.

-chhil

chhil

unread,
Nov 14, 2006, 10:13:14 AM11/14/06
to jpos-...@googlegroups.com
If this is a test transaction, what pin was used?

-chhil

On 11/14/06, ricmoore <richard...@gmail.com > wrote:

ricmoore

unread,
Nov 14, 2006, 10:43:05 AM11/14/06
to jPOS Users
the pin was 0000. please i will apprevciate sample code cause it giving
problem here is like my code is not correct.

I got 0000000000000000A913F4CB0BD30F97
when I encryt 8787878787878787 with this 0E329232EA6D0D73 according to
http://www.aci.net/Kalliste/des.htm
meanwhile the url says the result is 0000000000000000

The Key=385BA420FD26F4D5
PIN Data=7C28BD4AAD9E50C4
FORMAT=ISO-0
ALG:DES
The PIN:0000

I will appreciate you code sample.

On Nov 14, 4:13 pm, chhil <chil...@gmail.com> wrote:
> If this is a test transaction, what pin was used?
>
> -chhil
>

> > > Mark- Hide quoted text -- Show quoted text -

chhil

unread,
Nov 14, 2006, 10:45:56 AM11/14/06
to jpos-...@googlegroups.com
One additional piece missing is the pan..can you provide that...
Maybe you could post your code so we can look at it and see what could possibly be wrong...rather than the other way around :-)

-chhil

On 11/14/06, ricmoore <richard...@gmail.com> wrote:

ricmoore

unread,
Nov 14, 2006, 11:13:11 AM11/14/06
to jPOS Users
The PAN is :9333300100100000

The main class

byte[] bv
=secapi.crypto(ISOUtil.hex2byte("7C28BD4AAD9E50C4"),ISOUtil.hex2byte("385BA420FD26F4D5"),"DES",1);
System.out.println("Raw:"+new String(bv));

The class body for secapi:
public Key formDESkey(byte[] clearKeyBytes,String alg)
{
Key key = null;
key = new SecretKeySpec(clearKeyBytes, alg);
return key;
}
public byte[] crypto(byte[] data,byte[] key, String algorithm,int
mode)
{
byte[] result = null;
try{
System.out.println("Data in:"+new String(data)+",key:"+new
String(key));
Key nkey = formDESkey(key, algorithm);
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(mode == 0 ? Cipher.ENCRYPT_MODE :
Cipher.DECRYPT_MODE,nkey);
result = cipher.doFinal(data);
System.out.println("Result in
Hex:"+ISOUtil.hexString(result));
}catch(Exception ee)
{
System.out.println("crypto Error :"+ee);
ee.printStackTrace();
}
return result;
}
----

On Nov 14, 4:45 pm, chhil <chil...@gmail.com> wrote:
> One additional piece missing is the pan..can you provide that...
> Maybe you could post your code so we can look at it and see what could
> possibly be wrong...rather than the other way around :-)
>
> -chhil
>

> > > > > Mark- Hide quoted text -- Show quoted text -- Hide quoted text -- Show quoted text -

chhil

unread,
Nov 14, 2006, 1:59:54 PM11/14/06
to jpos-...@googlegroups.com
I changed a couple of things...not sure what the difference is but it does not throw the exception anymore..

In formDESkey...
key = new SecretKeySpec(clearKeyBytes, algorithm); //here I used algo = "DES"
In crypto
Cipher cipher = Cipher.getInstance(algorithm);//here I used algo  = "DES/ECB/NoPadding"

I would be interested in knowing what the difference is so if any crypto gurus know the reasoning do let me know.

-chhil

On 11/14/06, ricmoore <richard...@gmail.com> wrote:

The PAN is :9333300100100000

The main class

byte[] bv
=secapi.crypto(ISOUtil.hex2byte("7C28BD4AAD9E50C4"),ISOUtil.hex2byte("385BA420FD26F4D5"),"DES",1);
            System.out.println ("Raw:"+new String(bv));

ricmoore

unread,
Nov 14, 2006, 3:39:06 PM11/14/06
to jPOS Users
Thanks any method in jpos to translate PIN block

regards

On Nov 14, 7:59 pm, chhil <chil...@gmail.com> wrote:
> I changed a couple of things...not sure what the difference is but it does
> not throw the exception anymore..
>
> In formDESkey...
> key = new SecretKeySpec(clearKeyBytes, algorithm); //here I used algo =
> "DES"
> In crypto
> Cipher cipher = Cipher.getInstance(algorithm);//here I used algo =
> "DES/ECB/NoPadding"
>
> I would be interested in knowing what the difference is so if any crypto
> gurus know the reasoning do let me know.
>
> -chhil
>

> On 11/14/06, ricmoore <richard.omon...@gmail.com> wrote:
>
>
>
>
>
> > The PAN is :9333300100100000
>
> > The main class
>
> > byte[] bv
> > =secapi.crypto(ISOUtil.hex2byte("7C28BD4AAD9E50C4"),ISOUtil.hex2byte

> > ("385BA420FD26F4D5"),"DES",1);

> > System.out.println("Raw:"+new String(bv));

Alejandro Revilla

unread,
Nov 14, 2006, 4:01:58 PM11/14/06
to jpos-...@googlegroups.com
> In crypto
> Cipher cipher = Cipher.getInstance(algorithm);//here I used algo =
> "DES/ECB/NoPadding"
>
If you look at the bottom of
jpos6/modules/security/src/org/jpos/security/jceadapter/JCEHandler you
have:

String desMode = "ECB";
String desPadding = "NoPadding";

Thanks to Hani's effort I never had to pay attention to that, but it
seems that ECB mode and NoPadding is what the pinblock encryption
standard uses.

chhil

unread,
Nov 14, 2006, 4:24:21 PM11/14/06
to jpos-...@googlegroups.com
Thanks Alejandro...
May I should have first looked at the source than breaking my head over it :-)
-chhil

On 11/14/06, Alejandro Revilla < a...@jpos.org> wrote:

> In crypto
> Cipher cipher = Cipher.getInstance (algorithm);//here I used algo  =

ricmoore

unread,
Nov 15, 2006, 3:01:17 AM11/15/06
to jPOS Users
Thanks how do I translate a decryted PIN Block or reverse the PIN
Block.

I need to get the actual PIN.

What class should I use

On Nov 14, 10:24 pm, chhil <chil...@gmail.com> wrote:
> Thanks Alejandro...
> May I should have first looked at the source than breaking my head over it
> :-)
> -chhil
>
> On 11/14/06, Alejandro Revilla <a...@jpos.org> wrote:
>
>
>
>
>
> > > In crypto

> > > Cipher cipher = Cipher.getInstance(algorithm);//here I used algo =


> > > "DES/ECB/NoPadding"
>
> > If you look at the bottom of
> > jpos6/modules/security/src/org/jpos/security/jceadapter/JCEHandler you
> > have:
>
> > String desMode = "ECB";
> > String desPadding = "NoPadding";
>
> > Thanks to Hani's effort I never had to pay attention to that, but it
> > seems that ECB mode and NoPadding is what the pinblock encryption

> > standard uses.- Hide quoted text -- Show quoted text -

chhil

unread,
Nov 15, 2006, 9:25:18 AM11/15/06
to jpos-...@googlegroups.com
Please look at the security package available in jpos.
I doubt it that there will be any method available in the jpos security package that will allow you to get the pin in clear. You will probably have to write it yourself.

-chhil

Alejandro Revilla

unread,
Nov 15, 2006, 9:35:24 AM11/15/06
to jpos-...@googlegroups.com
There's a JCESecurityModule.calculatePIN that you can take as an example.

You can't use it from the outside, it's a private method (and I believe
that it's okay to stay private), but you can certainly pick some ideas
on how to implement it.

ricmoore

unread,
Nov 27, 2006, 8:53:06 AM11/27/06
to jPOS Users
Hi
Is there anything like DESede/ECB/NoPadding

Or how does one use not padding for DESede

Reply all
Reply to author
Forward
0 new messages