I coded my application in java in a first time and I should now coded it in javascript and I have some problems in the handling of string and arraybytes in javascript and recoding methods of conversion in both directions. Here is my java code:
public String VerifyPIN(String PIN, String successCb, String errorCb) {
byte[] AID = new byte[] {(byte)0xA0,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x04,(byte)0x10,(byte)0x10,(byte)0x11};
byte[] tmpPIN = new byte[] {(byte)0x00, (byte)0x20, (byte)0x00, (byte)0x80, (byte)0x08, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00};
System.arraycopy(PIN.getBytes(), 0, tmpPIN, 5, PIN.getBytes().length);
byte[] output = exchange(AID, tmpPIN);
String result = StringUtils.bytesToString(output);
if ("90 00".equals(result.trim())) {
//onSuccess()
} else {
//onError
}
return result.trim();
}
public String bytesToString(byte[] bytes) {
if (bytes != null)
{
StringBuffer sb = new StringBuffer();
for (byte b : bytes) {
sb.append(String.format("%02x ", b & 0xFF));
}
return sb.toString();
}
else {
return "N/A";
}
}
So how can I convert these two methods bytesToString and VerifyPIN to javascript.
thank you in advance