Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * @param {number[]} cmd
- * @param {number[]} options
- * @returns {number[]}
- */
- getMacInput = (cmd, options) => {
- console.log("Getting MAC Input");
- console.log("CMD Counter: ", this.CmdCounter);
- console.log("Transaction ID: ", this.TransactionIdentifier);
- // get cmdCounter
- const commandCounter = DesfireUtils.intToHexArray(this.CmdCounter, 1);
- console.log("Command Counter: ", commandCounter);
- const transactionId = DesfireUtils.hexStringToByte(this.TransactionIdentifier);
- console.log("transactionId: ", transactionId);
- let macInput = cmd.concat(commandCounter).concat(transactionId);
- if (options != null)
- macInput = macInput.concat(options);
- return macInput;
- }
- getCardVersion = async () => {
- let cmd = DESFIRE_INS.GET_UID;
- const macInput = this.getMacInput(cmd, null);
- const macInputString = DesfireUtils.getHexFromDecArray(macInput);
- console.log("Mac Input: ", macInputString);
- const macFull = CMAC.calculateCmac(this.sessionAuthMac, macInputString);
- console.log("Mac Full: ", macFull);
- const macTruncated = CMAC.macTruncate(macFull);
- console.log("MAC Truncated: ", macTruncated);
- const param = DesfireUtils.hexStringToByte(macTruncated);
- cmd = cmd.concat(param);
- let response = await this.sendCommand(cmd);
- console.log("Get Card Version: ", response)
- }
- CMAC::macTruncate = (message) => {
- const fullMAC = this.hexStringToByte(message);
- const fullMACLength = fullMAC.length;
- const truncatedMAC = new Uint8Array(fullMACLength / 2);
- let truncatedMACPos = 0;
- for (let i = 1; i < fullMACLength; i += 2) {
- truncatedMAC[truncatedMACPos] = fullMAC[i];
- truncatedMACPos++;
- }
- const truncatedMACString = Array.from(truncatedMAC).map(byte => {
- // Convert each byte to its hexadecimal representation
- return ('0' + byte.toString(16)).slice(-2); // Ensure two characters for each byte
- }).join('');
- console.log('Truncated MAC: ', truncatedMACString);
- return truncatedMACString;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement