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()); } } } } }
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()); } } } } }
void CreateCertContext(string name, DateTime start, DateTime expire) { CriticalAllocHandle provInfo; CriticalAllocHandle algorithmId; provInfo = GetProviderInfo(); algorithmId = GetSha1AlgorithmId(); // convert the times to SystemTime structures SystemTime beginTime = new SystemTime(start); SystemTime expireTime = new SystemTime(expire); // convert the name into a X500 name CertificateName certName = new CertificateName(name); using (CryptoApiBlob nameBlob = certName.GetCryptoApiBlob()) { using (provInfo) { using (algorithmId) { cert = CertCreateSelfSignCertificate(keyContainer, nameBlob.GetMemoryForPinning(), SelfSignFlags.None, provInfo, algorithmId, ref beginTime, ref expireTime, IntPtr.Zero); if (cert.IsInvalid) { PeerExceptionHelper.ThrowInvalidOperation_PeerCertGenFailure(PeerExceptionHelper.GetLastException()); } // if (!CertSetCertificateContextProperty(cert, CERT_KEY_PROV_INFO_PROP_ID, 0, provInfo)) // PeerExceptionHelper.ThrowInvalidOperation_PeerCertGenFailure(PeerExceptionHelper.GetLastException()); if (!CertSetCertificateContextProperty(cert, CERT_KEY_SPEC_PROP_ID, 0, key)) { PeerExceptionHelper.ThrowInvalidOperation_PeerCertGenFailure(PeerExceptionHelper.GetLastException()); } } } } }
void CreateCertContext(string name, DateTime start, DateTime expire) { CriticalAllocHandle provInfo; CriticalAllocHandle algorithmId; provInfo = GetProviderInfo(); algorithmId = GetSha1AlgorithmId(); // convert the times to SystemTime structures SystemTime beginTime = new SystemTime(start); SystemTime expireTime = new SystemTime(expire); // convert the name into a X500 name CertificateName certName = new CertificateName(name); using (CryptoApiBlob nameBlob = certName.GetCryptoApiBlob()) { using (provInfo) { using (algorithmId) { cert = CertCreateSelfSignCertificate(keyContainer, nameBlob.GetMemoryForPinning(), SelfSignFlags.None, provInfo, algorithmId, ref beginTime, ref expireTime, IntPtr.Zero); if (cert.IsInvalid) PeerExceptionHelper.ThrowInvalidOperation_PeerCertGenFailure(PeerExceptionHelper.GetLastException()); // if (!CertSetCertificateContextProperty(cert, CERT_KEY_PROV_INFO_PROP_ID, 0, provInfo)) // PeerExceptionHelper.ThrowInvalidOperation_PeerCertGenFailure(PeerExceptionHelper.GetLastException()); if (!CertSetCertificateContextProperty(cert, CERT_KEY_SPEC_PROP_ID, 0, key)) PeerExceptionHelper.ThrowInvalidOperation_PeerCertGenFailure(PeerExceptionHelper.GetLastException()); } } } }