---
name: "Tspi_Key_WrapKey"
section: "3"
platform: "linux"
package: "libtspi-dev"
version: "0.3.15-0.4"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Tspi_Key_WrapKey"
---

# Tspi\_Key\_WrapKey(3)

wrap a key with the key addressed by hWrappingKey.

## NAME

Tspi\_Key\_WrapKey - wrap a key with the key addressed by hWrappingKey.

## SYNOPSIS

**#include \<tss/platform.h\>** **#include \<tss/tcpa\_defines.h\>** **#include \<tss/tcpa\_typedef.h\>** **#include \<tss/tcpa\_struct.h\>** **#include \<tss/tss\_typedef.h\>** **#include \<tss/tss\_structs.h\>** **#include \<tss/tspi.h\>** **TSS\_RESULT Tspi\_Key\_WrapKey(TSS\_HKEY**  *hKey***, TSS\_HKEY** *hWrappingKey***,**                             **TSS\_HPCRS** *hPcrComposite***);**

## DESCRIPTION

**TSS\_Key\_WrapKey**   wraps the private key *hKey* using the public key addressed by *hWrappingKey*. If hPcrComposite is not set to NULL (0), the created key blob is bound to its PCR values. The key object addressed by *hKey* must contain the key information needed for the creation. On successful return from this call, *hKey* can be loaded into a TPM. *hKey* must have been created as a migratable key and should have its usage and migrations secrets set using **[Tspi\_Policy\_SetSecret(3)](/Tspi_Policy_SetSecret/3.md)**.  Also, *hKey* should have had its private key set to either RSA private component, p or q.

## PARAMETERS

### hKey

The handle of the key object that is wrapped.

### hWrappingKey

The handle to the key used to wrap the newly created key.

### hPcrComposite

The handle to an object, if the value of the handle doesn't equal NULL, the newly create key will be bound ot the PCR values described with this object.

## RETURN CODES

**Tspi\_Key\_WrapKey** returns TSS\_SUCCESS on success, otherwise one of the following values are returned: TSS\_E\_INVALID\_HANDLE - Either *hKey*, *hWrappingKey* or *hPcrComposite* are invalid handles. TSS\_E\_INTERNAL\_ERROR - An error occurred internal to the TSS.

## CONFORMING TO

**Tspi\_Key\_WrapKey** conforms to the Trusted Computing Group Software Specification version 1.1 Golden

## SEE ALSO

[**Tspi\_Key\_CreateKey**(3)](/Tspi_Key_CreateKey/3.md), [**Tspi\_Key\_CertifyKey**(3)](/Tspi_Key_CertifyKey/3.md), **Tspi\_Key\_RegisterKey**(3).
