当前位置:网站首页>对称加密、证书加密
对称加密、证书加密
2022-04-23 11:58:00 【我把夜熬成了白_】
--------------------------------------------------------对称加密---------------------------
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 MASTER KEY ENCRYPTION BY PASSWORD ='1209QQ-1'
--使用数据库主密钥创建一个对称密钥
CREATE SYMMETRIC KEY salaryKey
WITH ALGORITHM =AES_256
ENCRYPTION BY PASSWORD = '1209QQ-1'
--打开对称密钥PWDKEY
OPEN SYMMETRIC KEY salaryKey
DECRYPTION BY PASSWORD = '1209QQ-1'
--插入数据
insert into Employee_encryption(Eid,Did,Ename,Esex,Ebirth,salary) values
('60301','1001','xxx','女','2000-05-01',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'3000')),
('60403','2002','xxx','女','2000-08-23',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'2500')),
('30124','3002','宋志豪','男','1998-09-11',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'3600')),
('21004','3003','佳霖','男','1993-07-09',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'1369')),
('02305','5003','世佳','女','2000-01-03',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'2596')),
('04506','4001','度棒棒','男','1992-08-25',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'3654')),
('05607','1001','小霖','女','1997-04-29',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'1515')),
('00228','4002','宋佳','男','1978-09-30',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'9600')),
('40109','2003','美丽','女','1999-10-17',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'6800')),
('40518','5002','俊美','女','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
-------------------------使用证书对数据库加密--------------------------------
--增加列
ALTER TABLE Employee_encryption ADD marriage varbinary(1000)
--删除列
ALTER TABLE Employee_encryption DROP COLUMN marriage
CREATE CERTIFICATE CER_MARRIAGE
WITH SUBJECT='encrypt balance', --证书的主题
START_DATE='01/01/2022', --证书启用日期
EXPIRY_DATE= '06/12/2022' --证书到期日期
--DROP CERTIFICATE CER_BALANCE
INSERT INTO Employee_encryption values
('90000','5001','证书1','男','1988-08-08',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'1000'),ENCRYPTBYCERT(CERT_ID('CER_MARRIAGE'),'1')),
('90001','5001','证书2','女','2013-01-05',ENCRYPTBYKEY(KEY_GUID('salaryKey'),'5300'),ENCRYPTBYCERT(CERT_ID('CER_MARRIAGE'),'0')),
('90002','5001','证书3','男','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
版权声明
本文为[我把夜熬成了白_]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_42214698/article/details/124329555
边栏推荐
- ImportError: libX11. so. 6: cannot open shared object file: No such file or directory
- The database navigator uses the default MySQL connection prompt: the server time zone value 'Ö Ð¹ ú±ê ×¼ ʱ ¼ ä’ is unrecognized or repres
- 使用连接组优化连接 (IM 6)
- 解决由于找不到amd_ags_x64.dll,无法继续执行代码。重新安装程序可能会解决此问题,地平线(Forza Horizon 5)
- 一文详解头部位姿估计【收藏好文】
- Windows11 安装MySQL服务 提示:Install/Remove of the Service Denied
- 第四章 为IM 启用填充对象之启用和禁用表空间的IM列存储(IM 4.5)
- The listing of saiweidian Technology Innovation Board broke: a decrease of 26% and the market value of the company was 4.4 billion
- Redis learning 5 - high concurrency distributed lock practice
- Database Navigator 使用默认MySQL连接提示:The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized or repres
猜你喜欢

论文解读(CGC)《CGC: Contrastive Graph Clustering for Community Detection and Tracking》

解决由于找不到amd_ags_x64.dll,无法继续执行代码。重新安装程序可能会解决此问题,地平线(Forza Horizon 5)

云呐|固定资产盘点中,支持多种盘点方式(资产清查盘点)

激活函数之relu函数

Win10 splash screen after startup

Tensorflow使用keras创建神经网络的方法

Simple construction of rebbitmq

Maker education for primary and middle school students to learn in happiness

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

Sigmoid function of activation function
随机推荐
Change exchange II - [leetcode]
Redis optimization series (II) redis master-slave principle and master-slave common configuration
Next. JS static data generation and server-side rendering
In idea Solution to the problem of garbled code in Chinese display of properties file
第二十三课 临时对象
力扣-70.爬楼梯
第二十六课 类的静态成员函数
IDEA 代码格式化插件Save Actions
After a circle, I sorted out this set of interview questions..
《通用数据保护条例》(GDPR)系列解读三:欧洲子公司如何向国内母公司回传数据?
Database Navigator 使用默认MySQL连接提示:The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized or repres
Castle.DynamicProxy实现事务单元控制
软银愿景基金进军Web3安全行业 领投CertiK 6000万美元新一轮投资
软件测试基础DAY2-用例执行
Tensorflow使用keras创建神经网络的方法
Master slave replication configuration of MySQL
第二十五课 类的静态成员变量
Analyze the rules for the use of robots with good performance
Practical data Lake iceberg lesson 30 MySQL - > iceberg, time zone problems of different clients
VMware虚拟机使用esxi 导出硬盘vmdk文件