Encryption and Decryption


John Smith

Operating System: PocketPC 2003 (Emulator)
Language: VB.NET

I have downloaded the "Pocket PC Signature Application Sample" from
Microsoft's website
html/PPCSignatureApp.asp) and have gotten it to work successfully. I am
trying to rip-off the Encryption and Decryption capability from the sample
application and put it into another application that contains passwords in
it. My problem is that after I have duplicated (add existing item...) the 6
vb class files into my project and call the "Crypto.Encrypt()" Function
through my test run I receive a MissingMethodException Error. I did not
change the vb class files whatsoever. I didn't do anything more other than
"add existing item..." The build finishes successfully.

Any ideas? Thanx in Advance. (Sample Code Below)

'Code with Error: (Crypto.vb - Encrypt Function)

' Encrypt data. Use passphrase to generate the encryption key.
' Returns a byte array that contains the encrypted data.

Public Shared Function Encrypt(ByVal passphrase As String, ByVal data() As
Byte) As Byte()

' holds encrypted data
Dim buffer As Byte() = Nothing

' crypto handles
Dim hProv As IntPtr = IntPtr.Zero
Dim hKey As IntPtr = IntPtr.Zero

' get crypto provider, specify the provider (3rd argument)
' instead of using default to ensure the same provider is
' used on client and server

' This next line generated the error.

If Not WinApi.CryptAcquireContext(hProv, Nothing, WinApi.MS_DEF_PROV, _
End If

'**** Etc... (Code)

'Sample Code to call function:

Private Sub MySubroutine()

' Initialization vector converted to a byte array.
Dim initString() As Byte = Nothing

' Get bytes of initialization vector.
If (txtTitle.Text Is Nothing) Then
initString = New Byte() {}
initString = Encoding.ASCII.GetBytes(txtPassword.Text)
End If

' encrypt the signature data
Dim encryptData As Byte() =

' update the encrypted view
txtUserName.Text = Encoding.ASCII.GetString(encryptData, 0,

End Sub

Thanx in Advance,
John Smith

Sergey Bogdanov

Make sure that you have defined Conditional Compilation Constant -
COMPACT_FRAMEWORK (see Project -> Properties -> Configuration
Properties -> Build -> Conditional Compilation Constants) otherwise it
will be using advapi32.dll that doesn't exist in the PPC:

Const CryptDll As String = "coredll.dll"
Const CryptDll As String = "advapi32.dll"
#End If

Best regards,
Sergey Bogdanov

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question