当前位置: 首页>>代码示例>>C#>>正文


C# Marshaller.GetBytes方法代码示例

本文整理汇总了C#中Marshaller.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# Marshaller.GetBytes方法的具体用法?C# Marshaller.GetBytes怎么用?C# Marshaller.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Marshaller的用法示例。


在下文中一共展示了Marshaller.GetBytes方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        // ReSharper disable once InconsistentNaming
        internal override TpmRc Execute(Tpm2 tpm, AuthSession authSession, PolicyTree policy)
        {
            byte[] nonceTpm = UseNonceTpm ? Globs.CopyData(authSession.NonceTpm) : new byte[0];

            var dataToSign = new Marshaller();
            dataToSign.Put(nonceTpm, "");
            ISignatureUnion signature;
            // If the library has been given a signing key we can do the challenge here (else we need to call out)
            TpmHandle verificationKey;
            if (SigningKey != null)
            {
                dataToSign.Put(ExpirationTime, "");
                dataToSign.Put(CpHash, "");
                dataToSign.Put(PolicyRef, "");
                // Just ask the key to sign the challenge
                signature = SigningKey.Sign(dataToSign.GetBytes());
                verificationKey = tpm.LoadExternal(null, SigningKeyPub, TpmRh.Owner);
            }
            else
            {
                TpmPublic verifier;
                signature = AssociatedPolicy.ExecuteSignerCallback(this, nonceTpm, out verifier);
                verificationKey = tpm.LoadExternal(null, verifier, TpmRh.Owner);
            }
            TkAuth policyTicket;

            Timeout = tpm.PolicySigned(verificationKey,
                                       authSession,
                                       nonceTpm,
                                       CpHash,
                                       PolicyRef,
                                       ExpirationTime,
                                       signature,
                                       out policyTicket);

            TpmRc responseCode = tpm._GetLastResponseCode();
            // Save the policyTicket in case it is needed later
            PolicyTicket = policyTicket;
            tpm.FlushContext(verificationKey);
            return responseCode;
        }
开发者ID:Microsoft,项目名称:TSS.MSR,代码行数:42,代码来源:PolicyAces.cs

示例2: UpdateHandleData

        } // UpdateHandleData()

        /// <summary>
        /// Calculate the command hash.  Note that the handles are replaced by the name of the referenced object
        /// </summary>
        /// <param name="hashAlg"></param>
        /// <param name="commandParms"></param>
        /// <param name="handles"></param>
        /// <returns></returns>
        private byte[] GetCommandHash(TpmAlgId hashAlg, byte[] commandParms, TpmHandle[] handles)
        {
            var temp = new Marshaller();
            temp.Put(CurrentCommand, "ordinal");
            for (int j = 0; j < handles.Length; j++)
            {
                temp.Put(handles[j].Name, "name + " + j);
            }
            temp.Put(commandParms, "commandParms");
            byte[] parmsHash = CryptoLib.HashData(hashAlg, temp.GetBytes());
            return parmsHash;
        }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:21,代码来源:Tpm2.cs

示例3: PolicyUpdate

 /// <summary>
 /// Return an updated policy hash according to the TPM specification.
 /// </summary>
 /// <param name="?"></param>
 /// <param name="currentHash"></param>
 /// <param name="commandCode"></param>
 /// <param name="name"></param>
 /// <param name="refData"></param>
 /// <returns></returns>
 internal TpmHash PolicyUpdate(TpmHash currentHash, TpmCc commandCode, byte[] name, byte[] refData)
 {
     var m = new Marshaller();
     m.Put(commandCode, "commandCode");
     m.Put(name, "name");
     TpmHash h1 = currentHash.Extend(m.GetBytes());
     TpmHash h2 = h1.Extend(refData);
     return h2;
 }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:18,代码来源:PolicyAces.cs

示例4: GetPolicyDigest

        internal override TpmHash GetPolicyDigest(TpmAlgId hashAlg)
        {
            var m = new Marshaller();
            m.Put(OperandB, "operandB");
            m.Put(Offset, "offset");
            m.Put(Operation, "operation");
            byte[] args = CryptoLib.HashData(hashAlg, m.GetBytes());

            m = new Marshaller();
            m.Put(TpmCc.PolicyNV, "ord");
            m.Put(args, "args");
            m.Put(IndexName, "name");

            return GetNextAcePolicyDigest(hashAlg).Extend(m.GetBytes());
        }
开发者ID:Microsoft,项目名称:TSS.MSR,代码行数:15,代码来源:PolicyAces.cs

示例5: GetTpmRepresentation

 public byte[] GetTpmRepresentation()
 {
     var m = new Marshaller();
     ToNet(m);
     return m.GetBytes();
 }
开发者ID:Microsoft,项目名称:TSS.MSR,代码行数:6,代码来源:TpmBaseClasses.cs

