Beispiel #1
0
        } //NVCounter

        internal static void CreateTwoPrimaries(Tpm2 tpm)
        {
            var data = Encoding.UTF8.GetBytes("hello world");

            var handle1 = KeyHelpers.CreatePrimaryRsaKey(tpm, null, null, null, out TpmPublic key);

            IAsymSchemeUnion decScheme = new SchemeOaep(TpmAlgId.Sha1);

            var cipher = tpm.RsaEncrypt(handle1, data, decScheme, null);

            byte[] decrypted1 = tpm.RsaDecrypt(handle1, cipher, decScheme, null);

            var decyyptedData = Encoding.UTF8.GetString(decrypted1);



            var pub = tpm.ReadPublic(handle1, out byte[] name, out byte[] qn);

            var enc = KeyHelpers.CreateEncryptionDecryptionKey(tpm, handle1);

            tpm._ExpectResponses(TpmRc.Success, TpmRc.TbsCommandBlocked);
            var cipher2 = tpm.EncryptDecrypt(enc, 1, TpmAlgId.None, data, data, out byte[] test2);

            tpm.FlushContext(handle1);

            var handle2 = KeyHelpers.CreatePrimary(tpm, out TpmPublic key3); //, seed: new byte[] { 22, 123, 22, 1, 33 });

            tpm.FlushContext(handle2);
        }
        internal static byte[] RsaDecrypt(Tpm2 tpm, byte[] data)
        {
            var handle1 = KeyHelpers.CreatePrimaryRsaKey(tpm, null, new byte[] { 2 }, new byte[] { 1, 2, 3 }, out TpmPublic key);

            byte[] decrypted1 = tpm.RsaDecrypt(handle1, data, decScheme, null);
            tpm.FlushContext(handle1);
            return(decrypted1);
        }
Beispiel #3
0
        internal static void EncryptDecrypt(Tpm2 tpm)
        {
            var keyParams = KeyHelpers.CreateDecryptionKey2();

            TpmPublic    pubCreated;
            CreationData creationData;
            TkCreation   creationTicket;

            byte[] creationHash;


            TpmHandle h = tpm.CreatePrimary(TpmRh.Owner,
                                            null,
                                            keyParams,
                                            null, //outsideInfo,
                                            null, //new PcrSelection[] { creationPcr },
                                            out pubCreated,
                                            out creationData,
                                            out creationHash,
                                            out creationTicket);
        }