Encryption and Decryption

J

John Smith

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

I have downloaded the "Pocket PC Signature Application Sample" from
Microsoft's website
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/
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

Try
' 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, _
WinApi.PROV_RSA_FULL, WinApi.CRYPT_VERIFYCONTEXT) Then
Failed("CryptAcquireContext")
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() {}
Else
initString = Encoding.ASCII.GetBytes(txtPassword.Text)
End If

' encrypt the signature data
Dim encryptData As Byte() =
Crypto.Encrypt(Global.Settings.GetString(SettingKeys.CryptPassphrase),
initString)

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

End Sub


Thanx in Advance,
John Smith
 
S

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:

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


Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 

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

Top