尝试使用用户的 PIN(智能卡)建立会话时出错



我正在使用python-pkcs11访问我拥有的SmartCard。现在,我正在尝试创建一个会话,以便可以从卡中检索公共密钥。这是我正在测试的代码:

path = (...)
os.environ["PKCS11 MODULE"] = path
lib = pkcs11.lib(os.environ['PKCS11 MODULE'])
password = bytes("1234","utf-8")
print(password)
with token.open(user_pin=password) as session:
    print(session) 

一切看起来都不错,直到达到" user_pin =密码"。我有一个错误:

Traceback (most recent call last):
    File "acess.py", line 46, in <module>
    with token.open(user_pin=password) as session:
    File "pkcs11/_pkcs11.pyx", line 227, in pkcs11._pkcs11.Token.open
    AttributeError: 'bytes' object has no attribute 'encode'

在文档中,据说user_password必须在字节中,这就是我在做的事情。有人可以帮我吗?

编辑:

当我测试这三种情况中的任何一种时,我仍然会遇到错误:

with token.open(user_pin='1234') as session:
    print(session)
with token.open(user_pin=b"1234") as session:
    print(session)
with token.open(user_pin="1234") as session:
    print(session)

错误:

Traceback (most recent call last):
      File "acess.py", line 59, in <module>
        with token.open(user_pin="1234") as session:
      File "pkcs11/_pkcs11.pyx", line 239, in pkcs11._pkcs11.Token.open
      File "pkcs11/_errors.pyx", line 88, in pkcs11._pkcs11.assertRV
        pkcs11.exceptions.UserPinNotInitialized

您缺少该行:

token = lib.get_token(token_label ='您的令牌标签')

with token.open(user_pin =" 1234")作为session: 打印(session

相关内容

  • 没有找到相关文章

最新更新