本文整理匯總了C#中System.Security.Cryptography.SafeEvpPKeyHandle.SetHandle方法的典型用法代碼示例。如果您正苦於以下問題:C# SafeEvpPKeyHandle.SetHandle方法的具體用法?C# SafeEvpPKeyHandle.SetHandle怎麽用?C# SafeEvpPKeyHandle.SetHandle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Security.Cryptography.SafeEvpPKeyHandle
的用法示例。
在下文中一共展示了SafeEvpPKeyHandle.SetHandle方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DuplicateHandle
/// <summary>
/// Create another instance of SafeEvpPKeyHandle which has an independent lifetime
/// from this instance, but tracks the same resource.
/// </summary>
/// <returns>An equivalent SafeEvpPKeyHandle with a different lifetime</returns>
public SafeEvpPKeyHandle DuplicateHandle()
{
if (IsInvalid)
throw new InvalidOperationException(SR.Cryptography_OpenInvalidHandle);
// Reliability: Allocate the SafeHandle before calling UpRefEvpPkey so
// that we don't lose a tracked reference in low-memory situations.
SafeEvpPKeyHandle safeHandle = new SafeEvpPKeyHandle();
int newRefCount = Interop.Crypto.UpRefEvpPkey(this);
// UpRefEvpPkey returns the number of references to this key, if it's less than 2
// (the incoming handle, and this one) then someone has already Disposed() this key
// into non-existence.
if (newRefCount < 2)
{
Debug.Fail("Called UpRefEvpPkey on a key which was already marked for destruction");
throw Interop.Crypto.CreateOpenSslCryptographicException();
}
// Since we didn't actually create a new handle, copy the handle
// to the new SafeHandle.
safeHandle.SetHandle(handle);
return safeHandle;
}