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
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