VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,469 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,737 people online right now. Registration is fast and FREE... Join Now!




dll encryption

 

dll encryption

rjhe22

15 Sep, 2008 - 02:26 AM
Post #1

New D.I.C Head
*

Joined: 15 Sep, 2008
Posts: 10

i have the clslock but i need to reference it to get it to work any ideas


A new class clsLock provides:
1) Encryption
2) Decryption
3) Key Setting from String

The model used is the Triple DES (Data Encryption Standard)

This requires a 24 Byte Key and an 8 Byte Initialization Vector

Both must be known to decrypt

The IV is fixed in the class, but the Key can be changed via KeyFromString Function.

This way a specific key could be used by an application.


The idea is to encrypt things like passwords or other sensitive data in varbinary columns in the database. SQL provides its own encryption but it is generally considered to be weak

Applications can freely use the data but no query, Access or alien application can read the data without knowing

1) The encryption scheme,
2) The 24 byte key as its string or byte version
3) The 8 byte vector

We are protecting the source code and implementing the class as a standalone DLL, so the details are in compiled code and in secured source

User is offlineProfile CardPM
+Quote Post


rjhe22

RE: Dll Encryption

15 Sep, 2008 - 05:55 AM
Post #2

New D.I.C Head
*

Joined: 15 Sep, 2008
Posts: 10

can anyone help with this. i have the key and stuff in a dll file and i just need someone to help me figure out how to refer to it
User is offlineProfile CardPM
+Quote Post

magicmonkey

RE: Dll Encryption

15 Sep, 2008 - 06:10 AM
Post #3

D.I.C Regular
***

Joined: 12 Sep, 2008
Posts: 484



Thanked: 97 times
My Contributions
QUOTE(rjhe22 @ 15 Sep, 2008 - 06:55 AM) *

can anyone help with this. i have the key and stuff in a dll file and i just need someone to help me figure out how to refer to it


Could you post your current code? Or are you so lost that you haven't yet added a reference to the dll in your project? Click add refrence and browse for the .dll then see if you can declare an instance of your class. Good practice would be to include the encryption project in the main project so it gets compiled everytime chages are made and so that you can easily debug the class.


User is offlineProfile CardPM
+Quote Post

rjhe22

RE: Dll Encryption

15 Sep, 2008 - 06:14 AM
Post #4

New D.I.C Head
*

Joined: 15 Sep, 2008
Posts: 10

i have added the reference for the dll. after that im not sure what to do and thats where im stuck. any help would be great as i am new to .net
User is offlineProfile CardPM
+Quote Post

magicmonkey

RE: Dll Encryption

15 Sep, 2008 - 06:47 AM
Post #5

D.I.C Regular
***

Joined: 12 Sep, 2008
Posts: 484



Thanked: 97 times
My Contributions
QUOTE(rjhe22 @ 15 Sep, 2008 - 07:14 AM) *

i have added the reference for the dll. after that im not sure what to do and thats where im stuck. any help would be great as i am new to .net


Okay in the encryption dll project open up the project properties by dlb clicking on My Project in the solution explorer. Now select the Application tab and make note of the Root namespace, for this example I will assume it is 'DLLEncryption'. Now go back to your main project and try this...

CODE

   Dim MyEncryption as New DLLEncryption.MyEncryptionClass


You can also browse the object explorer in your main project by pressing CTRL-ALT-J. From this window you can see all your referenced assemblies and their classes. Right click on the encryption class you want to reference, select COPY and then you can PASTE it into your code.

Hope that helps,


User is offlineProfile CardPM
+Quote Post

rjhe22

RE: Dll Encryption

15 Sep, 2008 - 06:54 AM
Post #6

New D.I.C Head
*

Joined: 15 Sep, 2008
Posts: 10

ok i got an error there is no source code available for this location
User is offlineProfile CardPM
+Quote Post

magicmonkey

RE: Dll Encryption

15 Sep, 2008 - 07:02 AM
Post #7

D.I.C Regular
***

Joined: 12 Sep, 2008
Posts: 484



Thanked: 97 times
My Contributions
QUOTE(rjhe22 @ 15 Sep, 2008 - 07:54 AM) *

ok i got an error there is no source code available for this location


Now that you have code trying to create an instance of the class please post it. Don't forget to put it in the code tags.

This post has been edited by magicmonkey: 15 Sep, 2008 - 07:05 AM
User is offlineProfile CardPM
+Quote Post

rjhe22

RE: Dll Encryption

15 Sep, 2008 - 07:42 AM
Post #8

New D.I.C Head
*

Joined: 15 Sep, 2008
Posts: 10

CODE
Option Explicit On
Option Strict Off

Imports System.Windows.Forms

Imports CIMALock
Imports System.Security.Cryptography
Imports System.Text
Imports System
Imports System.IO



Public Class dlgMailSetup
    Private _mainTable As DataTable
    Private _data As clsData
    Private _mailSetup As DataTable
    Private _lock As clsLock

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me._data = New clsData
        'Me._data.Connect("Harvest")
        Me._data.Connect("Admin")
    
        Me._mailSetup = New DataTable("MailSetup")
        Me._data.LoadProc(Me._mailSetup)

        Me.txtMailService.DataBindings.Add("Text", Me._mailSetup, "MailService")
        Me.txtMailPOP.DataBindings.Add("Text", Me._mailSetup, "MailPOP")
        Me.txtMailSMTP.DataBindings.Add("Text", Me._mailSetup, "MailSMTP")
        Me.txtMailUser.DataBindings.Add("Text", Me._mailSetup, "MailUser")
        Me.txtMailKey.DataBindings.Add("Text", Me._mailSetup, "MailKey")
        Me.txtPortIn.DataBindings.Add("Text", Me._mailSetup, "PortIn")
        Me.txtPortOut.DataBindings.Add("Text", Me._mailSetup, "PortOut")


    End Sub
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        If Me.editCheck() = True Then


            Dim MyEncryption As New CIMABank.MyEncryption
            Me._data.UpdateFromTable(Me._mailSetup)
            Me.DialogResult = System.Windows.Forms.DialogResult.OK
            Me.Close()

        End If
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Function editCheck() As Boolean
        'check for completeness
        'called after OK button is hit
        Dim blnOK As Boolean = True
        Dim strMessage As String = ""



        If String.IsNullOrEmpty(Me.txtMailKey.Text.Trim) Then
            blnOK = False
            strMessage &= "Password Cannot be blank" & vbCrLf
        Else
            If String.IsNullOrEmpty(Me.txtMailKeyVerify.Text.Trim) Then
                blnOK = False
                strMessage &= "Password Cannot be blank" & vbCrLf
            End If
        End If

        If txtMailKey.Text <> txtMailKeyVerify.Text Then
            blnOK = False
            strMessage &= "Password does not match" & vbCrLf
        End If
        'Show the accumulated errors if any
        If blnOK = False Then
            strMessage = "The following error(s) must be resolved before proceeding" & vbCrLf & vbCrLf & strMessage
        End If

        'is True only if every check is passed
        Return blnOK

    End Function
    

End Class


this is all i have done with it.
cimalock is the dll file
User is offlineProfile CardPM
+Quote Post

magicmonkey

RE: Dll Encryption

15 Sep, 2008 - 09:05 AM
Post #9

D.I.C Regular
***

Joined: 12 Sep, 2008
Posts: 484



Thanked: 97 times
My Contributions
QUOTE(rjhe22 @ 15 Sep, 2008 - 08:42 AM) *

CODE
Option Explicit On
Option Strict Off

Imports System.Windows.Forms

Imports CIMALock
Imports System.Security.Cryptography
Imports System.Text
Imports System
Imports System.IO



