1

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

画面に表示して表示したい Value (hex): があります。暗号化トークンの特定の構成に関するものですか? 別のトークンを使用すると、この値が表示されます。

4

1 に答える 1