We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
public static void main4(String[] args) throws IOException { Tpm tpm = TpmFactory.platformTpm(); byte[] nullVec = new byte[0]; byte[] aesKey = Helpers.RandomBytes(16); TPMT_PUBLIC aesTemplate = new TPMT_PUBLIC(TPM_ALG_ID.SHA256, new TPMA_OBJECT(new TPMA_OBJECT[]{TPMA_OBJECT.decrypt, TPMA_OBJECT.sign, TPMA_OBJECT.fixedParent, TPMA_OBJECT.fixedTPM, TPMA_OBJECT.userWithAuth}), new byte[0], new TPMS_SYMCIPHER_PARMS(new TPMT_SYM_DEF_OBJECT(TPM_ALG_ID.AES, 128, TPM_ALG_ID.CFB)), new TPM2B_DIGEST_SYMCIPHER()); TPMS_SENSITIVE_CREATE sensCreate = new TPMS_SENSITIVE_CREATE(nullVec, aesKey); CreatePrimaryResponse aesPrimary = tpm.CreatePrimary(tpm._OwnerHandle, sensCreate, aesTemplate, nullVec, new TPMS_PCR_SELECTION[0]); TPM_HANDLE aesHandle = aesPrimary.handle; byte[] toEncrypt = new byte[]{1, 2, 3, 4, 5, 4, 3, 2, 12, 3, 4, 5}; byte[] iv = new byte[16]; EncryptDecryptResponse encrypted = tpm.EncryptDecrypt(aesHandle, (byte) 0, TPM_ALG_ID.CFB, iv, toEncrypt); EncryptDecryptResponse decrypted = tpm.EncryptDecrypt(aesHandle, (byte) 1, TPM_ALG_ID.CFB, iv, encrypted.outData); System.out.println("AES128 encryption with key = " + Helpers.toHex(aesKey)); System.out.println(" Input data:" + Helpers.toHex(toEncrypt)); System.out.println(" encrypted data:" + Helpers.toHex(encrypted.outData)); System.out.println(" decrypted data:" + Helpers.toHex(decrypted.outData));
TPM_HANDLE persistentHandle = TPM_HANDLE.persistent(0x81010001); tpm.EvictControl(TPM_HANDLE.from(TPM_RH.OWNER), aesHandle, persistentHandle); if (!Helpers.arraysAreEqual(toEncrypt, decrypted.outData)) { throw new RuntimeException("encrypt/decrypt failed!"); } else { tpm.FlushContext(aesHandle); }
}
The text was updated successfully, but these errors were encountered:
No branches or pull requests
public static void main4(String[] args) throws IOException {
Tpm tpm = TpmFactory.platformTpm();
byte[] nullVec = new byte[0];
byte[] aesKey = Helpers.RandomBytes(16);
TPMT_PUBLIC aesTemplate = new TPMT_PUBLIC(TPM_ALG_ID.SHA256, new TPMA_OBJECT(new TPMA_OBJECT[]{TPMA_OBJECT.decrypt, TPMA_OBJECT.sign, TPMA_OBJECT.fixedParent, TPMA_OBJECT.fixedTPM, TPMA_OBJECT.userWithAuth}), new byte[0], new TPMS_SYMCIPHER_PARMS(new TPMT_SYM_DEF_OBJECT(TPM_ALG_ID.AES, 128, TPM_ALG_ID.CFB)), new TPM2B_DIGEST_SYMCIPHER());
TPMS_SENSITIVE_CREATE sensCreate = new TPMS_SENSITIVE_CREATE(nullVec, aesKey);
CreatePrimaryResponse aesPrimary = tpm.CreatePrimary(tpm._OwnerHandle, sensCreate, aesTemplate, nullVec, new TPMS_PCR_SELECTION[0]);
TPM_HANDLE aesHandle = aesPrimary.handle;
byte[] toEncrypt = new byte[]{1, 2, 3, 4, 5, 4, 3, 2, 12, 3, 4, 5};
byte[] iv = new byte[16];
EncryptDecryptResponse encrypted = tpm.EncryptDecrypt(aesHandle, (byte) 0, TPM_ALG_ID.CFB, iv, toEncrypt);
EncryptDecryptResponse decrypted = tpm.EncryptDecrypt(aesHandle, (byte) 1, TPM_ALG_ID.CFB, iv, encrypted.outData);
System.out.println("AES128 encryption with key = " + Helpers.toHex(aesKey));
System.out.println(" Input data:" + Helpers.toHex(toEncrypt));
System.out.println(" encrypted data:" + Helpers.toHex(encrypted.outData));
System.out.println(" decrypted data:" + Helpers.toHex(decrypted.outData));
}
The text was updated successfully, but these errors were encountered: