VB.net Converting C# to VB.net

Hi

I am trying to convert the following C# code (in cEncryption.cs)
to VB.net code. I used a conversion tool to get the VB.net code below
I tried creating a class called cEncryption.vb and just pasting the code in.
As expected this doesn't work. I find the Namespace part confusing
Just need a little help with this, on how to build the VB.net equivalent

using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Configuration;
using System;
using System.Drawing;

// <summary>
// A simple, string-oriented wrapper class for encryption functions, including
// Hashing, Symmetric Encryption, and Asymmetric Encryption.
// </summary>
// <remarks>
// Jeff Atwood
// http://www.codinghorror.com/ 
// </remarks>
namespace Encryption
{
   
    #region " Symmetric"
   
    /// <summary>
    /// Symmetric encryption uses a single key to encrypt and decrypt.
    /// Both parties (encryptor and decryptor) must share the same secret key.
    /// </summary>
    public class Symmetric
    {
       
        private const string _DefaultIntializationVector = "%1Az=-@qT";
        private const int _BufferSize = 2048;
       
        public enum Provider
        {
            /// <summary>
            /// The Data Encryption Standard provider supports a 64 bit key only
            /// </summary>
            DES,
            /// <summary>
            /// The Rivest Cipher 2 provider supports keys ranging from 40 to 128 bits, default is 128 bits
            /// </summary>
            RC2,
            /// <summary>
            /// The Rijndael (also known as AES) provider supports keys of 128, 192, or 256 bits with a default of 256 bits
            /// </summary>
            Rijndael,
            /// <summary>
            /// The TripleDES provider (also known as 3DES) supports keys of 128 or 192 bits with a default of 192 bits
            /// </summary>
            TripleDES
        }
       
        // Private _data As Data
        private Data _key;
        private Data _iv;
        private SymmetricAlgorithm _crypto;
        // Private _EncryptedBytes As Byte()
        // Private _UseDefaultInitializationVector As Boolean
       
        private Symmetric()
        {
        }
       
        /// <summary>
        /// Instantiates a new symmetric encryption object using the specified provider.
        /// </summary>
        //public Symmetric(Provider provider)
        //{
        //    this.Symmetric(provider,true);
        //}

        public Symmetric(Provider provider, bool useDefaultInitializationVector)
        {
            switch (provider) {
                case Provider.DES:
                    _crypto = new DESCryptoServiceProvider();
                    break;
                case Provider.RC2:
                    _crypto = new RC2CryptoServiceProvider();
                    break;
                case Provider.Rijndael:
                    _crypto = new RijndaelManaged();
                    break;
                case Provider.TripleDES:
                    _crypto = new TripleDESCryptoServiceProvider();
                    break;
            }
           
            //-- make sure key and IV are always set, no matter what
            this.Key = RandomKey();
            if (useDefaultInitializationVector) {
                this.IntializationVector = new Data(_DefaultIntializationVector);
            }
            else {
                this.IntializationVector = RandomInitializationVector();
            }
        }
       
        /// <summary>
        /// The key used to encrypt/decrypt data
        /// </summary>
        public Data Key {
            get { return _key; }
            set {
                _key = value;
                _key.MaxBytes = _crypto.LegalKeySizes[0].MaxSize / 8;
                _key.MinBytes = _crypto.LegalKeySizes[0].MinSize / 8;
                _key.StepBytes = _crypto.LegalKeySizes[0].SkipSize / 8;
            }
        }
       
        /// <summary>
        /// Using the default Cipher Block Chaining (CBC) mode, all data blocks are processed using
        /// the value derived from the previous block; the first data block has no previous data block
        /// to use, so it needs an InitializationVector to feed the first block
        /// </summary>
        public Data IntializationVector {
            get { return _iv; }
            set {
                _iv = value;
                _iv.MaxBytes = _crypto.BlockSize / 8;
                _iv.MinBytes = _crypto.BlockSize / 8;
            }
        }
       
