Hi,

I have a create a new project (Control Library). And I am using this code. However it returns the following error:
Type 'PasswordDeriverBytes' is not defined regarding the SetKey function. (highlighted in bold) What am I missing out. I originally took this code from a windows form (for a desktop not PPC).

I really need to get this fixed.

Thanks in advance

VB Code:
  1. Imports System.Security.Cryptography
  2. Imports System.IO
  3. Public Class PDACrypt
  4.     Public Sub New()
  5.         MyBase.New()
  6.         InitializeComponent()
  7.         clientRC2CryptoServiceProvider = New RC2CryptoServiceProvider()
  8.     End Sub
  9.  
  10.     Public Shared clientRC2CryptoServiceProvider As RC2CryptoServiceProvider
  11.  
  12.     Private Function SetEncKey(ByVal pwd As String) As Byte()
  13.         Dim drive As Long
  14.         Dim rnd As Random
  15.         rnd = New Random
  16.         Dim byts(7) As Byte '8 bytes
  17.         rnd.NextBytes(byts)
  18.         SetKey(pwd, byts)
  19.         Return byts
  20.     End Function
  21.     Private Sub SetDecKey(ByVal pwd As String, ByVal salt As Byte())
  22.         Dim drive As Long
  23.         SetKey(pwd, salt)
  24.     End Sub[b]
  25.     Private Sub SetKey(ByVal pwd As String, ByVal salt As Byte())
  26.         Dim deriver As PasswordDeriveBytes
  27.         deriver = New PasswordDeriveBytes(pwd, salt)
  28.         clientRC2CryptoServiceProvider.Key = deriver.GetBytes(clientRC2CryptoServiceProvider.LegalKeySizes(0).MaxSize \ 8)
  29.         clientRC2CryptoServiceProvider.IV = deriver.GetBytes(clientRC2CryptoServiceProvider.BlockSize \ 8)
  30.     End Sub[/b]
  31.     Public Function EncryptFileRC2(ByVal pwd As String, ByVal fin As String, ByVal feout As String)
  32.         Dim fileStream As FileStream
  33.         Dim lngFileLength As Double = 0
  34.         fileStream = File.OpenWrite(feout)
  35.         Dim writeStream As BinaryWriter
  36.         writeStream = New BinaryWriter(fileStream)
  37.         Dim myByte As Byte
  38.         Dim salt() As Byte
  39.         salt = SetEncKey(pwd)
  40.         Try
  41.             Dim i As Integer
  42.             For i = 0 To salt.Length - 1
  43.                 writeStream.Write(salt(i))
  44.             Next
  45.             writeStream.Flush()
  46.         Catch
  47.         End Try
  48.         Dim encryptor As ICryptoTransform
  49.         encryptor = clientRC2CryptoServiceProvider.CreateEncryptor()
  50.         Dim encStream As CryptoStream
  51.         encStream = New CryptoStream(fileStream, encryptor, CryptoStreamMode.Write)
  52.  
  53.  
  54.         Dim fI As New FileInfo(fin)
  55.         Dim lngLoopCounter As Double = 0
  56.         lngFileLength = fI.Length
  57.  
  58.         Dim readStream As BinaryReader
  59.         readStream = New BinaryReader(File.OpenRead(fin))
  60.         Try
  61.             Do
  62.                 'pbStatus.Value = (100 / lngFileLength) * lngLoopCounter
  63.                 lngLoopCounter = lngLoopCounter + 1
  64.                 myByte = readStream.ReadByte()
  65.                 encStream.WriteByte(myByte)
  66.             Loop
  67.         Catch
  68.             encStream.FlushFinalBlock()
  69.             encStream.Flush()
  70.         End Try
  71.         encStream.Close()
  72.         fileStream.Close()
  73.         readStream.Close()
  74.     End Function
  75.     Public Function DecryptFileRC2(ByVal pwd As String, ByVal fin As String, ByVal fdout As String)
  76.         Dim fileStream As FileStream
  77.         fileStream = File.OpenRead(fin)
  78.         Dim salt(7) As Byte
  79.         Try
  80.             Dim i As Integer
  81.             For i = 0 To 7
  82.                 salt(i) = fileStream.ReadByte()
  83.             Next
  84.             SetDecKey(pwd, salt)
  85.         Catch
  86.             fileStream.Close()
  87.             '            Return
  88.         End Try
  89.         Dim encryptor As ICryptoTransform
  90.         encryptor = clientRC2CryptoServiceProvider.CreateDecryptor()
  91.         Dim decStream As CryptoStream
  92.         decStream = New CryptoStream(fileStream, encryptor, CryptoStreamMode.Read)
  93.         Dim readStream As BinaryReader
  94.         readStream = New BinaryReader(decStream)
  95.  
  96.         Dim lngFileLength As Double = 0
  97.         Dim fI As New FileInfo(fin)
  98.         Dim lngLoopCounter As Double = 0
  99.         lngFileLength = fI.Length
  100.  
  101.         Dim writeStream As BinaryWriter
  102.         writeStream = New BinaryWriter(File.OpenWrite(fdout))
  103.         Dim myByte As Byte
  104.         Try
  105.             Do
  106.                 'pbStatus.Value = (100 / lngFileLength) * lngLoopCounter
  107.                 lngLoopCounter = lngLoopCounter + 1
  108.                 myByte = readStream.ReadByte()
  109.                 writeStream.Write(myByte)
  110.             Loop
  111.         Catch
  112.             writeStream.Flush()
  113.         End Try
  114.         writeStream.Close()
  115.         fileStream.Close()
  116.         readStream.Close()
  117.     End Function
  118. End Class