Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing encryption via classname.vb 1

Status
Not open for further replies.

bobmmp

Programmer
Apr 22, 2002
43
US
I adapted and modified an encryption / decryption tutorial that was written for consult mode. I took the base part of the code and created a dll that I will call just classLibrary1. it is an adaptation of Rijndael using a salt, and a md5 hashed key. The dll is in the bin folder where it needs to be. When I call the my shared function with everything in code behind, i get my desired results.

You can see the demo here: .

The my problem is I want to call the code behind from a lot of different pages so I thought I would place a public class with two functions in the app_code folder called raj.vb.

my class with functions is:
Imports Microsoft.VisualBasic
Imports ClassLibrary1

Public Class raj
Public Shared Function RajEncrypt(ByVal myEncrypt As String, ByVal myKey As String)
Dim plainText As String = myEncrypt
Dim passPhrase As String = myKey

Dim cipherText As String
Dim saltValue As String
Dim hashAlgorithm As String
Dim passwordIterations As Integer
Dim initVector As String
Dim keySize As Integer

'plainText = "Hello, World!" ' original plaintext
'passPhrase = "Pas5pr@se" ' can be any string
saltValue = "s@1tValue" ' can be any string
'hashAlgorithm = "SHA1" ' can be "MD5"
hashAlgorithm = "MD5"

passwordIterations = 2 ' can be any number
initVector = "@1B2c3D4e5F6g7H8" ' must be 16 bytes
keySize = 192 ' can be 192 or 128

Return plainText

cipherText = myCrypt.RijndaelSimple.Encrypt(plainText, _
passPhrase, _
saltValue, _
hashAlgorithm, _
passwordIterations, _
initVector, _
keySize)

Return cipherText

End Function

Public Shared Function RajDecrypt(ByVal myEncrypt As String, ByVal myKey As String)
Dim plainText As String = myEncrypt
Dim cipherText As String

Dim passPhrase As String = myKey
Dim saltValue As String
Dim hashAlgorithm As String
Dim passwordIterations As Integer
Dim initVector As String
Dim keySize As Integer

'plainText = "Hello, World!" ' original plaintext
'passPhrase = "Pas5pr@se" ' can be any string
saltValue = "s@1tValue" ' can be any string
'hashAlgorithm = "SHA1" ' can be "MD5"
hashAlgorithm = "MD5"

passwordIterations = 2 ' can be any number
initVector = "@1B2c3D4e5F6g7H8" ' must be 16 bytes
keySize = 192 ' can be 192 or 128


plainText = myCrypt.RijndaelSimple.Decrypt(cipherText, _
passPhrase, _
saltValue, _
hashAlgorithm, _
passwordIterations, _
initVector, _
keySize)

Return plainText
End Function
End Class I am wanting to call this to encrypt customer names, phonenumber and email addresses and store the results in a mdf and then decrypt it for viewing by entering/typing in the key to read that data in a gridview.

Now I need to access the class functions from my code behind.

I am missing something on this part, and stripped everything out but this:

Partial Class Default2
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strEncrypt As String = TextBox1.Text
Dim strKey As String = TextBox2.Text
Dim myKey As String = strKey
Dim myEncrypt As String = strEncrypt

' calling this is where I am lost

End Sub
End Class Thanks for any and all help!

Bob B.
 
You just call it by classname.functionname()

raj.RajEncrypt(params...)
raj.RajDecrypt(params...)
 
Thanks jbenson.
Actually I was calling it by class name and function name.
It did not work until I added the following

Dim rajObject as New raj... why, you got me.
I was under the impression if it was in your app_code, your object would aready be exposed?

Thanks!

Bob B.
 
Yes you are correct, you should not have to declare a new class if you have it in the app_code folder. Did you recompile after you created the class?

Did you create the app_code folder? If so you have to use the menu item that says "Add ASP.NET Folder"

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top