Could you use the tpm2-tools as sample code?
In general you need to get a:
TCTI context to the simulator
SAPI context using the aforementioned TCTI
Call TPM2_EncryptDecrypt() or TPM2_EncryptDecrypt2(), see:
See Section 15.2 on the command fields.
As an aside, I often times compile everything with debugging flags and run both the
simulator and client
Application in debuggers so I can see what's actually going on. I've found that to
be invaluable when I am
From: tpm2 [mailto:email@example.com] On Behalf Of Sourajit
Sent: Monday, November 5, 2018 6:41 AM
Subject: [tpm2] Need assistance to encrypt/decrypt data using tpm2-tss
I am a beginner trying to learn more about the TPM and its functionalities. I am
trying to write a basic code using the SAPI to make the TPM generate a key and
encrypt some data/file, and then later decrypt the same.
So far I have been unable to perform the desired task. I have referred to the
sapi-assymetric-encrypt-decrypt test module. I am using the IBM TPM simulator
on Linux. So far searching on the internet for anything relevant ended with
nothing positive. I would be highly grateful if someone could give a short
description/steps to guide me through this.