T
tshad
I have a Dll I created in VS 2000.
The namespace is MyFunctions and the Class is CryptoUtil.
I have a program that is using the Class but it can't access it directly.
I have a class (below) called CryptoUtil.
The functions are Shared functions. I have this Dll in the bin folder of my
program. If I don't reference it - it can't seem to find it. If I have:
Import MyFunctions
I still can't access my function Encode directly (error: Name Encode not
declared)
I can't access it as: CryptoUtil.Encode (Encode is not a member of
CryptoUtil ????)
I can't access it as: MyFunctions.CryptoUtil.Encode (CryptoUtil is not a
member of MyFunctions?? - it isn't?)
This does work: CryptoUtil.MyFunctions.CryptoUtil.Encode. This makes
absolutely not sense to me at all unless it is because I am using a shared
routine.
I have another Dll (newHire) in the same folder that starts out:
****************************************
namespace MyFunctions
{
[Serializable]
public class NewHire
*****************************************
I can access this class as: newHire = New NewHire
What is the difference? Here is the CryptoUtil class:
***************************************************
Imports System
Namespace MyFunctions
Public Class CryptoUtil
Enum EncryptionAlgorithm
Des = 1
Rc2 = 2
Rijndael = 3
TripleDes = 4
End Enum
Public Shared Function Encode(ByVal value As String, ByVal key As
String) As String
Return TripleDESEncode(value, key)
End Function
Public Shared Function Decode(ByVal value As String, ByVal key As
String) As String
Return TripleDESDecode(value, key)
End Function
Public Shared Function TripleDESEncode(ByVal value As String, ByVal
key As String) As String
Dim des As New
Security.Cryptography.TripleDESCryptoServiceProvider
des.IV = New Byte(7) {}
Dim pdb As New Security.Cryptography.PasswordDeriveBytes(key,
New Byte(-1) {})
des.Key = pdb.CryptDeriveKey("TripleDES", "MD5", 168, New
Byte(7) {})
Dim ms As New IO.MemoryStream((value.Length * 2) - 1)
Dim encStream As New Security.Cryptography.CryptoStream(ms,
des.CreateEncryptor(), Security.Cryptography.CryptoStreamMode.Write)
Dim plainBytes As Byte() = Text.Encoding.UTF8.GetBytes(value)
encStream.Write(plainBytes, 0, plainBytes.Length)
encStream.FlushFinalBlock()
Dim encryptedBytes(CInt(ms.Length - 1)) As Byte
ms.Position = 0
ms.Read(encryptedBytes, 0, CInt(ms.Length))
encStream.Close()
Return Convert.ToBase64String(encryptedBytes)
End Function
Public Shared Function TripleDESDecode(ByVal value As String, ByVal
key As String) As String
Dim des As New
Security.Cryptography.TripleDESCryptoServiceProvider
des.IV = New Byte(7) {}
Dim pdb As New Security.Cryptography.PasswordDeriveBytes(key,
New Byte(-1) {})
des.Key = pdb.CryptDeriveKey("TripleDES", "MD5", 168, New
Byte(7) {})
Dim encryptedBytes As Byte() = Convert.FromBase64String(value)
Dim ms As New IO.MemoryStream(value.Length)
Dim decStream As New Security.Cryptography.CryptoStream(ms,
des.CreateDecryptor(), Security.Cryptography.CryptoStreamMode.Write)
decStream.Write(encryptedBytes, 0, encryptedBytes.Length)
decStream.FlushFinalBlock()
Dim plainBytes(CInt(ms.Length - 1)) As Byte
ms.Position = 0
ms.Read(plainBytes, 0, CInt(ms.Length))
decStream.Close()
Return Text.Encoding.UTF8.GetString(plainBytes)
End Function
End Class
End Namespace
****************************************************
Thanks,
Tom
The namespace is MyFunctions and the Class is CryptoUtil.
I have a program that is using the Class but it can't access it directly.
I have a class (below) called CryptoUtil.
The functions are Shared functions. I have this Dll in the bin folder of my
program. If I don't reference it - it can't seem to find it. If I have:
Import MyFunctions
I still can't access my function Encode directly (error: Name Encode not
declared)
I can't access it as: CryptoUtil.Encode (Encode is not a member of
CryptoUtil ????)
I can't access it as: MyFunctions.CryptoUtil.Encode (CryptoUtil is not a
member of MyFunctions?? - it isn't?)
This does work: CryptoUtil.MyFunctions.CryptoUtil.Encode. This makes
absolutely not sense to me at all unless it is because I am using a shared
routine.
I have another Dll (newHire) in the same folder that starts out:
****************************************
namespace MyFunctions
{
[Serializable]
public class NewHire
*****************************************
I can access this class as: newHire = New NewHire
What is the difference? Here is the CryptoUtil class:
***************************************************
Imports System
Namespace MyFunctions
Public Class CryptoUtil
Enum EncryptionAlgorithm
Des = 1
Rc2 = 2
Rijndael = 3
TripleDes = 4
End Enum
Public Shared Function Encode(ByVal value As String, ByVal key As
String) As String
Return TripleDESEncode(value, key)
End Function
Public Shared Function Decode(ByVal value As String, ByVal key As
String) As String
Return TripleDESDecode(value, key)
End Function
Public Shared Function TripleDESEncode(ByVal value As String, ByVal
key As String) As String
Dim des As New
Security.Cryptography.TripleDESCryptoServiceProvider
des.IV = New Byte(7) {}
Dim pdb As New Security.Cryptography.PasswordDeriveBytes(key,
New Byte(-1) {})
des.Key = pdb.CryptDeriveKey("TripleDES", "MD5", 168, New
Byte(7) {})
Dim ms As New IO.MemoryStream((value.Length * 2) - 1)
Dim encStream As New Security.Cryptography.CryptoStream(ms,
des.CreateEncryptor(), Security.Cryptography.CryptoStreamMode.Write)
Dim plainBytes As Byte() = Text.Encoding.UTF8.GetBytes(value)
encStream.Write(plainBytes, 0, plainBytes.Length)
encStream.FlushFinalBlock()
Dim encryptedBytes(CInt(ms.Length - 1)) As Byte
ms.Position = 0
ms.Read(encryptedBytes, 0, CInt(ms.Length))
encStream.Close()
Return Convert.ToBase64String(encryptedBytes)
End Function
Public Shared Function TripleDESDecode(ByVal value As String, ByVal
key As String) As String
Dim des As New
Security.Cryptography.TripleDESCryptoServiceProvider
des.IV = New Byte(7) {}
Dim pdb As New Security.Cryptography.PasswordDeriveBytes(key,
New Byte(-1) {})
des.Key = pdb.CryptDeriveKey("TripleDES", "MD5", 168, New
Byte(7) {})
Dim encryptedBytes As Byte() = Convert.FromBase64String(value)
Dim ms As New IO.MemoryStream(value.Length)
Dim decStream As New Security.Cryptography.CryptoStream(ms,
des.CreateDecryptor(), Security.Cryptography.CryptoStreamMode.Write)
decStream.Write(encryptedBytes, 0, encryptedBytes.Length)
decStream.FlushFinalBlock()
Dim plainBytes(CInt(ms.Length - 1)) As Byte
ms.Position = 0
ms.Read(plainBytes, 0, CInt(ms.Length))
decStream.Close()
Return Text.Encoding.UTF8.GetString(plainBytes)
End Function
End Class
End Namespace
****************************************************
Thanks,
Tom