MSSQL数据加密解密代码

可以查看:


复制代码 代码如下:

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

(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