欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

MSSQL数据加密解密代码

程序员文章站 2023-12-12 21:41:34
可以查看: 复制代码 代码如下: open symmetric key 命令关于 对称密钥加密使用证书解密 create master key encryption by...
可以查看:
复制代码 代码如下:

open symmetric key 命令关于 对称密钥加密使用证书解密
create master key encryption by password = 'password'
go
create certificate certtest
with subject = 'test certificate'
go
--创建非对称密钥
create asymmetric key testasymmetric
with algorithm = rsa_2048
encryption by password = 'password1' ;
go
alter asymmetric key testasymmetric with private key (decryption by password = 'password1')

--drop asymmetric key testasymmetric
--创建对称密钥
create symmetric key testsymmetric
with algorithm = aes_256
encryption by password = 'password' ;
go

open symmetric key testsymmetric
decryption by password = 'password' ;

go
select

encryptbyasymkey(asymkey_id ('testasymmetric'), name) ,
cast(decryptbyasymkey (asymkey_id( 'testasymmetric'),encryptbyasymkey (asymkey_id( 'testasymmetric'),name ) )
as nvarchar(200 )),
encryptbycert ( cert_id('certtest' ),name),
cast(decryptbycert (cert_id ('certtest'), encryptbycert (cert_id( 'certtest'),name ))
as nvarchar (200)),
encryptbykey ( key_guid('testsymmetric' ),name),
cast(decryptbykey (encryptbykey (key_guid ('testsymmetric'), name))
as nvarchar (200))

from sys .objects

上一篇:

下一篇: