Class BoltCardHelper
- Namespace
- LNURL
- Assembly
- LNURL.Core.dll
Provides helper methods for working with BoltCard NFC cards, including
decrypting the p parameter to extract UID and counter values,
verifying CMAC authentication codes, and creating p and c values.
public class BoltCardHelper
- Inheritance
-
BoltCardHelper
- Inherited Members
Methods
CheckCmac(byte[], byte[], byte[], byte[], out string)
Verifies the CMAC authentication code for a BoltCard tap by computing the expected CMAC from the UID, counter, and CMAC key, then comparing it against the provided CMAC.
public static bool CheckCmac(byte[] uid, byte[] ctr, byte[] k2CmacKey, byte[] cmac, out string error)
Parameters
uidbyte[]The 7-byte card UID.
ctrbyte[]The 3-byte tap counter.
k2CmacKeybyte[]The 16-byte AES key used for CMAC computation.
cmacbyte[]The 8-byte CMAC to verify against.
errorstringOutputs an error string if verification fails; otherwise
null.
Returns
- bool
trueif CMAC verification succeeds; otherwisefalse.
CreateCValue(byte[], byte[], byte[])
Creates the CMAC (c) value for a BoltCard from raw UID bytes, counter bytes, and CMAC key.
public static byte[] CreateCValue(byte[] uid, byte[] counter, byte[] k2CmacKey)
Parameters
uidbyte[]The 7-byte card UID.
counterbyte[]The 3-byte tap counter (little-endian).
k2CmacKeybyte[]The 16-byte AES key used for CMAC computation.
Returns
- byte[]
The computed 8-byte CMAC value.
Exceptions
- ArgumentException
Thrown when input arrays have invalid lengths.
CreateCValue(string, uint, byte[])
Creates the CMAC (c) value for a BoltCard from the UID string, counter, and CMAC key.
public static byte[] CreateCValue(string uid, uint counter, byte[] k2CmacKey)
Parameters
uidstringThe hex-encoded 7-byte card UID.
counteruintThe tap counter value.
k2CmacKeybyte[]The 16-byte AES key used for CMAC computation.
Returns
- byte[]
The computed 8-byte CMAC value.
CreatePValue(byte[], uint, string)
Creates the encrypted p value for a BoltCard by constructing the plaintext block
(starting with 0xC7, followed by UID and counter) and encrypting it with AES-CBC.
public static byte[] CreatePValue(byte[] aesKey, uint counter, string uid)
Parameters
aesKeybyte[]The 16-byte AES key used for encryption.
counteruintThe tap counter value.
uidstringThe hex-encoded 7-byte card UID.
Returns
- byte[]
The 16-byte encrypted
pvalue.
ExtractBoltCardFromRequest(Uri, byte[], out string)
Extracts BoltCard information from a given request URI by decrypting the p parameter
and reading the c (CMAC) parameter.
public static (string uid, uint counter, byte[] rawUid, byte[] rawCtr, byte[] c)? ExtractBoltCardFromRequest(Uri requestUri, byte[] aesKey, out string error)
Parameters
requestUriUriThe URI containing BoltCard
pandcquery parameters.aesKeybyte[]The 16-byte AES key for decryption.
errorstringOutputs an error string if extraction fails; otherwise
null.
Returns
- (string uid, uint counter, byte[] rawUid, byte[] rawCtr, byte[] c)?
A tuple containing the UID, counter, raw UID bytes, raw counter bytes, and raw CMAC bytes; or
nullon failure.
ExtractUidAndCounterFromP(byte[], byte[], out string?)
Extracts the UID and tap counter from the raw p parameter bytes by decrypting with the given AES key.
The decrypted data must start with 0xC7 to be considered valid.
public static (string uid, uint counter, byte[] rawUid, byte[] rawCtr)? ExtractUidAndCounterFromP(byte[] p, byte[] aesKey, out string? error)
Parameters
pbyte[]The 16-byte encrypted
pparameter.aesKeybyte[]The 16-byte AES key used for decryption.
errorstringWhen this method returns
null, contains an error description; otherwisenull.
Returns
- (string uid, uint counter, byte[] rawUid, byte[] rawCtr)?
A tuple containing the UID string, counter value, raw UID bytes, and raw counter bytes; or
nullon failure.
ExtractUidAndCounterFromP(string, byte[], out string?)
Extracts the UID and tap counter from a hex-encoded p parameter by decrypting it with the given AES key.
public static (string uid, uint counter, byte[] rawUid, byte[] rawCtr)? ExtractUidAndCounterFromP(string pHex, byte[] aesKey, out string? error)
Parameters
pHexstringThe hex-encoded encrypted
pparameter from the BoltCard NFC tap.aesKeybyte[]The 16-byte AES key used for decryption.
errorstringWhen this method returns
null, contains an error description; otherwisenull.