Encryption and DataSets in Memory Stream

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I wrote the follwoing code and was wondering if this function will return an encrypted dataset. Can someone proof this and tell me if this is the correct way of encrypting a dataset

Public Function EncryptDataSet(ByVal ds As DataSet) As DataSe

'instatiate a MemoryStrea
Dim ms As New MemoryStrea

'Instantiate one of the excryption methods. This activates the key
Dim DES As New DESCryptoServiceProvide

'Set up the Private Key (No one sees this
Dim keyBytes() As Byte = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0

'Set up the Encryptor by using the Provider with the keyByte
Dim DESEncryptor As ICryptoTransform = DES.CreateEncryptor(keyBytes, keyBytes

'Crypt the MemeoryStream and with the keys and set the stream to writ
Dim cryptStream As New CryptoStream(ms, DESEncryptor, CryptoStreamMode.Write

'Write the dataset to the cryptic strea
Dim byteInAsByte As Byte() = System.Convert.ChangeType(ds, TypeCode.Byte
Dim byteInAsInt As Integer = System.Convert.ChangeType(ds, TypeCode.Int32
cryptStream.Write(byteInAsByte, 0, byteInAsInt

'Return the Dataset Encrypted??
Return System.Convert.ChangeType(ms, TypeCode.Object

End Function
 
Bryan:

You have a few issues with this... The first one being you don't have option
strict ON ;-). The size of your IV isn't going to fly either for DES. I'll
post the corrected update in a few minutes

Bill
Bryan said:
I wrote the follwoing code and was wondering if this function will return
an encrypted dataset. Can someone proof this and tell me if this is the
correct way of encrypting a dataset?
Public Function EncryptDataSet(ByVal ds As DataSet) As DataSet

'instatiate a MemoryStream
Dim ms As New MemoryStream

'Instantiate one of the excryption methods. This activates the keys
Dim DES As New DESCryptoServiceProvider

'Set up the Private Key (No one sees this)
Dim keyBytes() As Byte = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}

'Set up the Encryptor by using the Provider with the keyBytes
Dim DESEncryptor As ICryptoTransform =
DES.CreateEncryptor(keyBytes, keyBytes)
 
Bryan, it's going to take a fair amount of work so give me a few minutes.
Bryan said:
I wrote the follwoing code and was wondering if this function will return
an encrypted dataset. Can someone proof this and tell me if this is the
correct way of encrypting a dataset?
Public Function EncryptDataSet(ByVal ds As DataSet) As DataSet

'instatiate a MemoryStream
Dim ms As New MemoryStream

'Instantiate one of the excryption methods. This activates the keys
Dim DES As New DESCryptoServiceProvider

'Set up the Private Key (No one sees this)
Dim keyBytes() As Byte = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}

'Set up the Encryptor by using the Provider with the keyBytes
Dim DESEncryptor As ICryptoTransform =
DES.CreateEncryptor(keyBytes, keyBytes)
 
Back
Top