        /// <summary>
        /// generates a random Initialization Vector, if one was not provided
        /// </summary>
        public Data RandomInitializationVector()
        {
            _crypto.GenerateIV();
            Data d = new Data(_crypto.IV);
            return d;
        }
       
        /// <summary>
        /// generates a random Key, if one was not provided
        /// </summary>
        public Data RandomKey()
        {
            _crypto.GenerateKey();
            Data d = new Data(_crypto.Key);
            return d;
        }
       
        /// <summary>
        /// Ensures that _crypto object has valid Key and IV
        /// prior to any attempt to encrypt/decrypt anything
        /// </summary>
        private void ValidateKeyAndIv(bool isEncrypting)
        {
            if (_key.IsEmpty) {
                if (isEncrypting) {
                    _key = RandomKey();
                }
                else {
                    throw new CryptographicException("No key was provided for the decryption operation!");
                }
            }
            if (_iv.IsEmpty) {
                if (isEncrypting) {
                    _iv = RandomInitializationVector();
                }
                else {
                    throw new CryptographicException("No initialization vector was provided for the decryption operation!");
                }
            }
            _crypto.Key = _key.Bytes;
            _crypto.IV = _iv.Bytes;
        }
       
        /// <summary>
        /// Encrypts the specified Data using provided key
        /// </summary>
        public Data Encrypt(Data d, Data key)
        {
            this.Key = key;
            return Encrypt(d);
        }
       
        /// <summary>
        /// Encrypts the specified Data using preset key and preset initialization vector
        /// </summary>
        public Data Encrypt(Data d)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
           
            ValidateKeyAndIv(true);
           
            CryptoStream cs = new CryptoStream(ms, _crypto.CreateEncryptor(), CryptoStreamMode.Write);
            cs.Write(d.Bytes, 0, d.Bytes.Length);
            cs.Close();
            ms.Close();
           
            return new Data(ms.ToArray());
        }
       
        /// <summary>
        /// Encrypts the stream to memory using provided key and provided initialization vector
        /// </summary>
        public Data Encrypt(Stream s, Data key, Data iv)
        {
            this.IntializationVector = iv;
            this.Key = key;
            return Encrypt(s);
        }
       
        /// <summary>
        /// Encrypts the stream to memory using specified key
        /// </summary>
        public Data Encrypt(Stream s, Data key)
        {
            this.Key = key;
            return Encrypt(s);
        }
       
        /// <summary>
        /// Encrypts the specified stream to memory using preset key and preset initialization vector
        /// </summary>
        public Data Encrypt(Stream s)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            byte[] b = new byte[_BufferSize + 1];
            int i = 0;
           
            ValidateKeyAndIv(true);
           
            CryptoStream cs = new CryptoStream(ms, _crypto.CreateEncryptor(), CryptoStreamMode.Write);
            i = s.Read(b, 0, _BufferSize);
            while (i > 0) {
                cs.Write(b, 0, i);
                i = s.Read(b, 0, _BufferSize);
            }
           
            cs.Close();
            ms.Close();
           
