Minimal Cryptnox example: open a secure channel and fetch card info.
Minimal Cryptnox example: open a secure channel and fetch card info.Wiring & prerequisites:
- PN532 NFC reader on SPI, with SS on pin PN532_SS_PIN.
- A Cryptnox card initialised (the secure channel itself does not need a PIN, but the card must be programmed; use
cryptnox init).
What the sketch does in each loop iteration:
- Connect to the card and establish the secure channel (CryptnoxWallet::connect).
- On success, ask the card for its info (CryptnoxWallet::getCardInfo).
- Disconnect.
This sketch never submits a PIN, so it cannot lock the card. It is the safest starting point to validate that the wiring and the secure channel work end to end before moving to VerifyPin or Sign examples.
#include <CryptnoxWallet.h>
#include <SPI.h>
#define PN532_SS_PIN (10U)
delay(1000);
SPI.begin();
while (1);
}
nfc.printFirmwareVersion();
}
if (
wallet.connect(session)) {
serialAdapter.println(
F(
"Card connected, secure channel established"));
if (
wallet.getCardInfo(session, &info)) {
} else {
serialAdapter.println(
F(
"getCardInfo failed (channel error or parse error)"));
}
} else {
serialAdapter.println(
F(
"Card not detected or secure channel failed"));
}
delay(1000);
}
void setup()
Arduino setup function.
CryptnoxWallet wallet(nfc, serialAdapter, cryptoProvider, platform)
PN532Adapter nfc(serialAdapter, PN532_SS, &SPI)
ArduinoLoggerAdapter serialAdapter
ArduinoCryptoProvider cryptoProvider
void loop()
Arduino main loop.
#define PN532_SS_PIN
SPI slave-select (CS) pin connected to the PN532 module.
CW_CryptoProvider implementation for the Arduino UNO R4 (RA4M1).
CW_Logger implementation wrapping Arduino's HardwareSerial.
High-level interface for interacting with a Cryptnox Hardware Wallet over NFC.
CW_NfcTransport implementation over the Adafruit_PN532 driver.
Subset of the Cryptnox card info returned by APDU 0x80FA0000.
char name[CW_CARD_NAME_MAX_LEN+1U]
char email[CW_CARD_EMAIL_MAX_LEN+1U]
Holds cryptographic session state for reentrant secure channel operations.