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 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.