本文整理汇总了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;
}