_php tutorial on deploying. NET 3DES Cryptographic functions in SQL2005

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.