A
amiga500
have written a code that does encryption string to be stored into my
SQL server in the column called ID.
The encryption string is of something like this
{6F0E54FA-2C51-487E-A2A5-0412DA9FA3C6} and the code I am developing for
my PocketPC is like this, this is the class I am using in my program:
Imports System.Security.Permissions
Imports System.Runtime.InteropServices
Imports System.Net.Sockets
Public Class Utility
'
' Generate GUIDs on the .NET Compact Framework.
'
Public Class CoreGuid
' guid variant types
Private Enum GuidVariant
ReservedNCS = &H0
Standard = &H2
ReservedMicrosoft = &H6
ReservedFuture = &H7
End Enum
' guid version types
Private Enum GuidVersion
TimeBased = &H1
Reserved = &H2
NameBased = &H3
Random = &H4
End Enum
' constants that are used in the class
Private Class ConstValues
' number of bytes in guid
Public Const ByteArraySize As Integer = 16
' multiplex variant info
Public Const VariantByte As Integer = 8
Public Const VariantByteMask As Integer = &H3F
Public Const VariantByteShift As Integer = 6
' multiplex version info
Public Const VersionByte As Integer = 7
Public Const VersionByteMask As Integer = &HF
Public Const VersionByteShift As Integer = 4
End Class
' imports for the crypto api functions
Private Class WinApi
Public Const PROV_RSA_FULL As Integer = 1
Public Const CRYPT_VERIFYCONTEXT As Integer = &HF0000000
<DllImport("advapi32.dll")> _
Public Shared Function CryptAcquireContext( _
ByRef phProv As IntPtr, ByVal pszContainer As String, _
ByVal pszProvider As String, ByVal dwProvType As
Integer, _
ByVal dwFlags As Integer) As Boolean
End Function
<DllImport("advapi32.dll")> _
Public Shared Function CryptReleaseContext( _
ByVal hProv As IntPtr, ByVal dwFlags As Integer) As
Boolean
End Function
<DllImport("advapi32.dll")> _
Public Shared Function CryptGenRandom( _
ByVal hProv As IntPtr, ByVal dwLen As Integer, _
ByVal pbBuffer() As Byte) As Boolean
End Function
End Class
' all static methods
Public Sub New()
End Sub
' Return a new System.Guid object.
Public Function NewGuid() As Guid
Dim hCryptProv As IntPtr = IntPtr.Zero
Dim guid As Guid = guid.Empty
Try
' holds random bits for guid
Dim bits(ConstValues.ByteArraySize - 1) As Byte
' get crypto provider handle
If Not WinApi.CryptAcquireContext(hCryptProv, Nothing,
Nothing, _
WinApi.PROV_RSA_FULL, WinApi.CRYPT_VERIFYCONTEXT)
Then
Throw New SystemException( _
"Failed to acquire cryptography handle.")
End If
' generate a 128 bit (16 byte) cryptographically random
number
If Not WinApi.CryptGenRandom(hCryptProv, bits.Length,
bits) Then
Throw New SystemException( _
"Failed to generate cryptography random
bytes.")
End If
' set the variant
bits(ConstValues.VariantByte) =
bits(ConstValues.VariantByte) And _
CByte(ConstValues.VariantByteMask)
bits(ConstValues.VariantByte) =
bits(ConstValues.VariantByte) Or _
CByte(GuidVariant.Standard <<
ConstValues.VariantByteShift)
' set the version
bits(ConstValues.VersionByte) =
bits(ConstValues.VersionByte) And _
CByte(ConstValues.VersionByteMask)
bits(ConstValues.VersionByte) =
bits(ConstValues.VersionByte) Or _
CByte(GuidVersion.Random <<
ConstValues.VersionByteShift)
' create the new System.Guid object
guid = New Guid(bits)
Finally
' release the crypto provider handle
If Not hCryptProv.Equals(IntPtr.Zero) Then
WinApi.CryptReleaseContext(hCryptProv, 0)
End If
End Try
Return guid
End Function
End Class
End Class
It compiles correctly in my program but when I run the program in the
PockPC I get the following error:
Can't find PInvoke DLL 'advapi32.dll' error number 438. This is the
line of code I am using the function mentioned above:
Dim objGUID As New Utility.CoreGuid
Try
strSQL = "INSERT INTO InventoryLocation
(ID,ItemNumber,Location, Lasalle) VALUES ('" &
Convert.ToString(objGUID.NewGuid) & "','" & strItemNumber & "','" &
txtNewLoc.Text & "'," & Val(txtQty.Text) & ")"
objConn.Open()
objComm = New SqlCommand(strSQL, objConn)
objDataReader = objComm.ExecuteReader
objConn.Close()
Catch
MsgBox(Err.Description & " - " & Err.Number)
Exit Sub
End Try
MsgBox("Operating completed.")
lngTotalNewLasalle = 0 : lngNewLasalle = 0 :
lngLasalle = 0
lngTotalLasalle = 0
Exit Sub
Can anyone help me please? It will be greatly appreciate it. Do I need
to install Advapi32.dll into the pocketPC? If so where can I find the
install for this? Ones again appreciate it for your help in advance.
SQL server in the column called ID.
The encryption string is of something like this
{6F0E54FA-2C51-487E-A2A5-0412DA9FA3C6} and the code I am developing for
my PocketPC is like this, this is the class I am using in my program:
Imports System.Security.Permissions
Imports System.Runtime.InteropServices
Imports System.Net.Sockets
Public Class Utility
'
' Generate GUIDs on the .NET Compact Framework.
'
Public Class CoreGuid
' guid variant types
Private Enum GuidVariant
ReservedNCS = &H0
Standard = &H2
ReservedMicrosoft = &H6
ReservedFuture = &H7
End Enum
' guid version types
Private Enum GuidVersion
TimeBased = &H1
Reserved = &H2
NameBased = &H3
Random = &H4
End Enum
' constants that are used in the class
Private Class ConstValues
' number of bytes in guid
Public Const ByteArraySize As Integer = 16
' multiplex variant info
Public Const VariantByte As Integer = 8
Public Const VariantByteMask As Integer = &H3F
Public Const VariantByteShift As Integer = 6
' multiplex version info
Public Const VersionByte As Integer = 7
Public Const VersionByteMask As Integer = &HF
Public Const VersionByteShift As Integer = 4
End Class
' imports for the crypto api functions
Private Class WinApi
Public Const PROV_RSA_FULL As Integer = 1
Public Const CRYPT_VERIFYCONTEXT As Integer = &HF0000000
<DllImport("advapi32.dll")> _
Public Shared Function CryptAcquireContext( _
ByRef phProv As IntPtr, ByVal pszContainer As String, _
ByVal pszProvider As String, ByVal dwProvType As
Integer, _
ByVal dwFlags As Integer) As Boolean
End Function
<DllImport("advapi32.dll")> _
Public Shared Function CryptReleaseContext( _
ByVal hProv As IntPtr, ByVal dwFlags As Integer) As
Boolean
End Function
<DllImport("advapi32.dll")> _
Public Shared Function CryptGenRandom( _
ByVal hProv As IntPtr, ByVal dwLen As Integer, _
ByVal pbBuffer() As Byte) As Boolean
End Function
End Class
' all static methods
Public Sub New()
End Sub
' Return a new System.Guid object.
Public Function NewGuid() As Guid
Dim hCryptProv As IntPtr = IntPtr.Zero
Dim guid As Guid = guid.Empty
Try
' holds random bits for guid
Dim bits(ConstValues.ByteArraySize - 1) As Byte
' get crypto provider handle
If Not WinApi.CryptAcquireContext(hCryptProv, Nothing,
Nothing, _
WinApi.PROV_RSA_FULL, WinApi.CRYPT_VERIFYCONTEXT)
Then
Throw New SystemException( _
"Failed to acquire cryptography handle.")
End If
' generate a 128 bit (16 byte) cryptographically random
number
If Not WinApi.CryptGenRandom(hCryptProv, bits.Length,
bits) Then
Throw New SystemException( _
"Failed to generate cryptography random
bytes.")
End If
' set the variant
bits(ConstValues.VariantByte) =
bits(ConstValues.VariantByte) And _
CByte(ConstValues.VariantByteMask)
bits(ConstValues.VariantByte) =
bits(ConstValues.VariantByte) Or _
CByte(GuidVariant.Standard <<
ConstValues.VariantByteShift)
' set the version
bits(ConstValues.VersionByte) =
bits(ConstValues.VersionByte) And _
CByte(ConstValues.VersionByteMask)
bits(ConstValues.VersionByte) =
bits(ConstValues.VersionByte) Or _
CByte(GuidVersion.Random <<
ConstValues.VersionByteShift)
' create the new System.Guid object
guid = New Guid(bits)
Finally
' release the crypto provider handle
If Not hCryptProv.Equals(IntPtr.Zero) Then
WinApi.CryptReleaseContext(hCryptProv, 0)
End If
End Try
Return guid
End Function
End Class
End Class
It compiles correctly in my program but when I run the program in the
PockPC I get the following error:
Can't find PInvoke DLL 'advapi32.dll' error number 438. This is the
line of code I am using the function mentioned above:
Dim objGUID As New Utility.CoreGuid
Try
strSQL = "INSERT INTO InventoryLocation
(ID,ItemNumber,Location, Lasalle) VALUES ('" &
Convert.ToString(objGUID.NewGuid) & "','" & strItemNumber & "','" &
txtNewLoc.Text & "'," & Val(txtQty.Text) & ")"
objConn.Open()
objComm = New SqlCommand(strSQL, objConn)
objDataReader = objComm.ExecuteReader
objConn.Close()
Catch
MsgBox(Err.Description & " - " & Err.Number)
Exit Sub
End Try
MsgBox("Operating completed.")
lngTotalNewLasalle = 0 : lngNewLasalle = 0 :
lngLasalle = 0
lngTotalLasalle = 0
Exit Sub
Can anyone help me please? It will be greatly appreciate it. Do I need
to install Advapi32.dll into the pocketPC? If so where can I find the
install for this? Ones again appreciate it for your help in advance.