            return new Data(ms.ToArray());
        }
       
        /// <summary>
        /// Decrypts the specified data using provided key and preset initialization vector
        /// </summary>
        public Data Decrypt(Data encryptedData, Data key)
        {
            this.Key = key;
            return Decrypt(encryptedData);
        }
       
        /// <summary>
        /// Decrypts the specified stream using provided key and preset initialization vector
        /// </summary>
        public Data Decrypt(Stream encryptedStream, Data key)
        {
            this.Key = key;
            return Decrypt(encryptedStream);
        }
       
        /// <summary>
        /// Decrypts the specified stream using preset key and preset initialization vector
        /// </summary>
        public Data Decrypt(Stream encryptedStream)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            byte[] b = new byte[_BufferSize + 1];
           
            ValidateKeyAndIv(false);
            CryptoStream cs = new CryptoStream(encryptedStream, _crypto.CreateDecryptor(), CryptoStreamMode.Read);
           
            int i = 0;
            i = cs.Read(b, 0, _BufferSize);
           
            while (i > 0) {
                ms.Write(b, 0, i);
                i = cs.Read(b, 0, _BufferSize);
            }
            cs.Close();
            ms.Close();
           
            return new Data(ms.ToArray());
        }
       
        /// <summary>
        /// Decrypts the specified data using preset key and preset initialization vector
        /// </summary>
        public Data Decrypt(Data encryptedData)
        {
            try {
                System.IO.MemoryStream ms = new System.IO.MemoryStream(encryptedData.Bytes, 0, encryptedData.Bytes.Length);
                byte[] b = new byte[encryptedData.Bytes.Length];
               
                ValidateKeyAndIv(false);
                CryptoStream cs = new CryptoStream(ms, _crypto.CreateDecryptor(), CryptoStreamMode.Read);
               
                try {
                    cs.Read(b, 0, encryptedData.Bytes.Length - 1);
                }
                catch (CryptographicException ex) {
                    throw new CryptographicException("Unable to decrypt data. The provided key may be invalid.", ex);
                }
                finally {
                    cs.Close();
                }
                return new Data(b);
            }
            catch {
                return null;
            }
        }
    }
   
   
    #endregion
   
    #region " Data"
   
    /// <summary>
    /// represents Hex, Byte, Base64, or String data to encrypt/decrypt;
    /// use the .Text property to set/get a string representation
    /// use the .Hex property to set/get a string-based Hexadecimal representation
    /// use the .Base64 to set/get a string-based Base64 representation
    /// </summary>
    public class Data
    {
        private byte[] _b;
        private int _MaxBytes = 0;
        private int _MinBytes = 0;
        private int _StepBytes = 0;
       
        /// <summary>
        /// Determines the default text encoding across ALL Data instances
        /// </summary>
        public static System.Text.Encoding DefaultEncoding = System.Text.Encoding.GetEncoding("Windows-1252");
       
        /// <summary>
        /// Determines the default text encoding for this Data instance
        /// </summary>
        public System.Text.Encoding Encoding = DefaultEncoding;
       
        /// <summary>
        /// Creates new, empty encryption data
        /// </summary>
        public Data()
        {
        }
       
        /// <summary>
        /// Creates new encryption data with the specified byte array
        /// </summary>
        public Data(byte[] b)
        {
            _b = b;
        }
       
        /// <summary>
        /// Creates new encryption data with the specified string;
        /// will be converted to byte array using default encoding
        /// </summary>
        public Data(string s)
        {
            this.Text = s;
        }
       
        /// <summary>
        /// Creates new encryption data using the specified string and the
        /// specified encoding to convert the string to a byte array.
        /// </summary>
        public Data(string s, System.Text.Encoding encoding)
        {
            this.Encoding = encoding;
            this.Text = s;
        }
       
        /// <summary>
        /// returns true if no data is present
        /// </summary>
        public bool IsEmpty {
            get {
                if (_b == null) {
                    return true;
                }
                if (_b.Length == 0) {
                    return true;
                }
                return false;
            }
        }
       
        /// <summary>
        /// allowed step interval, in bytes, for this data; if 0, no limit
        /// </summary>
        public int StepBytes {
            get { return _StepBytes; }
            set { _StepBytes = value; }
        }
       
        /// <summary>
        /// minimum number of bytes allowed for this data; if 0, no limit
        /// </summary>
        public int MinBytes {
            get { return _MinBytes; }
            set { _MinBytes = value; }
        }
       
        /// <summary>
        /// maximum number of bytes allowed for this data; if 0, no limit
        /// </summary>
        public int MaxBytes {
            get { return _MaxBytes; }
            set { _MaxBytes = value; }
        }
       
        /// <summary>
        /// Returns the byte representation of the data;
        /// This will be padded to MinBytes and trimmed to MaxBytes as necessary!
        /// </summary>
        public byte[] Bytes {
            get {
                if (_MaxBytes > 0) {
                    if (_b.Length > _MaxBytes) {
                        byte[] b = new byte[_MaxBytes];
                        Array.Copy(_b, b, b.Length);
                        _b = b;
                    }
                }
                if (_MinBytes > 0) {
                    if (_b.Length < _MinBytes) {
                        byte[] b = new byte[_MinBytes];
                        Array.Copy(_b, b, _b.Length);
                        _b = b;
                    }
                }
                return _b;
            }
            set { _b = value; }
        }
       
        /// <summary>
        /// Sets or returns text representation of bytes using the default text encoding
        /// </summary>
        public string Text {
            get {
                if (_b == null) {
                    return "";
                }
                else {
                    //-- need to handle nulls here; oddly, C# will happily convert
                    //-- nulls into the string whereas VB stops converting at the
                    //-- first null!
                    int i = Array.IndexOf(_b, (byte)0);
                    if (i >= 0) {
                        return this.Encoding.GetString(_b, 0, i);
                    }
                    else {
                        return this.Encoding.GetString(_b);
                    }
                }
            }
            set { _b = this.Encoding.GetBytes(value); }
        }
       
        /// <summary>
        /// Sets or returns Hex string representation of this data
        /// </summary>
        public string Hex {
            get { return Utils.ToHex(_b); }
            set { _b = Utils.FromHex(value); }
        }
       
        /// <summary>
        /// returns Hex string representation of this data
        /// </summary>
        public string ToHex()
        {
            return this.Hex;
        }
    }
   
   
    #endregion
   
    #region " Utils"
   
    /// <summary>
    /// Friend class for shared utility methods used by multiple Encryption classes
    /// </summary>
    internal class Utils
    {
       
        /// <summary>
        /// converts an array of bytes to a string Hex representation
        /// </summary>
        static internal string ToHex(byte[] ba)
        {
            if (ba == null || ba.Length == 0) {
                return "";
            }
            const string HexFormat = "{0:X2}";
            StringBuilder sb = new StringBuilder();
            foreach (byte b in ba) {
                sb.Append(string.Format(HexFormat, b));
            }
            return sb.ToString();
        }
       
        /// <summary>
        /// converts from a string Hex representation to an array of bytes
        /// </summary>
        static internal byte[] FromHex(string hexEncoded)
        {
            if (hexEncoded == null || hexEncoded.Length == 0) {
                return null;
            }
            try {
                int l = Convert.ToInt32(hexEncoded.Length / 2);
                byte[] b = new byte[l];
                for (int i = 0; i <= l - 1; i++) {
                    b = Convert.ToByte(hexEncoded.Substring(i * 2, 2), 16);
                }
                return b;
            }
            catch (Exception ex) {
                throw new System.FormatException("The provided string does not appear to be Hex encoded:" + Environment.NewLine + hexEncoded + Environment.NewLine, ex);
            }
        }
    }
   
}

