在SQL SERVER中实现RSA加密算法
/***************************************************
作者:herowang(让你望见影子的墙)
日期:2010.1.1
注: 转载请保留此信息
更多内容,请访问我的博客:blog.csdn.net/herowang
****************************************************/
在SQL SERVER中实现RSA加密算法
一、RSA算法原理
RSA算法非常简单,概述如下:
找两素数p和q
取n=p*q
取t=(p-1)*(q-1)
取任何一个数e,要求满足e<t并且e与t互素(就是最大公因数为1)
取d*e%t==1
这样最终得到三个数: n d e
设消息为数M (M <n)
设c=(M**d)%n就得到了加密后的消息c
设m=(c**e)%n则 m == M,从而完成对c的解密。
注:**表示次方,上面两式中的d和e可以互换。
在对称加密中:
n d两个数构成公钥,可以告诉别人;
n e两个数构成私钥,e自己保留,不让任何人知道。
给别人发送的信息使用e加密,只要别人能用d解开就证明信息是由你发送的,构成了签名机制。
别人给你发送信息时使用d加密,这样只有拥有e的你能够对其解密。
rsa的安全性在于对于一个大数n,没有有效的方法能够将其分解从而在已知n d的情况下无法获得e;同样在已知n e的情况下无法求得d。
以上内容出自原文出处http://www.xfocus.net/articles/200503/778.html
二、使用T-SQL实现RSA算法
--判断是否为素数
if object_id('f_pnumtest') is not null
drop function f_isPrimeNum
go
create function [dbo].[f_isPrimeNum]
(@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
--判断两个数是否互素,首先要选取两个互素的数
if object_id('f_
相关文档:
先来一段代码:
WITH OrderedOrders AS
(SELECT *,
ROW_NUMBER() OVER (order by [id])as RowNumber --id是用来排序的列
from table_info ) --table_info是表名
SELECT *
from OrderedOrders
WHERE RowNumber between 50 and 60;
在windows server 2003, sql server 2005 CTP,P4 2.66GHZ,1GB 内存下测试,执行时 ......
Aaron Bertrand
Adam Machanic
All Things SQL Server
Allen Kinsel - SQL DBA
Allen White
Amit Bansal writes...
Andrew Fryer's Blog
Andrew Kelly
Andy Leonard
Anything and Everything IT
Arcane Code
Arnie Rowland: Ramblings of a Harried Technogeek
B.I. for the SQL Guy
Bart Duncan's SQL Weblog ......
declare @ID varchar(10)
set @ID=9 --根节点
declare @i int --级数
declare @t table(ID varchar(10),ParentID varchar(10),Level int)
set @i = 1
insert into @t select @ID,0,0 --当前级,本级,如果不要的话可以注释掉或再加个参数来选择操作
insert into @t select ID,ParentID,@i from t_ ......
游标的类型:
1、静态游标(不检测数据行的变化)
2、动态游标(反映所有数据行的改变)
3、仅向前游标(不支持滚动)
4、键集游标(能反映修改,但不能准确反映插入、删除)
游标使用顺序:
1、定义游标
2、打开游标
3、使用游标
  ......