示例6: FormatError

 /// <summary>
 /// Create a 10 byte error response that matches TPM error responses.
 /// </summary>
 /// <param name="errorCode"></param>
 /// <returns></returns>
 private byte[] FormatError(TpmRc errorCode)
 {
     var m = new Marshaller();
     m.Put(TpmSt.NoSessions, "");
     m.Put((uint)10, "");
     m.Put(errorCode, "");
     return m.GetBytes();
 }
开发者ID:Microsoft,项目名称:TSS.MSR,代码行数:13,代码来源:SlotManager.cs

示例7: CreateResponse

        public static byte[] CreateResponse(
            TpmRc responseCode,
            TpmHandle[] handles,
            SessionOut[] sessions,
            byte[] responseParmsNoHandles)
        {
            var m = new Marshaller();
            TpmSt tag = sessions.Length == 0 ? TpmSt.NoSessions : TpmSt.Sessions;

            m.Put(tag, "tag");
            m.PushLength(4);
            m.Put(responseCode, "responseCode");

            foreach (TpmHandle h in handles)
            {
                m.Put(h, "handle");
            }

            if (tag == TpmSt.Sessions)
            {
                m.Put((uint)responseParmsNoHandles.Length, "parmsLenght");
            }

            m.Put(responseParmsNoHandles, "parms");
            foreach (SessionOut s in sessions)
                m.Put(s, "session");
            m.PopAndSetLengthToTotalLength();
            return m.GetBytes();
        }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:29,代码来源:Tpm2.cs

示例8: PolicyUpdate1

        /// <summary>
        /// Implements the first step of the policy digest update (see the PolicyUpdate()
        /// method), and also used by PolicyAuthorizeNV.
        /// </summary>
        internal TpmHash PolicyUpdate1(TpmHash currentHash, TpmCc commandCode, byte[] name)
        {
            var m = new Marshaller();
            m.Put(commandCode, "commandCode");
            m.Put(name, "name");

            return currentHash.Extend(m.GetBytes());
        }
开发者ID:Microsoft,项目名称:TSS.MSR,代码行数:12,代码来源:PolicyAces.cs

示例9: GetExpectedResponseHash

        /// <summary>
        /// The response hash includes the command ordinal, response code, and the actual command bytes.
        /// </summary>
        /// <param name="hashAlg"></param>
        /// <param name="commandCode"></param>
        /// <param name="responseCode"></param>
        /// <param name="responseParmsNoHandles"></param>
        /// <returns></returns>
        private byte[] GetExpectedResponseHash(
            TpmAlgId hashAlg,
            byte[] responseParmsNoHandles,
            TpmCc commandCode,
            TpmRc responseCode)
        {
            var temp = new Marshaller();
            temp.Put(responseCode, "responseCode");
            temp.Put(commandCode, "currentCommand");
            temp.Put(responseParmsNoHandles, null);

            byte[] parmsHash = CryptoLib.HashData(hashAlg, temp.GetBytes());
            return parmsHash;
        }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:22,代码来源:Tpm2.cs

示例10: CreateCommand

        /// <summary>
        /// Create a TPM command byte stream from constituent components
        /// </summary>
        /// <param name="commandCode"></param>
        /// <param name="handles"></param>
        /// <param name="sessions"></param>
        /// <param name="parmsWithoutHandles"></param>
        /// <returns></returns>
        public static byte[] CreateCommand(
            TpmCc commandCode,
            TpmHandle[] handles,
            SessionIn[] sessions,
            byte[] parmsWithoutHandles)
        {

            // ReSharper disable once UnusedVariable
            CommandInfo commandInfo = Tpm2.CommandInfoFromCommandCode(commandCode);

            var m = new Marshaller();
            TpmSt tag = sessions.Length == 0 ? TpmSt.NoSessions : TpmSt.Sessions;
            m.Put(tag, "tag");
            m.PushLength(4);
            m.Put(commandCode, "commandCode");
            foreach (TpmHandle h in handles)
            {
                m.Put(h, "handle");
            }

            if (tag == TpmSt.Sessions)
            {
                var m2 = new Marshaller();
                foreach (SessionIn s in sessions)
                {
                    m2.Put(s, "session");
                }
                m.PutUintPrependedArray(m2.GetBytes(), "sessions");
            }

            m.Put(parmsWithoutHandles, "parms");

            m.PopAndSetLengthToTotalLength();
            return m.GetBytes();
        }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:43,代码来源:Tpm2.cs

