Table of Contents

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

uid byte[]

The 7-byte card UID.

ctr byte[]

The 3-byte tap counter.

k2CmacKey byte[]

The 16-byte AES key used for CMAC computation.

cmac byte[]

The 8-byte CMAC to verify against.

error string

Outputs an error string if verification fails; otherwise null.

Returns

bool

true if CMAC verification succeeds; otherwise false.

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

uid byte[]

The 7-byte card UID.

counter byte[]

The 3-byte tap counter (little-endian).

k2CmacKey byte[]

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

uid string

The hex-encoded 7-byte card UID.

counter uint

The tap counter value.

k2CmacKey byte[]

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

aesKey byte[]

The 16-byte AES key used for encryption.

counter uint

The tap counter value.

uid string

The hex-encoded 7-byte card UID.

Returns

byte[]

The 16-byte encrypted p value.

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

requestUri Uri

The URI containing BoltCard p and c query parameters.

aesKey byte[]

The 16-byte AES key for decryption.

error string

Outputs 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 null on 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

p byte[]

The 16-byte encrypted p parameter.

aesKey byte[]

The 16-byte AES key used for decryption.

error string

When this method returns null, contains an error description; otherwise null.

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 null on 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

pHex string

The hex-encoded encrypted p parameter from the BoltCard NFC tap.

aesKey byte[]

The 16-byte AES key used for decryption.

error string

When this method returns null, contains an error description; otherwise null.

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 null on failure.