Public Class dlgMailSetup
    Private _mainTable As DataTable
    Private _data As clsData
    Private _mailSetup As DataTable
    Private _lock As clsLock

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me._data = New clsData
        'Me._data.Connect("Harvest")
        Me._data.Connect("Admin")
    
        Me._mailSetup = New DataTable("MailSetup")
        Me._data.LoadProc(Me._mailSetup)

        Me.txtMailService.DataBindings.Add("Text", Me._mailSetup, "MailService")
        Me.txtMailPOP.DataBindings.Add("Text", Me._mailSetup, "MailPOP")
        Me.txtMailSMTP.DataBindings.Add("Text", Me._mailSetup, "MailSMTP")
        Me.txtMailUser.DataBindings.Add("Text", Me._mailSetup, "MailUser")
        Me.txtMailKey.DataBindings.Add("Text", Me._mailSetup, "MailKey")
        Me.txtPortIn.DataBindings.Add("Text", Me._mailSetup, "PortIn")
        Me.txtPortOut.DataBindings.Add("Text", Me._mailSetup, "PortOut")


    End Sub
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        If Me.editCheck() = True Then


            Dim MyEncryption As New CIMABank.MyEncryption
            Me._data.UpdateFromTable(Me._mailSetup)
            Me.DialogResult = System.Windows.Forms.DialogResult.OK
            Me.Close()

        End If
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Function editCheck() As Boolean
        'check for completeness
        'called after OK button is hit
        Dim blnOK As Boolean = True
        Dim strMessage As String = ""



        If String.IsNullOrEmpty(Me.txtMailKey.Text.Trim) Then
            blnOK = False
            strMessage &= "Password Cannot be blank" & vbCrLf
        Else
            If String.IsNullOrEmpty(Me.txtMailKeyVerify.Text.Trim) Then
                blnOK = False
                strMessage &= "Password Cannot be blank" & vbCrLf
            End If
        End If

        If txtMailKey.Text <> txtMailKeyVerify.Text Then
            blnOK = False
            strMessage &= "Password does not match" & vbCrLf
        End If
        'Show the accumulated errors if any
        If blnOK = False Then
            strMessage = "The following error(s) must be resolved before proceeding" & vbCrLf & vbCrLf & strMessage
        End If

        'is True only if every check is passed
        Return blnOK

    End Function
    

End Class


this is all i have done with it.
cimalock is the dll file


The only line of code I see related to cimalock is 'Dim MyEncryption As New CIMABank.MyEncryption'? Is that were the error is being thrown?

My guess is that your cimalock.dll is throwing an unhandled error during its initialization and VS can't find the source code to show you the error. This is one of the reason i suggested earlier about including cimalock project into your solution, remove the direct reference to cimalock.dll and add a project reference to the cimalock project. Now when the error is thrown in your cimalock classes VS will break into the cimalock project at the error.


User is offlineProfile CardPM
+Quote Post

rjhe22

RE: Dll Encryption

16 Sep, 2008 - 12:26 AM
Post #10

New D.I.C Head
*

Joined: 15 Sep, 2008
Posts: 10

ok i think i will do it that way. but if i do it and they ask me to do it the other way would you have an idea on how to do that
User is offlineProfile CardPM
+Quote Post

magicmonkey

RE: Dll Encryption

16 Sep, 2008 - 04:58 AM
Post #11

D.I.C Regular
***

Joined: 12 Sep, 2008
Posts: 484



Thanked: 97 times
My Contributions
QUOTE(rjhe22 @ 16 Sep, 2008 - 01:26 AM) *

ok i think i will do it that way. but if i do it and they ask me to do it the other way would you have an idea on how to do that


There is technically no difference between the two methods from a deployment standpoint. VS will still compile the CIMALock project into its own dll. It just simplifies your development process.
User is offlineProfile CardPM
+Quote Post

rjhe22

RE: Dll Encryption

16 Sep, 2008 - 05:30 AM
Post #12

New D.I.C Head
*

Joined: 15 Sep, 2008
Posts: 10

ok thats great thanks for all the help
User is offlineProfile CardPM
+Quote Post

rjhe22

RE: Dll Encryption

