コード例 #1
0
        private void CreateCertContext(string name, DateTime start, DateTime expire)
        {
            CriticalAllocHandle providerInfo = this.GetProviderInfo();
            CriticalAllocHandle handle2      = GetSha1AlgorithmId();
            SystemTime          pStartTime   = new SystemTime(start);
            SystemTime          pEndTime     = new SystemTime(expire);
            CertificateName     name2        = new CertificateName(name);

            using (CryptoApiBlob blob = name2.GetCryptoApiBlob())
            {
                using (providerInfo)
                {
                    using (handle2)
                    {
                        this.cert = CertCreateSelfSignCertificate(this.keyContainer, blob.GetMemoryForPinning(), SelfSignFlags.None, (IntPtr)providerInfo, (IntPtr)handle2, ref pStartTime, ref pEndTime, IntPtr.Zero);
                        if (this.cert.IsInvalid)
                        {
                            PeerExceptionHelper.ThrowInvalidOperation_PeerCertGenFailure(PeerExceptionHelper.GetLastException());
                        }
                        if (!CertSetCertificateContextProperty(this.cert, 1, 0, this.key))
                        {
                            PeerExceptionHelper.ThrowInvalidOperation_PeerCertGenFailure(PeerExceptionHelper.GetLastException());
                        }
                    }
                }
            }
        }
コード例 #2
0
        public static CriticalAllocHandle FromBlob <T>(T id)
        {
            CriticalAllocHandle handle = CriticalAllocHandle.FromSize(Marshal.SizeOf(typeof(T)));

            Marshal.StructureToPtr(id, (IntPtr)handle, false);
            return(handle);
        }
コード例 #3
0
        public static CriticalAllocHandle FromGuid(Guid input)
        {
            int size = Marshal.SizeOf(typeof(Guid));
            CriticalAllocHandle handle = CriticalAllocHandle.FromSize(size);

            Marshal.Copy(input.ToByteArray(), 0, (IntPtr)handle, size);
            return(handle);
        }
コード例 #4
0
        public static CriticalAllocHandle FromGuid(Guid input)
        {
            int guidSize = Marshal.SizeOf(typeof(Guid));
            CriticalAllocHandle result = CriticalAllocHandle.FromSize(guidSize);

            Marshal.Copy(input.ToByteArray(), 0, (IntPtr)result, guidSize);
            return(result);
        }
コード例 #5
0
        public static CriticalAllocHandle FromBlob <T>(T id)
        {
            int size = Marshal.SizeOf(typeof(T));
            CriticalAllocHandle result = CriticalAllocHandle.FromSize(size);

            Marshal.StructureToPtr(id, (IntPtr)result, false);
            return(result);
        }
コード例 #6
0
        public static CriticalAllocHandle FromSize(int size)
        {
            CriticalAllocHandle result = new CriticalAllocHandle();

            RuntimeHelpers.PrepareConstrainedRegions();
            try { }
            finally
            {
                result.SetHandle(Marshal.AllocHGlobal(size));
            }
            return(result);
        }
 public void AllocateBlob(int size)
 {
     data   = CriticalAllocHandle.FromSize(size);
     cbData = size;
 }