Home > Backend Development > PHP Tutorial > Deploying .net 3DES encryption function in SQL2005_PHP tutorial

Deploying .net 3DES encryption function in SQL2005_PHP tutorial

WBOY
Release: 2016-07-13 17:02:34
Original
784 people have browsed it

SQL2005 supports the deployment of .net applications in SQL SERVER, so some operations such as encryption that have been written in .net can be completely moved to sql, without the need to perform calculations from the program, making the database It can be relatively independent from the program, which is a lot more convenient.
A while ago, I needed to encrypt data, so I wrote a 3DES encryption function and deployed it in SQL2005. Of course, the secret key now also exists as a table in the database. As for this key, you can consider using usb-key in the future. rsa encryption or other encryption methods to ensure data security. Now let’s talk about how to implement the encryption function deployed in sqlserver.
Create a new project. Database in VB-->SQL Server Project, I created a new project called DESCryptoService. After that, you will be asked to add a database reference and select the database you want to deploy to.
Write the following code and it will be 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()

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631039.htmlTechArticleSQL2005 supports deploying .net applications in SQL SERVER, so some operations that have been written in .net before For example, encryption can be completely moved to sql, without the need to start from the program...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template