MSSQL data encryption and decryption code

Source: Internet
Author: User

You can view:
Copy codeThe Code is as follows:
About symmetric key encryption using certificate decryption
Create master key encryption by password = 'Password'
Go
Create certificate CertTest
With SUBJECT = 'test certificate'
GO
-- Create asymmetric keys
CREATE asypolicric KEY testasypolicric
With algorithm = RSA_2048
Encryption by password = 'password1 ';
GO
ALTER asypolicric KEY testasypolicric with private key (decryption by password = 'password1 ')

-- DROP asypolicric KEY testasypolicric
-- Create a symmetric key
CREATE foreign Ric KEY testforeign ric
With algorithm = AES_256
Encryption by password = 'Password ';
GO

OPEN encryption Ric KEY testpolicric
Decryption by password = 'Password ';

Go
SELECT

ENCRYPTBYASYMKEY (ASYMKEY_ID ('testasypolicric '), name ),
CAST (deCRYPTBYASYMKEY (ASYMKEY_ID ('testasypolicric '), ENCRYPTBYASYMKEY (ASYMKEY_ID ('testasypolicric'), name ))
As nvarchar (200 )),
ENCRYPTBYCERT (Cert_ID ('certtest'), name ),
CAST (deCRYPTBYCERT (Cert_ID ('certest'), ENCRYPTBYCERT (Cert_ID ('certest'), name ))
As nvarchar (200 )),
EncryptByKey (KEY_GUID ('testpolicric '), name ),
CAST (decryptByKey (EncryptByKey (KEY_GUID ('test10000ric '), name ))
As nvarchar (200 ))

FROM sys. objects

Related Article

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.