none
VB6 Security DLL's equivalent in C# RRS feed

All replies

  • It would be helpful to know what specifically you are trying to accomplish.  You can always use pinvoke to call secur32.dll, but I am guessing the functionality you want is exposed elsewhere already in the .Net framework.
    Wednesday, May 13, 2015 11:27 AM
  • Hi,

    I am migrating a legacy VB6 application that is having use of above two security DLLs and I wants to replace these with equivalent .NET class.

    Below are the list of methods used-

      
    Private Declare Function NT4QuerySecurityPackageInfo Lib "security" _
          Alias "QuerySecurityPackageInfoA" (ByVal PackageName As String, _
          ByRef pPackageInfo As Long) As Long

    Private Declare Function QuerySecurityPackageInfo Lib "secur32" _
          Alias "QuerySecurityPackageInfoA" (ByVal PackageName As String, _
          ByRef pPackageInfo As Long) As Long

    Private Declare Function NT4FreeContextBuffer Lib "security" _
          Alias "FreeContextBuffer" (ByVal pvContextBuffer As Long) As Long

    Private Declare Function FreeContextBuffer Lib "secur32" _
          (ByVal pvContextBuffer As Long) As Long

    Private Declare Function NT4InitializeSecurityContext Lib "security" _
          Alias "InitializeSecurityContextA" _
          (ByRef phCredential As SecHandle, ByRef phContext As SecHandle, _
          ByVal pszTargetName As Long, ByVal fContextReq As Long, _
          ByVal Reserved1 As Long, ByVal TargetDataRep As Long, _
          ByRef pInput As SecBufferDesc, ByVal Reserved2 As Long, _
          ByRef phNewContext As SecHandle, ByRef pOutput As SecBufferDesc, _
          ByRef pfContextAttr As Long, ByRef ptsExpiry As TimeStamp) As Long

    Private Declare Function InitializeSecurityContext Lib "secur32" _
          Alias "InitializeSecurityContextA" _
          (ByRef phCredential As SecHandle, ByRef phContext As SecHandle, _
          ByVal pszTargetName As Long, ByVal fContextReq As Long, _
          ByVal Reserved1 As Long, ByVal TargetDataRep As Long, _
          ByRef pInput As SecBufferDesc, ByVal Reserved2 As Long, _
          ByRef phNewContext As SecHandle, ByRef pOutput As SecBufferDesc, _
          ByRef pfContextAttr As Long, ByRef ptsExpiry As TimeStamp) As Long

    Private Declare Function NT4InitializeSecurityContext2 Lib "security" _
          Alias "InitializeSecurityContextA" _
          (ByRef phCredential As SecHandle, ByVal phContext As Long, _
          ByVal pszTargetName As Long, ByVal fContextReq As Long, _
          ByVal Reserved1 As Long, ByVal TargetDataRep As Long, _
          ByVal pInput As Long, ByVal Reserved2 As Long, _
          ByRef phNewContext As SecHandle, ByRef pOutput As SecBufferDesc, _
          ByRef pfContextAttr As Long, ByRef ptsExpiry As TimeStamp) As Long

    Private Declare Function InitializeSecurityContext2 Lib "secur32" _
          Alias "InitializeSecurityContextA" _
          (ByRef phCredential As SecHandle, ByVal phContext As Long, _
          ByVal pszTargetName As Long, ByVal fContextReq As Long, _
          ByVal Reserved1 As Long, ByVal TargetDataRep As Long, _
          ByVal pInput As Long, ByVal Reserved2 As Long, _
          ByRef phNewContext As SecHandle, ByRef pOutput As SecBufferDesc, _
          ByRef pfContextAttr As Long, ByRef ptsExpiry As TimeStamp) As Long

    Private Declare Function NT4AcquireCredentialsHandle Lib "security" _
          Alias "AcquireCredentialsHandleA" (ByVal pszPrincipal As Long, _
          ByVal pszPackage As String, ByVal fCredentialUse As Long, _
          ByVal pvLogonId As Long, _
          ByRef pAuthData As SEC_WINNT_AUTH_IDENTITY, _
          ByVal pGetKeyFn As Long, ByVal pvGetKeyArgument As Long, _
          ByRef phCredential As SecHandle, ByRef ptsExpiry As TimeStamp) _
          As Long
          
    Private Declare Function AcquireCredentialsHandle Lib "secur32" _
          Alias "AcquireCredentialsHandleA" (ByVal pszPrincipal As Long, _
          ByVal pszPackage As String, ByVal fCredentialUse As Long, _
          ByVal pvLogonId As Long, _
          ByRef pAuthData As SEC_WINNT_AUTH_IDENTITY, _
          ByVal pGetKeyFn As Long, ByVal pvGetKeyArgument As Long, _
          ByRef phCredential As SecHandle, ByRef ptsExpiry As TimeStamp) _
          As Long
          
    Private Declare Function NT4AcquireCredentialsHandle2 Lib "security" _
          Alias "AcquireCredentialsHandleA" (ByVal pszPrincipal As Long, _
          ByVal pszPackage As String, ByVal fCredentialUse As Long, _
          ByVal pvLogonId As Long, ByVal pAuthData As Long, _
          ByVal pGetKeyFn As Long, ByVal pvGetKeyArgument As Long, _
          ByRef phCredential As SecHandle, ByRef ptsExpiry As TimeStamp) _
          As Long
          
    Private Declare Function AcquireCredentialsHandle2 Lib "secur32" _
          Alias "AcquireCredentialsHandleA" (ByVal pszPrincipal As Long, _
          ByVal pszPackage As String, ByVal fCredentialUse As Long, _
          ByVal pvLogonId As Long, ByVal pAuthData As Long, _
          ByVal pGetKeyFn As Long, ByVal pvGetKeyArgument As Long, _
          ByRef phCredential As SecHandle, ByRef ptsExpiry As TimeStamp) _
          As Long
          
    Private Declare Function NT4AcceptSecurityContext Lib "security" _
          Alias "AcceptSecurityContext" (ByRef phCredential As SecHandle, _
          ByRef phContext As SecHandle, ByRef pInput As SecBufferDesc, _
          ByVal fContextReq As Long, ByVal TargetDataRep As Long, _
          ByRef phNewContext As SecHandle, ByRef pOutput As SecBufferDesc, _
          ByRef pfContextAttr As Long, ByRef ptsExpiry As TimeStamp) As Long

    Private Declare Function AcceptSecurityContext Lib "secur32" _
          (ByRef phCredential As SecHandle, _
          ByRef phContext As SecHandle, ByRef pInput As SecBufferDesc, _
          ByVal fContextReq As Long, ByVal TargetDataRep As Long, _
          ByRef phNewContext As SecHandle, ByRef pOutput As SecBufferDesc, _
          ByRef pfContextAttr As Long, ByRef ptsExpiry As TimeStamp) As Long

    Private Declare Function NT4AcceptSecurityContext2 Lib "security" _
          Alias "AcceptSecurityContext" (ByRef phCredential As SecHandle, _
          ByVal phContext As Long, ByRef pInput As SecBufferDesc, _
          ByVal fContextReq As Long, ByVal TargetDataRep As Long, _
          ByRef phNewContext As SecHandle, ByRef pOutput As SecBufferDesc, _
          ByRef pfContextAttr As Long, ByRef ptsExpiry As TimeStamp) As Long

    Private Declare Function AcceptSecurityContext2 Lib "secur32" _
          Alias "AcceptSecurityContext" (ByRef phCredential As SecHandle, _
          ByVal phContext As Long, ByRef pInput As SecBufferDesc, _
          ByVal fContextReq As Long, ByVal TargetDataRep As Long, _
          ByRef phNewContext As SecHandle, ByRef pOutput As SecBufferDesc, _
          ByRef pfContextAttr As Long, ByRef ptsExpiry As TimeStamp) As Long

    Private Declare Function NT4CompleteAuthToken Lib "security" _
          Alias "CompleteAuthToken" (ByRef phContext As SecHandle, _
          ByRef pToken As SecBufferDesc) As Long

    Wednesday, May 13, 2015 11:34 AM
  • You may want to look into PInvoke then, it is the equivalent of Declare Function in VB.

    These MSDN Links should help you a lot:

    https://msdn.microsoft.com/en-us/library/e59b22c5.aspx

    https://msdn.microsoft.com/en-us/library/aa288468%28v=vs.71%29.aspx

    Also this is a site that has a number of PInvoke method signatures already created:

    http://pinvoke.net/

    They have a number of the methods from Secur32.dll already converted for you.  It is community driven so there is no guaranty that they are accurate.

    Wednesday, May 13, 2015 11:41 AM
  • No, I m looking for its equivalent .NET framework class not PInvoke/API. PInvoke is same as declare function in VB6.
    Wednesday, May 13, 2015 11:45 AM
  • In that case, it would be more helpful if you would explain the problem you are trying to solve?
    Wednesday, May 13, 2015 11:59 AM
  • As I mentioned earlier, application is using API

    Private Declare Function NT4QuerySecurityPackageInfo Lib "security" _
          Alias "QuerySecurityPackageInfoA" (ByVal PackageName As String, _
          ByRef pPackageInfo As Long) As Long

    and I wants to replace it with its equivalent .net class

    Wednesday, May 13, 2015 12:02 PM
  • I understand that is the Old API that you were using.  If you want to just use the API, PInvoke is the only option.  If you have an application (Securing a connection, validating credentials, etc.), There may be equivalent functionality in the framework but there may not be a 1 for 1 equivalent of the QuerySecurityPackageInfo method.  If you could explain what you are trying to do it will help provide you an answer.
    Wednesday, May 13, 2015 12:13 PM
  • Emmm, you should just use QuerySecurityPackageInfo() because it's just there to preserve NT4 compatibility (which is important for applications at the time of VB6 but of little value for current applications)

    I concur with what mageos said, the authentication machnism in .NET framework is spread into different namespace. You have to tell us what security package(s) you're going to use in order to tell you what corresponding classes you need to replace the function.


    Thursday, May 14, 2015 1:50 AM
    Answerer