SQL2005 supports the deployment of. NET applications in SQL Server, then some of the operations previously written in. NET, such as encryption, have been completely moved to SQL, without the need to operate from the program, so that the database can be relatively independent of the program, a lot of convenience.
Before the array, need to encrypt data, so write a 3DES encryption function deployed to SQL2005, of course, now the secret key also as a table in the database, as for this key, you can later consider using Usb-key RSA encryption or other ways to encrypt, to ensure data security. Let's start by saying how to implement cryptographic functions deployed to SQL Server.
Create a new project. Database-->sql Server project in VB, I created a project called Descryptoservice later, and then you add a database reference and select the database you want to deploy to.
Write the following code and it's OK.
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server
Imports System.IO
Imports System.Xml
Imports System.Text
Imports System.Security.Cryptography
Partial Public Class Encrypttobase64decryptfrombase64class encrypttobase64decryptfrombase64
_
Public Shared function encrypttobase64string () function encrypttobase64string (ByVal stringtoencryptsql as SqlString, ByVal Sencryptionkeysql as SqlString) as SqlString
Dim Stringtoencrypt as String = CType (Stringtoencryptsql, String)
Dim Sencryptionkey as String = CType (Sencryptionkeysql, String)
Dim IV () as Byte = {&h12, &h34, &h56, &h78, &H90, &hab, &HCD, &hef}
Dim key () as Byte = {}
Try
Key = System.Text.Encoding.UTF8.GetBytes (left (Sencryptionkey, 8))
Dim des as New DESCryptoServiceProvider ()
Dim Inputbytearray () as Byte = Encoding.UTF8.GetBytes (stringtoencrypt)
Dim MS as New MemoryStream ()
Dim CS as New CryptoStream (MS, Des. CreateEncryptor (Key, IV), CryptoStreamMode.Write)
Cs. Write (Inputbytearray, 0, Inputbytearray.length)
Cs. FlushFinalBlock ()
http://www.bkjia.com/PHPjc/631039.html www.bkjia.com true http://www.bkjia.com/PHPjc/631039.html techarticle SQL2005 supports the deployment of. NET applications in SQL Server, some of the operations that have been written in. NET, such as encryption, have been completely moved to SQL, without needing to go from the program ...