示例11: ParseCommand

        public static string ParseCommand(byte[] buf)
        {
            CommandHeader commandHeader;
            TpmHandle[] inHandles;
            SessionIn[] inSessions;
            byte[] commandParmsNoHandles;
            string response = "";

            bool ok = CrackCommand(buf, out commandHeader, out inHandles, out inSessions, out commandParmsNoHandles);
            if (!ok)
            {
                response = "The TPM command is not properly formatted.  Doing the best I can...\n";
            }
            CommandInfo command = Tpm2.CommandInfoFromCommandCode(commandHeader.CommandCode);
            if (command == null)
            {
                response += String.Format("The command-code {0} is not defined.  Aborting\n", commandHeader.CommandCode);
                return response;
            }
            response += "Header:\n";
            response += commandHeader + "\n";

            var m2 = new Marshaller();
            foreach (TpmHandle h in inHandles)
            {
                m2.Put(h, "");
            }

            byte[] commandParmsWithHandles = Globs.Concatenate(new[] {m2.GetBytes(), commandParmsNoHandles});
            var m = new Marshaller(commandParmsWithHandles);
            object inParms = m.Get(command.InStructType, "");
            response += "Command Parameters:\n";
            response += inParms + "\n";
            response += "Sessions [" + inSessions.Length + "]\n";
            for (int j = 0; j < inSessions.Length; j++)
            {
                // ReSharper disable once FormatStringProblem
                response += String.Format("{0}: 0x{1:x}\n", j, inSessions[j]);
            }
            return response;
        }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:41,代码来源:Tpm2.cs

示例12: GetDataStructureToSign

 /// <summary>
 /// This is a formatting helper to help callbacks create a properly formed hash to sign.
 /// </summary>
 /// <returns></returns>
 public static byte[] GetDataStructureToSign(int expirationTime, byte[] nonceTpm, byte[] cpHash, byte[] policyRef)
 {
     var dataToSign = new Marshaller();
     dataToSign.Put(nonceTpm, "");
     dataToSign.Put(expirationTime, "");
     dataToSign.Put(cpHash, "");
     dataToSign.Put(policyRef, "");
     return dataToSign.GetBytes();
 }
开发者ID:Microsoft,项目名称:TSS.MSR,代码行数:13,代码来源:Policy.cs

示例13: VerifyQuote

        /// <summary>
        /// Verify that a TPM quote matches an expect PCR selection, is well formed, and is properly signed
        /// by the private key corresponding to this public key.
        /// </summary>
        /// <param name="pcrDigestAlg"></param>
        /// <param name="expectedSelectedPcr"></param>
        /// <param name="expectedPcrValues"></param>
        /// <param name="nonce"></param>
        /// <param name="quotedInfo"></param>
        /// <param name="signature"></param>
        /// <param name="qualifiedNameOfSigner"></param>
        /// <returns></returns>
        public bool VerifyQuote(
            TpmAlgId pcrDigestAlg,
            PcrSelection[] expectedSelectedPcr,
            Tpm2bDigest[] expectedPcrValues,
            byte[] nonce,
            Attest quotedInfo,
            ISignatureUnion signature,
            byte[] qualifiedNameOfSigner = null)
        {
            if (!(quotedInfo.attested is QuoteInfo))
            {
                return false;
            }

            if (quotedInfo.magic != Generated.Value)
            {
                return false;
            }

            if (!quotedInfo.extraData.IsEqual(nonce))
            {
                return false;
            }

            // Check environment of signer (name) is expected
            if (qualifiedNameOfSigner != null)
            {
                if (!quotedInfo.qualifiedSigner.IsEqual(qualifiedNameOfSigner))
                {
                    return false;
                }
            }

            // Now check the quote-specific fields
            var quoted = (QuoteInfo)quotedInfo.attested;

            // Check values pcr indices are what we expect
            if (!Globs.ArraysAreEqual(quoted.pcrSelect, expectedSelectedPcr))
            {
                return false;
            }

            // Check that values in the indices above are what we expect
            // ReSharper disable once UnusedVariable
            var expected = new PcrValueCollection(expectedSelectedPcr, expectedPcrValues);
            var m = new Marshaller();

            foreach (Tpm2bDigest d in expectedPcrValues)
            {
                m.Put(d.buffer, "");
            }

            TpmHash expectedPcrHash = TpmHash.FromData(pcrDigestAlg, m.GetBytes());
            if (!Globs.ArraysAreEqual(expectedPcrHash, quoted.pcrDigest))
            {
                return false;
            }

            // And finally check the signature
            bool sigOk = VerifySignatureOverData(quotedInfo.GetTpmRepresentation(), signature);
            return sigOk;
        }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:74,代码来源:TpmKey.cs

示例14: GetSelectionHash

 /// <summary>
 /// Get the hash of the concatenation of the values in the array order defined by the PcrSelection[] 
 /// returned from GetPcrSelectionArray.
 /// </summary>
 /// <param name="hashAlg"></param>
 /// <returns></returns>
 public TpmHash GetSelectionHash(TpmAlgId hashAlg)
 {
     var m = new Marshaller();
     PcrSelection[] selections = GetPcrSelectionArray();
     foreach (PcrSelection sel in selections)
     {
         uint[] pcrIndices = sel.GetSelectedPcrs();
         foreach (uint index in pcrIndices)
         {
             PcrValue v = GetSpecificValue(sel.hash, index);
             m.Put(v.value.HashData, "hash");
         }
     }
     var valueHash = new TpmHash(hashAlg, CryptoLib.HashData(hashAlg, m.GetBytes()));
     return valueHash;
 }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:22,代码来源:TpmCustomDefs.cs


注:本文中的Marshaller.GetBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。