在vb中,怎样生成key pair(public key,private key),用哪个函数,我找资料是说,advapi32.dll里面包含有,但具体该如何声明呢,用C#可以System.Security.Cryptography namespace,但现在是我要做成activeX控件,请各位同仁帮忙!
谢谢!

解决方案 »

  1.   

    Private Declare Function CryptSignHashA Lib “advapi32.dll" (ByVal hHash As Long, _
    ByVal dwKeySpec As Long, ByVal sDescription As String, ByVal dwFlags As Long, _
      ByRef pbSignature As Byte, pdwSigLen As Long) As LongPrivate Declare Function CryptVerifySignatureA Lib “advapi32.dll" (ByVal hHash As Long, _
    ByRef pbSignature As Byte, ByVal dwSigLen As Long, ByVal hPubKey As Long, _
      ByVal sDescription As String, ByVal dwFlags As Long) As Long
      

  2.   

    Option Explicit
    Private Type GUID
     Data1 As Long 
     Data2 As Long
     Data3 As Long
     Data4(8) As Byte
    End Type
    Private Declare Function CoCreateGuid Lib "ole32.dll" (pguid As GUID) As Long
    Private Declare Function StringFromGUID2 Lib "ole32.dll"(rguid As Any,ByVal lpstrClsId As Long,ByVal cbMax As Long) As Long Private Function GUIDGen() As String
     Dim uGUID As GUID 
     Dim sGUID As String 
     Dim bGUID() As Byte 
     Dim lLen As Long 
     Dim RetVal As Long 
     lLen = 40 
     bGUID = String(lLen, 0) 
     CoCreateGuid uGUID ’把结构转换为一个可显示的字符串 
     RetVal = StringFromGUID2(uGUID, VarPtr(bGUID(0)), lLen) 
     sGUID = bGUID
     If (Asc(Mid$(sGUID, RetVal, 1)) = 0) Then RetVal = RetVal - 1 
     GUIDGen = Left$(sGUID, RetVal) 
    End Function Private Sub cmdGUID_Click() 
     txtGUID.Text = GUIDGen 
    End Sub
      

  3.   

    在msdn中,找到了CrptGenKey这个函数,但在vb中怎么声明