我正在尝试读取 USB 令牌证书详细信息,例如后天、前天和主题,以及 USB 令牌上的证书的其他详细信息我正在使用 Botan 2.19 库和 PKCS11 我成功登录并设置了 bin但我无法获取证书详细信息 我的考验是
session.login(Botan::PKCS11::UserType::User, pin);
Botan::PKCS11::Slot slot(module, slotsx[0]);
Botan::PKCS11::Session session(slot, false);
Botan::PKCS11::secure_string pin = {'1', '1', '1', '1', '2', '2', '2', '2'};
session.login(Botan::PKCS11::UserType::User, pin);
// Retrieve the certificate objects from the token
std::vector<Botan::PKCS11::ObjectHandle> cert_objects = module->C_FindObjects(slot, Botan::PKCS11::ObjectClass::Certificate);
if (!cert_objects.empty()) {
// Assuming you want to read the first certificate on the token
Botan::PKCS11::ObjectHandle cert_object = cert_objects[0];
// Get the certificate data as a binary DER format
std::vector<uint8_t> der_data = session.get_attribute_value(cert_object, Botan::PKCS11::AttributeType::Value);
// Parse the certificate from DER data
Botan::DataSource_Memory cert_source(der_data.data(), der_data.size());
Botan::X509_Certificate cert(cert_source);
// Access certificate information
std::cout << "Certificate subject: " << cert.subject_dn().to_string() << std::endl;
std::cout << "Certificate issuer: " << cert.issuer_dn().to_string() << std::endl;
std::cout << "Certificate serial number: " << cert.serial_number() << std::endl;
std::cout << "Certificate not valid before: " << cert.not_before() << std::endl;
std::cout << "Certificate not valid after: " << cert.not_after() << std::endl;
谁能帮我找到读取证书数据的解决方案吗?