当前位置:网站首页>Symmetric encryption, certificate encryption
Symmetric encryption, certificate encryption
2022-04-23 12:03:00 【I boiled the night white_】
-------------------------------------------------------- Symmetric encryption ---------------------------
create table Employee_encryption
(
Eid char(5) primary key not null,
Did char(4) not null,
Ename char(10) not null,
Esex char(2) not null,
Ebirth date check(Ebirth>='1956-1-1' and Ebirth<='2050-1-1'),
salary varbinary(1000) not null,
foreign key(Did) references Department(Did)
)
-- Create a database master key
CREATE MASTER KEY ENCRYPTION BY PASSWORD ='1209QQ-1'
-- Create a symmetric key using the database master key
CREATE SYMMETRIC KEY salaryKey
WITH ALGORITHM =AES_256
ENCRYPTION BY PASSWORD = '1209QQ-1'
-- Open symmetric key PWDKEY
OPEN SYMMETRIC KEY salaryKey
DECRYPTION BY PASSWORD = '1209QQ-1'
-- insert data
insert into Employee_encryption(Eid,Did,Ename,Esex,Ebirth,salary) values
('60301','1001','xxx',' Woman ','2000-05-01',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'3000')),
('60403','2002','xxx',' Woman ','2000-08-23',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'2500')),
('30124','3002',' Song Zhihao ',' male ','1998-09-11',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'3600')),
('21004','3003',' Jialin ',' male ','1993-07-09',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'1369')),
('02305','5003',' Shijia ',' Woman ','2000-01-03',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'2596')),
('04506','4001',' Du Bang Bang ',' male ','1992-08-25',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'3654')),
('05607','1001',' Xiao Lin ',' Woman ','1997-04-29',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'1515')),
('00228','4002',' Song Jia ',' male ','1978-09-30',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'9600')),
('40109','2003',' beautiful ',' Woman ','1999-10-17',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'6800')),
('40518','5002',' Beautiful ',' Woman ','1999-03-08',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'50000'))
SELECT Eid,Did,Ename,Esex,Ebirth,CONVERT(VARCHAR,DECRYPTBYKEY(salary)) as salary FROM Employee_encryption
CLOSE SYMMETRIC KEY salaryKey
------------------------- Encrypt the database with a certificate --------------------------------
-- Add column
ALTER TABLE Employee_encryption ADD marriage varbinary(1000)
-- Delete column
ALTER TABLE Employee_encryption DROP COLUMN marriage
CREATE CERTIFICATE CER_MARRIAGE
WITH SUBJECT='encrypt balance', -- The subject of the certificate
START_DATE='01/01/2022', -- Certificate activation date
EXPIRY_DATE= '06/12/2022' -- Certificate expiration date
--DROP CERTIFICATE CER_BALANCE
INSERT INTO Employee_encryption values
('90000','5001',' certificate 1',' male ','1988-08-08',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'1000'),ENCRYPTBYCERT(CERT_ID('CER_MARRIAGE'),'1')),
('90001','5001',' certificate 2',' Woman ','2013-01-05',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'5300'),ENCRYPTBYCERT(CERT_ID('CER_MARRIAGE'),'0')),
('90002','5001',' certificate 3',' male ','1976-03-04',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'6300'),ENCRYPTBYCERT(CERT_ID('CER_MARRIAGE'),'1'))
--delete from Employee_encryption where eid='90000'
SELECT Eid,Did,Ename,Esex,Ebirth,
CONVERT(VARCHAR,DECRYPTBYKEY(salary)) as salary ,
CONVERT(VARCHAR,DECRYPTBYCERT(CERT_ID('CER_MARRIAGE'), marriage))
FROM Employee_encryption
版权声明
本文为[I boiled the night white_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231158303737.html
边栏推荐
- 为什么要有包装类,顺便说一说基本数据类型、包装类、String类该如何转换?
- IDEA 数据库插件Database Navigator 插件
- Idea code formatting plug-in save actions
- 云呐|固定资产盘点中,支持多种盘点方式(资产清查盘点)
- 5个免费音频素材网站,建议收藏
- Interpretation of biological recognition in robot programming course
- Tensorflow uses keras to create neural networks
- docker MySQL主从备份
- Exploring the equipment and teaching of robot education
- 如果你是一个Golang面试官,你会问哪些问题?
猜你喜欢

Nacos Foundation (6): Nacos configuration management model

Docker MySQL master-slave backup

Design and practice of the smallest short website system in the whole network

Nacos Foundation (9): Nacos configuration management from single architecture to microservices

WIN10 启动后花屏

激活函数之阶跃函数

Yunna | how to manage the company's fixed assets and how to manage fixed assets

Next. JS static data generation and server-side rendering

Database Navigator 使用默认MySQL连接提示:The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized or repres

C# F23. Stringsimilarity Library: String repeatability, text similarity, anti plagiarism
随机推荐
Fastjson 2 来了,性能继续提升,还能再战十年
WIN10 启动后花屏
论坛系统数据库设计
Fabric 1.0 source code analysis (33) implementation of peer channel command and subcommand
画结果图推荐网址
[web daily practice] eight color puzzle (float)
1.Electron开发环境搭建
第四章 为IM 启用填充对象之在NO INMEMORY表上指定INMEMORY列属性:示例(IM-4.4 第四部分)
IFLYTEK's revenue in 2021 was 18.3 billion yuan: a year-on-year increase of 41% and a net profit of 1.556 billion yuan
C# F23.StringSimilarity库 字符串重复度、文本相似度、防抄袭
Database design of simple voting system
golang之笔试题&面试题01
Analyzing the role of social robots in basic science
程序员如何用130行代码敲定核酸统计
九十八、freemarker框架报错 s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request
用户接口和IM表达式(IM 5.6)
Tensorflow common functions
Yunna | fixed assets inventory supports multiple inventory methods (asset inventory)
Idea code formatting plug-in save actions
On the integration of steam education in early childhood education