我想使用PKCS#11兼容的加密USB令牌生成AES密钥并在屏幕上显示其值。
为此,我想使用IAIK PKCS#11包装器。
我尝试通过IAIK软件包随附的示例生成密钥,但未成功。密钥已生成,但看不到密钥的任何值。我应该怎么做才能看到键值以便在屏幕上显示它?
这是我的代码:
Module pkcs11Module = null;
pkcs11Module = Module.getInstance("pkcs11.dll");
Session session = null;
pkcs11Module.initialize(null);
Slot[] slots = pkcs11Module.getSlotList(Module.SlotRequirement.TOKEN_PRESENT);
if (slots.length == 0) {
output_.println("No slot with present token found!");
throw new TokenException("No token found!");
}
Slot selectedSlot;
// slot 0
selectedSlot = slots[0];
Token token = selectedSlot.getToken();
session = token.openSession(Token.SessionType.SERIAL_SESSION, Token.SessionReadWriteBehavior.RW_SESSION, null, null);
session.login(Session.UserType.USER, "12345678".toCharArray());
Mechanism keyGenerationMechanism = Mechanism.get(PKCS11Constants.CKM_AES_KEY_GEN);
AESSecretKey aesKey = new AESSecretKey();
aesKey.getValueLen().setLongValue(new Long(32));
AESSecretKey aesKeyNew = (AESSecretKey) session.generateKey(keyGenerationMechanism, aesKey);
output_.println("the AES Key is: ");
output_.println(aesKeyNew.toString());
session.closeSession();
pkcs11Module.finalize(null);
结果如下:
the AES Key is:
Object Class: Secret Key
Token: false
Private: false
Modifiable: true
Label: <NULL_PTR>
Key Type: AES
ID: <NULL_PTR>
Start Date: <NULL_PTR>
End Date: <NULL_PTR>
Derive: true
Local: true
Key Generation Mechanism: CKM_AES_KEY_GEN
Allowed Mechanisms: <Attribute not present>
Sensitive: false
Encrypt: true
Decrypt: true
Sign: false
Verify: false
Wrap: true
Unwrap: true
Extractable: true
Always Sensitive: false
Never Extractable: true
Check Value: <Attribute not present>
Wrap With Trusted: <Attribute not present>
Trusted: <Attribute not present>
Wrap Template: <Attribute not present>
Unwrap Template: <Attribute not present>
Value (hex): <NULL_PTR>
Value Length (dec): 0
有值(十六进制):我想在屏幕上看到并显示。它与密码令牌的特定配置有关吗?当我使用其他令牌时,我会看到此值。
根据您显示的内容,将PKCS#11属性CKA_SENSITIVE
设置为false表示您应该能够查看该值。但是,令牌很可能不允许您提取值。这些令牌中的大多数并没有完全实现PKCS#11,而仅允许进行某些操作。如果这是真的,那么它应该是不可能的设置CKA_SENSITIVE
为false,但仅此而已你...
我将跟踪令牌的制造商(或者,如果可能的话,开发商),并要求令牌实现的特定功能。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句