Tpm2Lib.Tpm2.CreatePrimary C# (CSharp) Method

CreatePrimary() private method

private CreatePrimary ( TpmHandle primaryHandle, SensitiveCreate inSensitive, byte inPublic, byte outsideInfo, PcrSelection creationPCR, [ outPublic, [ creationData, [ creationHash, [ creationTicket ) : TpmHandle
primaryHandle TpmHandle
inSensitive SensitiveCreate
inPublic byte
outsideInfo byte
creationPCR PcrSelection
outPublic [
creationData [
creationHash [
creationTicket [
return TpmHandle
        public TpmHandle CreatePrimary(
            TpmHandle primaryHandle,
            SensitiveCreate inSensitive,
            byte[] inPublic,
            byte[] outsideInfo,
            PcrSelection[] creationPCR,
            [SuppressMessage("Microsoft.Design", "CA1021")]
            out TpmPublic outPublic,
            [SuppressMessage("Microsoft.Design", "CA1021")]
            out CreationData creationData,
            [SuppressMessage("Microsoft.Design", "CA1021")]
            out byte[] creationHash,
            [SuppressMessage("Microsoft.Design", "CA1021")]
            out TkCreation creationTicket
        )
        {
            Tpm2CreatePrimaryRequest inS = new Tpm2CreatePrimaryRequest();
            inS.primaryHandle = primaryHandle;
            inS.inSensitive = inSensitive;
            inS.inPublic = inPublic;
            inS.outsideInfo = outsideInfo;
            inS.creationPCR = creationPCR;
            TpmStructureBase outSBase;
            DispatchMethod(TpmCc.CreatePrimary, (TpmStructureBase) inS, typeof(Tpm2CreatePrimaryResponse), out outSBase, 1, 1);
            Tpm2CreatePrimaryResponse outS = (Tpm2CreatePrimaryResponse) outSBase;
            outPublic = outS.outPublic;
            creationData = outS.creationData;
            creationHash = outS.creationHash;
            creationTicket = outS.creationTicket;
            return outS.objectHandle;
        }
        /// <summary>

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// Creates a primary RSA storage key.
        /// Illustrates automatic authorization of a permanent handle access.
        /// </summary>
        /// <returns>Handle of the created key.</returns>
        static TpmHandle CreateRsaPrimaryKey(Tpm2 tpm)
        {
            //
            // First member of SensitiveCreate contains auth value of the key
            //
            var sensCreate = new SensitiveCreate(new byte[] {0xa, 0xb, 0xc}, new byte[0]);

            TpmPublic parms = new TpmPublic(
                TpmAlgId.Sha1,
                ObjectAttr.Restricted | ObjectAttr.Decrypt | ObjectAttr.FixedParent | ObjectAttr.FixedTPM
                    | ObjectAttr.UserWithAuth | ObjectAttr.SensitiveDataOrigin,
                new byte[0],
                new RsaParms(
                    new SymDefObject(TpmAlgId.Aes, 128, TpmAlgId.Cfb),
                    new NullAsymScheme(),
                    2048,
                    0),
                new Tpm2bPublicKeyRsa());

            byte[] outsideInfo = Globs.GetRandomBytes(8);
            var creationPcr = new PcrSelection(TpmAlgId.Sha1, new uint[] { 0, 1, 2 });

            TpmPublic pubCreated;
            CreationData creationData;
            TkCreation creationTicket;
            byte[] creationHash;

            Console.WriteLine("Automatic authorization of TpmRh.Owner.");

            //
            // An auth session is added automatically to authorize access to the permanent
            // handle TpmHandle.RhOwner.
            //
            // Note that if the TPM is not a simulator and not cleared, you need to
            // assign the corresponding auth value to the tpm.OwnerAuth property of
            // the given Tpm2 object.
            //
            TpmHandle h = tpm.CreatePrimary(TpmRh.Owner,
                                            sensCreate, 
                                            parms,
                                            outsideInfo,
                                            new PcrSelection[] { creationPcr },
                                            out pubCreated,
                                            out creationData,
                                            out creationHash,
                                            out creationTicket);

            Console.WriteLine("Primary RSA storage key created.");

            return h;
        }
Tpm2