Created
May 30, 2023 18:14
-
-
Save hpkaushik121/e77f297eaef78f882a7f691fb2ec2427 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static byte[] externalAuthenticate(byte[] cryptogram, byte[] proprietaryBytes) { | |
if (cryptogram == null) { | |
throw new IllegalArgumentException("Argument 'cryptogram' cannot be null"); | |
} | |
if (cryptogram.length != 8) { | |
throw new IllegalArgumentException("Argument 'cryptogram' must have a length of 8. length=" + cryptogram.length); | |
} | |
if (proprietaryBytes != null && (proprietaryBytes.length < 1 || proprietaryBytes.length > 8)) { | |
throw new IllegalArgumentException("Argument 'proprietaryBytes' must have a length in the range 1 to 8. length=" + proprietaryBytes.length); | |
} | |
int length = cryptogram.length; | |
ByteArrayOutputStream stream = new ByteArrayOutputStream(); | |
stream.write(0x00); //CLA | |
stream.write(0x82); //INS | |
stream.write(0x00); //P1 | |
stream.write(0x00); //P2 | |
if (proprietaryBytes != null) { | |
length += proprietaryBytes.length; | |
} | |
stream.write(length); | |
stream.write(cryptogram, 0, cryptogram.length); | |
if (proprietaryBytes != null) { | |
stream.write(proprietaryBytes, 0, proprietaryBytes.length); | |
} | |
stream.write(0x00); //Le | |
return stream.toByteArray(); | |
} | |
public static void main(String[] args) { | |
byte[] cryptogram = new byte[]{0x4E,0x29,0x20,0x46,0x02,0x03,0x38,0x51}; | |
byte[] externalAuthenticate = externalAuthenticate(cryptogram,null); | |
for (byte b : externalAuthenticate) { | |
System.out.printf("%02X ", b); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment