在SQL SERVER中实现RSA加密算法(第二版)
/***************************************************
作者:herowang(让你望见影子的墙)
日期:2010.1.5
注: 转载请保留此信息
更多内容,请访问我的博客:blog.csdn.net/herowang
****************************************************/
/*
本次修改增加了unicode的支持,但是加密后依然显示为16进制数据,因为进行RSA加密后所得到的unicode编码是无法显示的,所以密文依然采用16进制数据显示。
需要特别注意:如果要对中文进行加密,那么所选取的两个素数要比较大,两个素数的成绩最好要大于65536,即大于unicode的最大编码值
另外修改了第一个版本的部分函数名称
*/
在SQL SERVER中实现RSA加密算法
--判断是否为素数
if object_id('f_primeNumTest') is not null
drop function f_primeNumTest
go
create function [dbo].[f_primeNumTest]
(@p int)
returns bit
begin
declare @flg bit,@i int
select @flg=1, @i=2
while @i<sqrt(@p)
begin
if(@p%@i=0 )
begin
set @flg=0
break
end
set @i=@i+1
end
return @flg
end
go
--判断两个数是否互素
if object_id('f_isNumsPrime') is not null
drop function f_isNumsPrime
go
create function f_isNumsPrime
(@num1 int,@num2 int)
returns bit
begin
declare @tmp int,@flg bit
set @flg=1
while (@num2%@num1<>0)
begin
select @tmp=@num1,@num1=@num2%@num1,@num2=@tmp
end
if @num1=1
set @flg=0
return @flg
end
go
--产生密钥对
if object_id('p_createKey') is not null
drop proc p_createKey
go
create proc p_createKey
@p int,@q int
as
begin
decla
相关文档:
常用SQL查询:
1、查看表空间的名称及大小
select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size
from dba_tablespaces t, dba_data_files d
where t.tablespace_name = d.tablespace_name
group by t.tablespace_name;
2、查看表空间物理文件的名称及大小
select tablespace_name, file_id, ......
--跨服务器查询如下:
SELECT a.*,b.stor_Name
from OPENROWSET('MSDASQL',
'DRIVER={SQL Server};SERVER=tom;UID=sa;PWD=123',
pubs.dbo.authors) AS a,stores b
ORDER BY a.au_lname, a.au_fname
--其中,tom为远程服务器名,stores 是本机数据库pubs中的表
--需要注意的是若二个表中的 ......
left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录
right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录
inner join(等值连接) 只返回两个表中联结字段相等的行
举例如下:
--------------------------------------------
表A记录如下:
aID aNum
1 a ......
use Tempdb
go
if object_ID('fn_ACITEncryption') is not null
drop function fn_ACITEncryption
go
create function fn_ACITEncryption
(
@Str nvarchar(4000),--加密的字符串
@Flag bit=1,--1、加密 0、解密
@Key nvarchar(50)--密文
)
returns nvarchar(4000)--這里可轉換 ......