public unsafe byte[] QueryContextAttributeSession() { SecPkgContext_SessionKey pBuffer = default; SecStatus status; byte[] bytes = null; RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { try { status = QueryContextAttributesSession(ref this.securityContext, SecurityContextAttribute.SECPKG_ATTR_SESSION_KEY, ref pBuffer); if (status == SecStatus.SEC_E_OK) { bytes = new Span <byte>(pBuffer.SessionKey, (int)pBuffer.SessionKeyLength).ToArray(); } } finally { ThrowIfError(FreeContextBuffer(pBuffer.SessionKey)); } } if (status != SecStatus.SEC_E_UNSUPPORTED_FUNCTION && status > SecStatus.SEC_E_ERROR) { throw new Win32Exception((int)status); } return(bytes); }
private static extern uint QueryContextAttributes( ref SecHandle phContext, uint ulAttribute, out SecPkgContext_SessionKey value);
internal static extern SecStatus QueryContextAttributesSession( ref SECURITY_HANDLE phContext, SecurityContextAttribute ulAttribute, ref SecPkgContext_SessionKey pBuffer );
public static extern int QueryContextAttributes( ref SECURITY_HANDLE phContext, uint ulAttribute, out SecPkgContext_SessionKey pSessKeyOut);