VB.Net/Database ADO.net/Encrypt Database Data — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 12:44, 26 мая 2010
Encrypt a DataSet
Imports System
Imports System.Xml
Imports System.Xml.Schema
Imports System.IO
Imports System.Data.OleDb
Imports System.Data.rumon
Imports System.Data.SqlClient
Imports System.Data
Imports System.Security
Imports System.Security.Cryptography
Public Class MainClass
Shared Sub Main()
Dim fs As FileStream = New FileStream("DSencrypted.dat",FileMode.Create, FileAccess.Write)
Dim MyDS As DataSet = New DataSet()
Dim MyDS2 As DataSet = New DataSet()
Dim Connection As SqlConnection = New SqlConnection("Server=(local)\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=SSPI")
Connection.Open()
Dim MyDA As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM Employee", Connection)
MyDA.Fill(MyDS, "Employee")
Dim DES As DESCryptoServiceProvider = New DESCryptoServiceProvider()
Dim DESencrypter As ICryptoTransform = DES.CreateEncryptor()
Dim cryptStream As CryptoStream = New CryptoStream(fs, DESencrypter, CryptoStreamMode.Write)
MyDS.WriteXml(cryptStream, XmlWriteMode.WriteSchema)
cryptStream.Close()
End Sub
End Class
Save data from Database table to a DES Encrypted file
Imports System
Imports System.Xml
Imports System.Xml.Schema
Imports System.IO
Imports System.Data.OleDb
Imports System.Data.rumon
Imports System.Data.SqlClient
Imports System.Data
Imports System.Security
Imports System.Security.Cryptography
Public Class MainClass
Shared Sub Main()
Dim fs As FileStream = New FileStream("DSencrypted.dat",FileMode.Create, FileAccess.Write)
Dim MyDS As DataSet = New DataSet()
Dim MyDS2 As DataSet = New DataSet()
Dim Connection As SqlConnection = New SqlConnection("Server=(local)\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=SSPI")
Connection.Open()
Dim MyDA As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM Employee", Connection)
MyDA.Fill(MyDS, "Employee")
Dim DES As DESCryptoServiceProvider = New DESCryptoServiceProvider()
Dim DESencrypter As ICryptoTransform = DES.CreateEncryptor()
Dim cryptStream As CryptoStream = New CryptoStream(fs, DESencrypter, CryptoStreamMode.Write)
MyDS.WriteXml(cryptStream, XmlWriteMode.WriteSchema)
cryptStream.Close()
End Sub
End Class