I am trying to encrypt data with AES. I used Smart Card Shell 3 to generate the AES key. But now I don’t understand how to encrypt data.
I read the documentation : Crypto - Reference Documentation
I tried to use the function encrypt(), it’s working when I am generating a new AES key (as shown in the example) but I don’t understant how to use it with the AES key on the Nitrokey.
I also tried the sc-hsm-embedded library to encrypt data :
AES-KEY-GEN becomes available in the list of mechanisms after installing sc-hsm-embedded
You need to use the sc-hsm-pkcs11 module from the sc-hsm-embedded project. OpenSC does not yet include support for AES keys on a SmartCard-HSM.
See testAES for details on how AES keys can be used via the PKCS#11 interface.
If you download the starterkit, then you find in sc-hsm-workspace-20200310.zip a workspace for the Smart Card Shell. The aes-performance.js and importAES.js scripts in examples/ show how AES operations can be performed.
Thanks for your help, but as I said before I already tried the example scripts. And when I am generating a new AES key it’s working but not when I am using a key from the smart card. I don’t know what I am missing… (see screenshot below)
Regarding sc-hsm-embedded, I might have an idea why it doesn’t work. I used the “.msi” windows installer and I think it installs the master branch and not the aes branch. So I installed the Windows Subsystem for Linux (WSL) and tried again with the aes branch this time. But it seems like WSL doesn’t not recognize USB devices…
I understood the AES support is in the master branch already (lately only tests are added), and included in the latest V2.11 release. @sc-hsm Could you confirm?
WSL1 might indeed not connect to the USB devices AFAIR. I believe the things were going to change with WSL2 - could you check what version did you use?
Edit: USB pass-through seems to still not be available after a brief search. There are reports of working this around with USB-IP and with a recompiled kernel.
Oh yes of course ! Thank you. Just a last question, the initialisation vector used by default is 0000000000000000 ? Is there a way to specify the use of another initialisation vector in the APDU command ? Because I saw that the aes_crypt_cbc() function (link below) of the Nitrokey firmware requires an iv to be input.
In CBC mode the IV is xor’ed with the first input block. You can do that before you pass the input to the HSM. On the way back you need to xor the first plain block with the IV again.
The same when you chain multiple blocks, in which case the IV is the last block from the previous operation.