#endregion


Imports System.IO
Imports System.Security.Cryptography
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Configuration
Imports System.Drawing

' <summary>
' A simple, string-oriented wrapper class for encryption functions, including
' Hashing, Symmetric Encryption, and Asymmetric Encryption.
' </summary>
' <remarks>
' Jeff Atwood
' http://www.codinghorror.com/ 
' </remarks>
Namespace Encryption

      #Region " Symmetric"

      ''' <summary>
      ''' Symmetric encryption uses a single key to encrypt and decrypt.
      ''' Both parties (encryptor and decryptor) must share the same secret key.
      ''' </summary>
      Public Class Symmetric

            Private Const _DefaultIntializationVector As String = "%1Az=-@qT"
            Private Const _BufferSize As Integer = 2048

            Public Enum Provider
                  ''' <summary>
                  ''' The Data Encryption Standard provider supports a 64 bit key only
                  ''' </summary>
                  DES
                  ''' <summary>
                  ''' The Rivest Cipher 2 provider supports keys ranging from 40 to 128 bits, default is 128 bits
                  ''' </summary>
                  RC2
                  ''' <summary>
                  ''' The Rijndael (also known as AES) provider supports keys of 128, 192, or 256 bits with a default of 256 bits
                  ''' </summary>
                  Rijndael
                  ''' <summary>
                  ''' The TripleDES provider (also known as 3DES) supports keys of 128 or 192 bits with a default of 192 bits
                  ''' </summary>
                  TripleDES
            End Enum

            ' Private _data As Data
            Private _key As Data
            Private _iv As Data
            Private _crypto As SymmetricAlgorithm
            ' Private _EncryptedBytes As Byte()
            ' Private _UseDefaultInitializationVector As Boolean

            Private Sub New()
            End Sub

            ''' <summary>
            ''' Instantiates a new symmetric encryption object using the specified provider.
            ''' </summary>
            'public Symmetric(Provider provider)
            '{
            '    this.Symmetric(provider,true);
            '}

            Public Sub New(provider__1 As Provider, useDefaultInitializationVector As Boolean)
                  Select Case provider__1
                        Case Provider.DES
                              _crypto = New DESCryptoServiceProvider()
                              Exit Select
                        Case Provider.RC2
                              _crypto = New RC2CryptoServiceProvider()
                              Exit Select
                        Case Provider.Rijndael
                              _crypto = New RijndaelManaged()
                              Exit Select
                        Case Provider.TripleDES
                              _crypto = New TripleDESCryptoServiceProvider()
                              Exit Select
                  End Select

                  '-- make sure key and IV are always set, no matter what
                  Me.Key = RandomKey()
                  If useDefaultInitializationVector Then
                        Me.IntializationVector = New Data(_DefaultIntializationVector)
                  Else
                        Me.IntializationVector = RandomInitializationVector()
                  End If
            End Sub

            ''' <summary>
            ''' The key used to encrypt/decrypt data
            ''' </summary>
            Public Property Key() As Data
                  Get
                        Return _key
                  End Get
                  Set
                        _key = value
                        _key.MaxBytes = _crypto.LegalKeySizes(0).MaxSize \ 8
                        _key.MinBytes = _crypto.LegalKeySizes(0).MinSize \ 8
                        _key.StepBytes = _crypto.LegalKeySizes(0).SkipSize \ 8
                  End Set
            End Property

            ''' <summary>
            ''' Using the default Cipher Block Chaining (CBC) mode, all data blocks are processed using
            ''' the value derived from the previous block; the first data block has no previous data block
            ''' to use, so it needs an InitializationVector to feed the first block
            ''' </summary>
            Public Property IntializationVector() As Data
                  Get
                        Return _iv
                  End Get
                  Set
                        _iv = value
                        _iv.MaxBytes = _crypto.BlockSize \ 8
                        _iv.MinBytes = _crypto.BlockSize \ 8
                  End Set
            End Property

            ''' <summary>
            ''' generates a random Initialization Vector, if one was not provided
            ''' </summary>
            Public Function RandomInitializationVector() As Data
                  _crypto.GenerateIV()
                  Dim d As New Data(_crypto.IV)
                  Return d
            End Function

            ''' <summary>
            ''' generates a random Key, if one was not provided
            ''' </summary>
            Public Function RandomKey() As Data
                  _crypto.GenerateKey()
                  Dim d As New Data(_crypto.Key)
                  Return d
            End Function

            ''' <summary>
            ''' Ensures that _crypto object has valid Key and IV
            ''' prior to any attempt to encrypt/decrypt anything
            ''' </summary>
            Private Sub ValidateKeyAndIv(isEncrypting As Boolean)
                  If _key.IsEmpty Then
                        If isEncrypting Then
                              _key = RandomKey()
                        Else
                              Throw New CryptographicException("No key was provided for the decryption operation!")
                        End If
                  End If
                  If _iv.IsEmpty Then
                        If isEncrypting Then
                              _iv = RandomInitializationVector()
                        Else
                              Throw New CryptographicException("No initialization vector was provided for the decryption operation!")
                        End If
                  End If
                  _crypto.Key = _key.Bytes
                  _crypto.IV = _iv.Bytes
            End Sub

            ''' <summary>
            ''' Encrypts the specified Data using provided key
            ''' </summary>
            Public Function Encrypt(d As Data, key As Data) As Data
                  Me.Key = key
                  Return Encrypt(d)
            End Function

            ''' <summary>
            ''' Encrypts the specified Data using preset key and preset initialization vector
            ''' </summary>
            Public Function Encrypt(d As Data) As Data
                  Dim ms As New System.IO.MemoryStream()

                  ValidateKeyAndIv(True)

                  Dim cs As New CryptoStream(ms, _crypto.CreateEncryptor(), CryptoStreamMode.Write)
                  cs.Write(d.Bytes, 0, d.Bytes.Length)
                  cs.Close()
                  ms.Close()

                  Return New Data(ms.ToArray())
            End Function

            ''' <summary>
            ''' Encrypts the stream to memory using provided key and provided initialization vector
            ''' </summary>
            Public Function Encrypt(s As Stream, key As Data, iv As Data) As Data
                  Me.IntializationVector = iv
                  Me.Key = key
                  Return Encrypt(s)
            End Function

            ''' <summary>
            ''' Encrypts the stream to memory using specified key
            ''' </summary>
            Public Function Encrypt(s As Stream, key As Data) As Data
                  Me.Key = key
                  Return Encrypt(s)
            End Function

            ''' <summary>
            ''' Encrypts the specified stream to memory using preset key and preset initialization vector
            ''' </summary>
            Public Function Encrypt(s As Stream) As Data
                  Dim ms As New System.IO.MemoryStream()
                  Dim b As Byte() = New Byte(_BufferSize) {}
                  Dim i As Integer = 0

                  ValidateKeyAndIv(True)

                  Dim cs As New CryptoStream(ms, _crypto.CreateEncryptor(), CryptoStreamMode.Write)
                  i = s.Read(b, 0, _BufferSize)
                  While i > 0
                        cs.Write(b, 0, i)
                        i = s.Read(b, 0, _BufferSize)
                  End While

                  cs.Close()
                  ms.Close()

                  Return New Data(ms.ToArray())
            End Function

            ''' <summary>
            ''' Decrypts the specified data using provided key and preset initialization vector
            ''' </summary>
            Public Function Decrypt(encryptedData As Data, key As Data) As Data
                  Me.Key = key
                  Return Decrypt(encryptedData)
            End Function

            ''' <summary>
            ''' Decrypts the specified stream using provided key and preset initialization vector
            ''' </summary>
            Public Function Decrypt(encryptedStream As Stream, key As Data) As Data
                  Me.Key = key
                  Return Decrypt(encryptedStream)
            End Function

            ''' <summary>
            ''' Decrypts the specified stream using preset key and preset initialization vector
            ''' </summary>
            Public Function Decrypt(encryptedStream As Stream) As Data
                  Dim ms As New System.IO.MemoryStream()
                  Dim b As Byte() = New Byte(_BufferSize) {}

                  ValidateKeyAndIv(False)
                  Dim cs As New CryptoStream(encryptedStream, _crypto.CreateDecryptor(), CryptoStreamMode.Read)

                  Dim i As Integer = 0
                  i = cs.Read(b, 0, _BufferSize)

                  While i > 0
                        ms.Write(b, 0, i)
                        i = cs.Read(b, 0, _BufferSize)
                  End While
                  cs.Close()
                  ms.Close()

                  Return New Data(ms.ToArray())
            End Function

            ''' <summary>
            ''' Decrypts the specified data using preset key and preset initialization vector
            ''' </summary>
            Public Function Decrypt(encryptedData As Data) As Data
                  Try
                        Dim ms As New System.IO.MemoryStream(encryptedData.Bytes, 0, encryptedData.Bytes.Length)
                        Dim b As Byte() = New Byte(encryptedData.Bytes.Length - 1) {}

                        ValidateKeyAndIv(False)
                        Dim cs As New CryptoStream(ms, _crypto.CreateDecryptor(), CryptoStreamMode.Read)

                        Try
                              cs.Read(b, 0, encryptedData.Bytes.Length - 1)
                        Catch ex As CryptographicException
                              Throw New CryptographicException("Unable to decrypt data. The provided key may be invalid.", ex)
                        Finally
                              cs.Close()
                        End Try
                        Return New Data(b)
                  Catch
                        Return Nothing
                  End Try
            End Function
      End Class


      #End Region

      #Region " Data"

      ''' <summary>
      ''' represents Hex, Byte, Base64, or String data to encrypt/decrypt;
      ''' use the .Text property to set/get a string representation
      ''' use the .Hex property to set/get a string-based Hexadecimal representation
      ''' use the .Base64 to set/get a string-based Base64 representation
      ''' </summary>
      Public Class Data
            Private _b As Byte()
            Private _MaxBytes As Integer = 0
            Private _MinBytes As Integer = 0
            Private _StepBytes As Integer = 0

            ''' <summary>
            ''' Determines the default text encoding across ALL Data instances
            ''' </summary>
            Public Shared DefaultEncoding As System.Text.Encoding = System.Text.Encoding.GetEncoding("Windows-1252")

            ''' <summary>
            ''' Determines the default text encoding for this Data instance
            ''' </summary>
            Public Encoding As System.Text.Encoding = DefaultEncoding

            ''' <summary>
            ''' Creates new, empty encryption data
            ''' </summary>
            Public Sub New()
            End Sub

            ''' <summary>
            ''' Creates new encryption data with the specified byte array
            ''' </summary>
            Public Sub New(b As Byte())
                  _b = b
            End Sub

            ''' <summary>
            ''' Creates new encryption data with the specified string;
            ''' will be converted to byte array using default encoding
            ''' </summary>
            Public Sub New(s As String)
                  Me.Text = s
            End Sub

            ''' <summary>
            ''' Creates new encryption data using the specified string and the
            ''' specified encoding to convert the string to a byte array.
            ''' </summary>
            Public Sub New(s As String, encoding As System.Text.Encoding)
                  Me.Encoding = encoding
                  Me.Text = s
            End Sub

            ''' <summary>
            ''' returns true if no data is present
            ''' </summary>
            Public ReadOnly Property IsEmpty() As Boolean
                  Get
                        If _b Is Nothing Then
                              Return True
                        End If
                        If _b.Length = 0 Then
                              Return True
                        End If
                        Return False
                  End Get
            End Property

            ''' <summary>
            ''' allowed step interval, in bytes, for this data; if 0, no limit
            ''' </summary>
            Public Property StepBytes() As Integer
                  Get
                        Return _StepBytes
                  End Get
                  Set
                        _StepBytes = value
                  End Set
            End Property

            ''' <summary>
            ''' minimum number of bytes allowed for this data; if 0, no limit
            ''' </summary>
            Public Property MinBytes() As Integer
                  Get
                        Return _MinBytes
                  End Get
                  Set
                        _MinBytes = value
                  End Set
            End Property

            ''' <summary>
            ''' maximum number of bytes allowed for this data; if 0, no limit
            ''' </summary>
            Public Property MaxBytes() As Integer
                  Get
                        Return _MaxBytes
                  End Get
                  Set
                        _MaxBytes = value
                  End Set
            End Property

            ''' <summary>
            ''' Returns the byte representation of the data;
            ''' This will be padded to MinBytes and trimmed to MaxBytes as necessary!
            ''' </summary>
            Public Property Bytes() As Byte()
                  Get
                        If _MaxBytes > 0 Then
                              If _b.Length > _MaxBytes Then
                                    Dim b As Byte() = New Byte(_MaxBytes - 1) {}
                                    Array.Copy(_b, b, b.Length)
                                    _b = b
                              End If
                        End If
                        If _MinBytes > 0 Then
                              If _b.Length < _MinBytes Then
                                    Dim b As Byte() = New Byte(_MinBytes - 1) {}
                                    Array.Copy(_b, b, _b.Length)
                                    _b = b
                              End If
                        End If
                        Return _b
                  End Get
                  Set
                        _b = value
                  End Set
            End Property

            ''' <summary>
            ''' Sets or returns text representation of bytes using the default text encoding
            ''' </summary>
            Public Property Text() As String
                  Get
                        If _b Is Nothing Then
                              Return ""
                        Else
                              '-- need to handle nulls here; oddly, C# will happily convert
                              '-- nulls into the string whereas VB stops converting at the
                              '-- first null!
                              Dim i As Integer = Array.IndexOf(_b, CByte(0))
                              If i >= 0 Then
                                    Return Me.Encoding.GetString(_b, 0, i)
                              Else
                                    Return Me.Encoding.GetString(_b)
                              End If
                        End If
                  End Get
                  Set
                        _b = Me.Encoding.GetBytes(value)
                  End Set
            End Property

            ''' <summary>
            ''' Sets or returns Hex string representation of this data
            ''' </summary>
            Public Property Hex() As String
                  Get
                        Return Utils.ToHex(_b)
                  End Get
                  Set
                        _b = Utils.FromHex(value)
                  End Set
            End Property

            ''' <summary>
            ''' returns Hex string representation of this data
            ''' </summary>
            Public Function ToHex() As String
                  Return Me.Hex
            End Function
      End Class


      #End Region

      #Region " Utils"

      ''' <summary>
      ''' Friend class for shared utility methods used by multiple Encryption classes
      ''' </summary>
      Friend Class Utils

            ''' <summary>
            ''' converts an array of bytes to a string Hex representation
            ''' </summary>
            Friend Shared Function ToHex(ba As Byte()) As String
                  If ba Is Nothing OrElse ba.Length = 0 Then
                        Return ""
                  End If
                  Const  HexFormat As String = "{0:X2}"
                  Dim sb As New StringBuilder()
                  For Each b As Byte In ba
                        sb.Append(String.Format(HexFormat, b))
                  Next
                  Return sb.ToString()
            End Function

            ''' <summary>
            ''' converts from a string Hex representation to an array of bytes
            ''' </summary>
            Friend Shared Function FromHex(hexEncoded As String) As Byte()
                  If hexEncoded Is Nothing OrElse hexEncoded.Length = 0 Then
                        Return Nothing
                  End If
                  Try
                        Dim l As Integer = Convert.ToInt32(hexEncoded.Length \ 2)
                        Dim b As Byte() = New Byte(l - 1) {}
                        For i As Integer = 0 To l - 1
                              b(i) = Convert.ToByte(hexEncoded.Substring(i * 2, 2), 16)
                        Next
                        Return b
                  Catch ex As Exception
                        Throw New System.FormatException("The provided string does not appear to be Hex encoded:" & Environment.NewLine & hexEncoded & Environment.NewLine, ex)
                  End Try
            End Function
      End Class

End Namespace

#End Region
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ArkCommented:
Remove everything (including Class ... End Class directives) from cEncryption.vb code - code page must be blank. Then copy/paste your vb converted code.
BTW
End Namespace
#End Region

Open in new window

must be
#End Region
End Namespace

Open in new window

at the end
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much. I had actually done that but been thrown by that last bit. Appreciate the help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.