Skip to content

id card‐lib

Boriss Melikjan edited this page Sep 9, 2025 · 1 revision

Java API for communicating with ID-cards (APDU commands for EstEID v. 3.5, EstEID v. 3.4, ID1 (Cosmo v8.1, v8.2, Cosmo X) and Thales).

Examples of usages

val smartCardReaderManager: SmartCardReaderManager = ...

// returns the right implementation of the Token based on the current card in the reader
val token: Token =
    Token.create(smartCardReaderManager.connectedReader())

// read personal data file from the card
PersonalData personalData = token.personalData();

// change PIN1/PIN2/PUK code
try {
    token.changeCode(CodeType.PIN1, "1234".toByteArray(), "4321".toByteArray())
} catch (ex: SmartCardReaderException) {
    // current code is invalid
}

// change PIN1/PIN2 via PUK code (in case the code is blocked or forgotten)
try {
    token.unblockAndChangeCode("12345678".toByteArray(), CodeType.PIN1, "1234".toByteArray())
} catch (ex: SmartCardReaderException) {
    // PUK code is invalid
}

// how tries left before code is blocked (0 means the code is blocked)
val retryCounter = token.codeRetryCounter(CodeType.PIN1)

// read certificate from the card
val certificateData = token.certificate(CertificateType.AUTHENTICATION)

// calculate electronic signature with pre-calculated hash
val hash = byteArrayOf()
val ecc = true
try {
    val signedData = token.calculateSignature("12345".toByteArray(), hash, ecc)
} catch (ex: SmartCardReaderException) {
    // PIN2 code is invalid
}

// decrypt data
val data = byteArrayOf()
val ecc = true
try {
    val result = token.decrypt("1234".toByteArray(), data, ecc)
} catch (CodeVerificationException e) {
    // PIN1 code is invalid
}

Clone this wiki locally