I have recently migrated to a "web project" instead of a "web site" following the words of one of my coworkers. Now the most simple things are failing for me as in importing a namespace. I cannot inherit it nor can I import it at all. Nothing inside the
class is recognized. Please see the example below:
This all worked inside the website but now fails...
Here is the encryption namespace I am trying to import:
Option Explicit
On
Option
Strict
Off
Imports
Microsoft.VisualBasic
Imports
System.Security.Cryptography
Imports
System
Imports
System.IO
Namespace Encrypt
Public Class ClsEncrDecr
Public Function Encode(ByVal dec
As String)
As String
Dim bt() As
Byte
ReDim bt(dec.Length)
bt = System.Text.Encoding.ASCII.GetBytes(dec)
Dim enc As
String
enc = System.Convert.ToBase64String(bt)
Return enc
End Function
Public Function EncodeByte(ByVal bt()
As Byte)
As String
Dim enc As
String
enc = System.Convert.ToBase64String(bt)
Return enc
End Function
Public Function Decode(ByVal enc
As String)
As String
Dim bt() As
Byte
bt = System.Convert.FromBase64String(enc)
Dim dec As
String
dec = System.Text.Encoding.ASCII.GetString(bt)
Return dec
End Function
Public
Function DecodeToByte(ByVal enc
As String)
As Byte()
Dim bt() As
Byte
bt = System.Convert.FromBase64String(enc)
Return bt
End Function
Public
Enum EncryptionType
DES
RC2
Rijndael
TripleDES
End Enum
Public Property InitialIV()
As String
Get
Return initialIV1
End Get
Set(ByVal Value
As String)
initialIV1 = Value
End Set
End Property
Private initialIV1
As String = ConfigurationSettings.AppSettings("EncryptionVector")
Private SymmetricAlgorithm
As SymmetricAlgorithm
Public Function SymmetricEncryption(ByVal Type
As EncryptionType)
As EncryptionType
Select Case (Type)
Case EncryptionType.DES
SymmetricAlgorithm =
New DESCryptoServiceProvider()
Case EncryptionType.RC2
SymmetricAlgorithm =
New RC2CryptoServiceProvider()
Case EncryptionType.Rijndael
SymmetricAlgorithm =
New RijndaelManaged()
Case EncryptionType.TripleDES
SymmetricAlgorithm =
New TripleDESCryptoServiceProvider()
End Select
End Function
Public
Function SymmetricEncryption(ByVal ServiceProvider
As SymmetricAlgorithm)
As SymmetricAlgorithm
SymmetricAlgorithm = ServiceProvider
Return SymmetricAlgorithm
End Function
Public Function Encrypt(ByVal Contents
As String,
ByVal Key As
String) As
String
Dim bytIn
As Byte() = UTF8Encoding.UTF8.GetBytes(Contents)Dim ms
As New System.IO.MemoryStream()
SymmetricAlgorithm.Key = GetLegalKey(Key)
SymmetricAlgorithm.IV = GetLegalIV()
Dim encrypto As ICryptoTransform = SymmetricAlgorithm.CreateEncryptor()Dim
cs As New CryptoStream(ms, encrypto, CryptoStreamMode.Write)
cs.Write(bytIn, 0, bytIn.Length)
cs.FlushFinalBlock()
ms.Close()
Dim bytOut As
Byte() = ms.ToArray()
Return System.Convert.ToBase64String(bytOut)
End Function
Public Function Decrypt(ByVal Contents
As String,
ByVal Key As
String) As
String
Dim bytIn
As Byte() = System.Convert.FromBase64String(Contents)Dim
ms As New System.IO.MemoryStream(bytIn, 0, bytIn.Length)
SymmetricAlgorithm.Key = GetLegalKey(Key)
SymmetricAlgorithm.IV = GetLegalIV()
Dim encrypto As ICryptoTransform = SymmetricAlgorithm.CreateDecryptor()
Dim cs As
New CryptoStream(ms, encrypto, CryptoStreamMode.Read)
Dim sr As
New System.IO.StreamReader(cs)
Return sr.ReadToEnd()
End Function
Private
Function GetLegalKey(ByVal Key
As String)
As Byte()Dim sTemp
As String = Key
SymmetricAlgorithm.GenerateKey()
Dim bytTemp
As Byte() = SymmetricAlgorithm.Key
Dim KeyLength
As Integer = bytTemp.Length
If (sTemp.Length > KeyLength)
Then
sTemp = sTemp.Substring(0, KeyLength)
ElseIf (sTemp.Length < KeyLength)
Then
sTemp = sTemp.PadRight(KeyLength, " ")
End If
Return ASCIIEncoding.ASCII.GetBytes(sTemp)
End Function
Private
Function GetLegalIV()
As Byte()Dim sTemp
As String = InitialIV
SymmetricAlgorithm.GenerateIV()
Dim bytTemp
As Byte() = SymmetricAlgorithm.IV
Dim IVLength As
Integer = bytTemp.Length
If (sTemp.Length > IVLength)
Then
sTemp = sTemp.Substring(0, IVLength)
ElseIf (sTemp.Length < IVLength)
Then
sTemp = sTemp.PadRight(IVLength, " ")
End If
Return ASCIIEncoding.ASCII.GetBytes(sTemp)
End Function
End
Class
End
Namespace
Here is the page I am trying to import this use of these functions:
Option
Explicit
On
Option
Strict
On
Imports
System.Security
Imports
System.Data
Imports
System.Web.UI.WebControls
Imports
Microsoft.VisualBasic
Imports
Encrypt < I get the error message Imports encrypt does not contain any public members or cannot be found
Partial
Class Admin_Encrypt
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender
As System.Object,
ByVal e As System.EventArgs)
Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private
Sub Encrypt_Click(ByVal sender
As System.Object,
ByVal e As System.EventArgs)
Handles Encrypt.Click
Dim cls As
New ClsEncrDecr()
Dim enctype
As String =
"Me.ddlEncrypt.SelectedValue.ToString"
'To select the kind of encryption you want to have
"EncryptionKey"))
End Sub
Private
Sub Decrypt_Click(ByVal sender
As System.Object,
ByVal e As System.EventArgs)
Handles Decrypt.Click
Dim cls As
New ClsEncrDecr()
'To select the kind of encryption you want to have
cyiamxtc
Member
27 Points
14 Posts
cannot import namespaces in web project...
Aug 28, 2007 03:05 PM|LINK
I have recently migrated to a "web project" instead of a "web site" following the words of one of my coworkers. Now the most simple things are failing for me as in importing a namespace. I cannot inherit it nor can I import it at all. Nothing inside the class is recognized. Please see the example below:
This all worked inside the website but now fails...
Here is the encryption namespace I am trying to import:
Option Explicit OnOption
Strict OffImports
Microsoft.VisualBasicImports
System.Security.CryptographyImports
SystemImports
System.IO Namespace Encrypt Public Class ClsEncrDecr Public Function Encode(ByVal dec As String) As String Dim bt() As Byte ReDim bt(dec.Length)bt = System.Text.Encoding.ASCII.GetBytes(dec)
Dim enc As Stringenc = System.Convert.ToBase64String(bt)
Return enc End Function Public Function EncodeByte(ByVal bt() As Byte) As String Dim enc As Stringenc = System.Convert.ToBase64String(bt)
Return enc End Function Public Function Decode(ByVal enc As String) As String Dim bt() As Bytebt = System.Convert.FromBase64String(enc)
Dim dec As Stringdec = System.Text.Encoding.ASCII.GetString(bt)
Return dec End Function Public Function DecodeToByte(ByVal enc As String) As Byte() Dim bt() As Bytebt = System.Convert.FromBase64String(enc)
Return bt End Function Public Enum EncryptionTypeDES
RC2
Rijndael
TripleDES
End Enum Public Property InitialIV() As String Get Return initialIV1 End Get Set(ByVal Value As String)initialIV1 = Value
End Set End Property Private initialIV1 As String = ConfigurationSettings.AppSettings("EncryptionVector") Private SymmetricAlgorithm As SymmetricAlgorithm Public Function SymmetricEncryption(ByVal Type As EncryptionType) As EncryptionType Select Case (Type) Case EncryptionType.DESSymmetricAlgorithm =
New DESCryptoServiceProvider() Case EncryptionType.RC2SymmetricAlgorithm =
New RC2CryptoServiceProvider() Case EncryptionType.RijndaelSymmetricAlgorithm =
New RijndaelManaged() Case EncryptionType.TripleDESSymmetricAlgorithm =
New TripleDESCryptoServiceProvider() End Select End Function Public Function SymmetricEncryption(ByVal ServiceProvider As SymmetricAlgorithm) As SymmetricAlgorithmSymmetricAlgorithm = ServiceProvider
Return SymmetricAlgorithm End Function
Public Function Encrypt(ByVal Contents As String, ByVal Key As String) As String Dim bytIn As Byte() = UTF8Encoding.UTF8.GetBytes(Contents)Dim ms As New System.IO.MemoryStream()SymmetricAlgorithm.Key = GetLegalKey(Key)
SymmetricAlgorithm.IV = GetLegalIV()
Dim encrypto As ICryptoTransform = SymmetricAlgorithm.CreateEncryptor()Dim cs As New CryptoStream(ms, encrypto, CryptoStreamMode.Write)cs.Write(bytIn, 0, bytIn.Length)
cs.FlushFinalBlock()
ms.Close()
Dim bytOut As Byte() = ms.ToArray() Return System.Convert.ToBase64String(bytOut) End Function
Public Function Decrypt(ByVal Contents As String, ByVal Key As String) As String Dim bytIn As Byte() = System.Convert.FromBase64String(Contents)Dim ms As New System.IO.MemoryStream(bytIn, 0, bytIn.Length)SymmetricAlgorithm.Key = GetLegalKey(Key)
SymmetricAlgorithm.IV = GetLegalIV()
Dim encrypto As ICryptoTransform = SymmetricAlgorithm.CreateDecryptor() Dim cs As New CryptoStream(ms, encrypto, CryptoStreamMode.Read) Dim sr As New System.IO.StreamReader(cs) Return sr.ReadToEnd() End Function Private Function GetLegalKey(ByVal Key As String) As Byte()Dim sTemp As String = KeySymmetricAlgorithm.GenerateKey()
Dim bytTemp As Byte() = SymmetricAlgorithm.Key Dim KeyLength As Integer = bytTemp.Length If (sTemp.Length > KeyLength) ThensTemp = sTemp.Substring(0, KeyLength)
ElseIf (sTemp.Length < KeyLength) Then sTemp = sTemp.PadRight(KeyLength, " ") End If Return ASCIIEncoding.ASCII.GetBytes(sTemp) End Function Private Function GetLegalIV() As Byte()Dim sTemp As String = InitialIVSymmetricAlgorithm.GenerateIV()
Dim bytTemp As Byte() = SymmetricAlgorithm.IV Dim IVLength As Integer = bytTemp.Length If (sTemp.Length > IVLength) ThensTemp = sTemp.Substring(0, IVLength)
ElseIf (sTemp.Length < IVLength) Then sTemp = sTemp.PadRight(IVLength, " ") End If Return ASCIIEncoding.ASCII.GetBytes(sTemp) End Function End ClassEnd
NamespaceHere is the page I am trying to import this use of these functions:
Option Explicit OnOption
Strict OnImports
System.SecurityImports
System.DataImports
System.Web.UI.WebControlsImports
Microsoft.VisualBasicImports
Encrypt < I get the error message Imports encrypt does not contain any public members or cannot be found Partial Class Admin_Encrypt Inherits System.Web.UI.Page Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here End Sub Private Sub Encrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Encrypt.Click Dim cls As New ClsEncrDecr() Dim enctype As String = "Me.ddlEncrypt.SelectedValue.ToString" 'To select the kind of encryption you want to havecls.SymmetricEncryption(ClsEncrDecr.EncryptionType.Rijndael)
cls.InitialIV = System.Configuration.ConfigurationManager.AppSettings("EncryptionVector")txtEncrypt.Text = cls.Encrypt(txtNormal.Text, System.Configuration.ConfigurationManager.AppSettings(
"EncryptionKey")) End Sub Private Sub Decrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Decrypt.Click Dim cls As New ClsEncrDecr() 'To select the kind of encryption you want to havecls.SymmetricEncryption(ClsEncrDecr.EncryptionType.Rijndael)
cls.InitialIV = System.Configuration.ConfigurationManager.AppSettings("EncryptionVector")txtDecrypt.Text = cls.Decrypt(txtEncrypt.Text, System.Configuration.ConfigurationManager.AppSettings(
"EncryptionKey")) End SubEnd
ClassCentillion Industries Incorporated
Pittsburgh, PA