diff --git a/wrapper/CSharp/wolfTPM-tests.cs b/wrapper/CSharp/wolfTPM-tests.cs
index 8950ade3..11e1aa2e 100644
--- a/wrapper/CSharp/wolfTPM-tests.cs
+++ b/wrapper/CSharp/wolfTPM-tests.cs
@@ -203,6 +203,9 @@ private void LoadGeneratedKey(string algorithm)
rc = device.LoadKey(blob, parent_key);
Assert.AreEqual((int)Status.TPM_RC_SUCCESS, rc);
+ rc = blob.SetKeyAuthPassword("ThisIsMyKeyAuth");
+ Assert.AreEqual((int)Status.TPM_RC_SUCCESS, rc);
+
rc = device.UnloadHandle(blob);
Assert.AreEqual((int)Status.TPM_RC_SUCCESS, rc);
}
diff --git a/wrapper/CSharp/wolfTPM.cs b/wrapper/CSharp/wolfTPM.cs
index a974d2c1..2d8c9777 100644
--- a/wrapper/CSharp/wolfTPM.cs
+++ b/wrapper/CSharp/wolfTPM.cs
@@ -216,6 +216,10 @@ private static extern int wolfTPM2_SetKeyBlobFromBuffer(IntPtr key,
[DllImport(DLLNAME, EntryPoint = "wolfTPM2_GetHandleRefFromKeyBlob")]
private static extern IntPtr wolfTPM2_GetHandleRefFromKeyBlob(IntPtr keyBlob);
+ [DllImport(DLLNAME, EntryPoint = "wolfTPM2_SetKeyAuthPassword")]
+ private static extern int wolfTPM2_SetKeyAuthPassword(
+ IntPtr keyBlob, string auth, int authSz);
+
internal IntPtr keyblob;
public KeyBlob()
@@ -282,6 +286,23 @@ public IntPtr GetHandle()
{
return wolfTPM2_GetHandleRefFromKeyBlob(keyblob);
}
+
+ ///
+ /// Set the authentication data for a key
+ ///
+ /// pointer to auth data
+ /// Success: 0
+ public int SetKeyAuthPassword(string auth)
+ {
+ int rc = wolfTPM2_SetKeyAuthPassword(keyblob,
+ auth,
+ auth.Length);
+ if (rc != (int)Status.TPM_RC_SUCCESS) {
+ throw new WolfTpm2Exception(
+ "wolfTPM2_SetKeyAuthPassword", rc);
+ }
+ return rc;
+ }
}
public class Key : IDisposable
@@ -300,9 +321,7 @@ public class Key : IDisposable
[DllImport(DLLNAME, EntryPoint = "wolfTPM2_SetKeyAuthPassword")]
private static extern int wolfTPM2_SetKeyAuthPassword(
- IntPtr key,
- string auth,
- int authSz);
+ IntPtr key, string auth, int authSz);
[DllImport(DLLNAME, EntryPoint = "wolfTPM2_GetHandleRefFromKey")]
private static extern IntPtr wolfTPM2_GetHandleRefFromKey(IntPtr key);