17 Sep, 2008 - 07:33 AM
Post #13

New D.I.C Head
*

Joined: 15 Sep, 2008
Posts: 10

im geeting Index -1 does not have a value with the following code
CODE
Dim lck As New CIMALock.clsLock
            Dim rowC As DataRow = CType(Me.txtMailKey.DataBindings(0).BindingManagerBase.Current, DataRowView).Row
            rowC.Item("MailKey") = lck.Encrypt(Me.txtMailKey.Text)


any ideas on this error
User is offlineProfile CardPM
+Quote Post

magicmonkey

RE: Dll Encryption

17 Sep, 2008 - 08:51 AM
Post #14

D.I.C Regular
***

Joined: 12 Sep, 2008
Posts: 484



Thanked: 97 times
My Contributions
QUOTE(rjhe22 @ 17 Sep, 2008 - 08:33 AM) *

im geeting Index -1 does not have a value with the following code
CODE
Dim lck As New CIMALock.clsLock
            Dim rowC As DataRow = CType(Me.txtMailKey.DataBindings(0).BindingManagerBase.Current, DataRowView).Row
            rowC.Item("MailKey") = lck.Encrypt(Me.txtMailKey.Text)


any ideas on this error


Either DataBindings(0) or rowC.item("MailKey") is not a valid index. When the error occurs type the following in the immediate window.

? rowC.Item("MailKey")
? Me.txtMailKey.DataBindings(0)

and see if the error matches, "MailKey" is probably not the correct field name.
User is offlineProfile CardPM
+Quote Post

rjhe22

RE: Dll Encryption

17 Sep, 2008 - 08:57 AM
Post #15

New D.I.C Head
*

Joined: 15 Sep, 2008
Posts: 10

got this back


? rowC.Item("MailKey")
'rowC.Item' is not declared or the module containing it is not loaded in the debugging session.
? Me.txtMailKey.DataBindings(0)
'Me' is valid only within an instance method.
User is offlineProfile CardPM
+Quote Post

rjhe22

RE: Dll Encryption

22 Sep, 2008 - 04:56 AM
Post #16

New D.I.C Head
*

Joined: 15 Sep, 2008
Posts: 10

when i did them i got this

? rowC.Item("MailKey")
Referenced object has a value of 'Nothing'.
? Me.txtMailKey.DataBindings(0)
{System.Windows.Forms.Binding}
BindableComponent: {System.Windows.Forms.MaskedTextBox}
BindingManagerBase: {System.Windows.Forms.CurrencyManager}
BindingMemberInfo: {System.Windows.Forms.BindingMemberInfo}
Control: {System.Windows.Forms.MaskedTextBox}
ControlUpdateMode: OnPropertyChanged {0}
DataSource: {System.Data.DataTable}
DataSourceNullValue: {System.DBNull}
DataSourceUpdateMode: OnValidation {0}
FormatInfo: Nothing
FormatString: ""
FormattingEnabled: False
IsBinding: False
NullValue: Nothing
PropertyName: "text"


when i did them i got this

CODE
? rowC.Item("MailKey")
Referenced object has a value of 'Nothing'.

the first one has to come out like that as it does not reach the line.

CODE
? Me.txtMailKey.DataBindings(0)
{System.Windows.Forms.Binding}
    BindableComponent: {System.Windows.Forms.MaskedTextBox}
    BindingManagerBase: {System.Windows.Forms.CurrencyManager}
    BindingMemberInfo: {System.Windows.Forms.BindingMemberInfo}
    Control: {System.Windows.Forms.MaskedTextBox}
    ControlUpdateMode: OnPropertyChanged {0}
    DataSource: {System.Data.DataTable}
    DataSourceNullValue: {System.DBNull}
    DataSourceUpdateMode: OnValidation {0}
    FormatInfo: Nothing
    FormatString: ""
    FormattingEnabled: False
    IsBinding: False
    NullValue: Nothing
    PropertyName: "text"

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 02:41AM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month