[Solved] How can i convert java byte array to hexadecimal array in java


There doesn’t appear to be a problem. Java understands hexadecimal notation: it’s okay to write

eg = new CommandAPU(new byte[] {(byte)0x80, (byte)0xCA, (byte)0x9F, 0x7F, 0x00});

Your problem is probably the colon :

Colons are used for “labeling” code, so that the JVM can go to that point and keep running. That is, because eg is now a label, it can point to the CONSTRUCTOR for CommandAPU, which is code, but not the OBJECT made by CommandAPU(byte[] ), which are data.

What you need is to make a variable that can point to a CommandAPU object:

CommandAPU eg;

Then call the constructor, which makes an object. It returns a pointer that goes to the object’s place in memory, so make eg point there, too:

eg = new CommandAPU(stuff);

You can now use eg wherever you need a CommandAPU.

However… you want to use the SCardTransmit function, yes? C# can deal with Windows DLLs well (or so I’ve read), but Java is apparently quite tricky… You can try reading how to do it all in Java. You can possibly move the byte array from your Java code to your C#, but I don’t think it’s sane to move a finished object from the JVM to an external program.

That said it kind of looks like you can do Card IO entirely from Java! How exciting. I’ve trudged blindly up the Java Constructor Chain™, and this is what I found. Deep breath:

myChannel = javax.smartcardio.TerminalFactory.getDefault().terminals().getTerminal(theNameOfTheTerminal).connect(theProtocolToUse).getBasicChannel();

breath again

Assuming you filled in the arguments right and a million things didn’t go wrong, you can then use

myChannel.transmit(eg);

to do whatever. Unless you already have an instance of the relevant CardChannel.

As a final note, this website is meant to be a place to ask new questions, not a forum. Your question (or rather, your errors), have likely been solved elsewhere already. I understand it can be intimidating, facing the vast wall of resources, all written in English, but please seek help elsewhere first before coming here. Good luck!

solved How can i convert java byte array to hexadecimal array in java