200分吐血,rsa 算法的解密和加密的控件哪里可以下载,大侠快就我啊(200分)

  • 主题发起人 主题发起人 wjserver
  • 开始时间 开始时间
W

wjserver

Unregistered / Unconfirmed
GUEST, unregistred user!
200分吐血,rsa 算法的解密和加密的控件哪里可以下载,大侠快就我啊
要有源码和sample
 
加密:RSA加密算法介绍
作者: 评价: 上站日期: 2002-05-01
内容说明:
来源:

--------------------------------------------------------------------------------




  首先, 找出三个数, p, q, r,

  其中 p, q 是两个相异的质数, r 是与 (p-1)(q-1) 互质的数。

  p, q, r 这三个数便是 private key。接著, 找出m, 使得 rm == 1 mod (p-1)(q-1)..... 这个 m 一定存在, 因为 r 与 (p-1)(q-1) 互质, 用辗转相除法就可以得到了..... 再来, 计算 n = pq....... m, n 这两个数便是 public key。

  编码过程是, 若资料为 a, 将其看成是一个大整数, 假设 a < n.... 如果 a > = n 的话, 就将 a 表成 s 进位 (s < = n, 通常取 s = 2^t), 则每一位数均小於 n, 然後分段编码...... 接下来, 计算 b == a^m mod n, (0 < = b < n), b 就是编码後的资料...... 解码的过程是, 计算 c == b^r mod pq (0 < = c < pq), 於是乎, 解码完毕...... 等会会证明 c 和 a 其实是相等的 :) 如果第三者进行窃听时, 他会得到几个数: m, n(=pq), b...... 他如果要解码的话, 必须想办法得到 r...... 所以, 他必须先对 n 作质因数分解......... 要防止他分解, 最有效的方法是找两个非常的大质数 p, q, 使第三者作因数分解时发生困难......... < 定理> 若 p, q 是相异质数, rm == 1 mod (p-1)(q-1), a 是任意一个正整数, b == a^m mod pq, c == b^r mod pq, 则 c == a mod pq 证明的过程, 会用到费马小定理, 叙述如下: m 是任一质数, n 是任一整数, 则 n^m == n mod m (换另一句话说, 如果 n 和 m 互质, 则 n^(m-1) == 1 mod m) 运用一些基本的群论的知识, 就可以很容易地证出费马小定理的........ < 证明> 因为 rm == 1 mod (p-1)(q-1), 所以 rm = k(p-1)(q-1) + 1, 其中 k 是整数 因为在 modulo 中是 preserve 乘法的 (x == y mod z and u == v mod z => xu == yv mod z), 所以, c == b^r == (a^m)^r == a^(rm) == a^(k(p-1)(q-1)+1) mod pq 1. 如果 a 不是 p 的倍数, 也不是 q 的倍数时, 则 a^(p-1) == 1 mod p (费马小定理) => a^(k(p-1)(q-1)) == 1 mod p a^(q-1) == 1 mod q (费马小定理) => a^(k(p-1)(q-1)) == 1 mod q 所以 p, q 均能整除 a^(k(p-1)(q-1)) - 1 => pq | a^(k(p-1)(q-1)) - 1 即 a^(k(p-1)(q-1)) == 1 mod pq => c == a^(k(p-1)(q-1)+1) == a mod pq 2. 如果 a 是 p 的倍数, 但不是 q 的倍数时, 则 a^(q-1) == 1 mod q (费马小定理) => a^(k(p-1)(q-1)) == 1 mod q => c == a^(k(p-1)(q-1)+1) == a mod q => q | c - a 因 p | a => c == a^(k(p-1)(q-1)+1) == 0 mod p => p | c - a 所以, pq | c - a => c == a mod pq 3. 如果 a 是 q 的倍数, 但不是 p 的倍数时, 证明同上 4. 如果 a 同时是 p 和 q 的倍数时, 则 pq | a => c == a^(k(p-1)(q-1)+1) == 0 mod pq => pq | c - a => c == a mod pq Q.E.D. 这个定理说明 a 经过编码为 b 再经过解码为 c 时, a == c mod n (n = pq).... 但我们在做编码解码时, 限制 0 < = a < n, 0 < = c < n, 所以这就是说 a 等於 c, 所以这个过程确实能做到编码解码的功能.....




 
http://www.neweasier.com/downloadvcl.html?id=1640
但是没有源代码
 
//RSA的加密和解密函数,等价于(m^e) mod n(即m的e次幂对n求余)
function Encrypt_Decrypt(m: Int64; e: Int64=$2C86F9; n: Int64=$69AAA0E3): Int64;
var
a, b, c: Int64;
begin
a:=m;
b:=e;
c:=1;
while b<>0 do
if (b mod 2)=0
then begin
b:=b div 2;
a:=(a * a) mod n;
end
else begin
b:=b - 1;
c:=(a * c) mod n;
end;
Result:=c;
end;
 
我这里有源代码,但我不知道怎么用
 
http://www.vclxx.org/DELPHIGB/AAAT1027.HTM#Encrypt
到这里来慢慢找看
 
看看这个行不行。
SoftLock加密控件(v1.0)
http://www.csdn.net/cnshare/soft/openfile.asp?kind=1&id=12690
SoftLock加密控件是一个用于保护软件产品的ActiveX控件。

SoftLock加密控件将用户软件绑定在计算机“硬件指纹”上,即计算机的硬盘号、主板信息等特征参数,使得只有经过授权的计算机可以运行指定的产品。比如可以使用控件来使用户软件几个功能无效直到它被注册为止(类似“无效功能软件”),或者在某段时间之后软件无法使用(类似“试用软件”)。

主要技术指标:
加密算法采用 RSA-MD5,RSA-SHA1单向散列函数,128位加密。
公开密钥算法(也叫非对称算法)设计。
硬件指纹采用物理硬盘序列号以及CPU序列号和ID号。
 
md5算法(网上收集)
unit MD5;

interface

uses
SysUtils;

const
MD5Version = 102;
CopyRight : String = ' MD5 Message-Digest (c) 97-98 F. Piette V1.02 ';

{$Q-}
{$R-}

type
TMD5Context = record
State: array[0..3] of LongInt;
Count: array[0..1] of LongInt;
case Integer of
0: (BufChar: array[0..63] of Byte);
1: (BufLong: array[0..15] of LongInt);
end;
TMD5Digest = array[0..15] of Char;

procedure MD5Init(var MD5Context: TMD5Context);
procedure MD5Update(var MD5Context: TMD5Context;
const Data;
Len: Integer);
procedure MD5Transform(var Buf: array of LongInt;
const Data: array of LongInt);
procedure MD5UpdateBuffer(var MD5Context: TMD5Context;
Buffer: Pointer;
BufSize: Integer);
procedure MD5Final(var Digest: TMD5Digest; var MD5Context: TMD5Context);

function GetMD5(Buffer: Pointer; BufSize: Integer): string;
function StrMD5(Buffer : String): string;

implementation

const
MaxBufSize = 16384;

type
PMD5Buffer = ^TMD5Buffer;
TMD5Buffer = array[0..(MaxBufSize - 1)] of Char;



{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ MD5 initialization. Begins an MD5 operation, writing a new context. }
procedure MD5Init(var MD5Context: TMD5Context);
begin
FillChar(MD5Context, SizeOf(TMD5Context), #0);
with MD5Context do begin
{ Load magic initialization constants. }
State[0] := LongInt($67452301);
State[1] := LongInt($EFCDAB89);
State[2] := LongInt($98BADCFE);
State[3] := LongInt($10325476);
end
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ MD5 block update operation. Continues an MD5 message-digest operation, }
{ processing another message block, and updating the context. }
procedure MD5Update(
var MD5Context: TMD5Context; { Context }
const Data; { Input block }
Len: Integer); { Length of input block }
type
TByteArray = array[0..0] of Byte;
var
Index: Word;
T: LongInt;
begin
with MD5Context do begin
T := Count[0];
Inc(Count[0], LongInt(Len) shl 3);
if Count[0] < T then
Inc(Count[1]);
Inc(Count[1], Len shr 29);
T := (T shr 3) and $3F;
Index := 0;
if T <> 0 then begin
Index := T;
T := 64 - T;
if Len < T then begin
Move(Data, BufChar[Index], Len);
Exit;
end;
Move(Data, BufChar[Index], T);
MD5Transform(State, BufLong);
Dec(Len, T);
Index := T; { Wolfgang Klein, 05/06/99 }
end;
while Len >= 64 do begin
Move(TByteArray(Data)[Index], BufChar, 64);
MD5Transform(State, BufLong);
Inc(Index, 64);
Dec(Len, 64);
end;
Move(TByteArray(Data)[Index], BufChar, Len);
end
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ MD5 finalization. Ends an MD5 message-digest operation, writing the message }
{ digest and zeroizing the context. }
procedure MD5Final(var Digest: TMD5Digest; var MD5Context: TMD5Context);
var
Cnt : Word;
P : Byte;
begin
with MD5Context do begin
Cnt := (Count[0] shr 3) and $3F;
P := Cnt;
BufChar[P] := $80;
Inc(P);
Cnt := 64 - 1 - Cnt;
if Cnt < 8 then begin
FillChar(BufChar[P], Cnt, #0);
MD5Transform(State, BufLong);
FillChar(BufChar, 56, #0);
end
else
FillChar(BufChar[P], Cnt - 8, #0);
BufLong[14] := Count[0];
BufLong[15] := Count[1];
MD5Transform(State, BufLong);
Move(State, Digest, 16)
end;
FillChar(MD5Context, SizeOf(TMD5Context), #0)
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ MD5 basic transformation. Transforms state based on block. }
procedure MD5Transform(
var Buf: array of LongInt;
const Data: array of LongInt);
var
A, B, C, D: LongInt;

procedure Round1(var W: LongInt; X, Y, Z, Data: LongInt; S: Byte);
begin
Inc(W, (Z xor (X and (Y xor Z))) + Data);
W := (W shl S) or (W shr (32 - S));
Inc(W, X)
end;

procedure Round2(var W: LongInt; X, Y, Z, Data: LongInt; S: Byte);
begin
Inc(W, (Y xor (Z and (X xor Y))) + Data);
W := (W shl S) or (W shr (32 - S));
Inc(W, X)
end;

procedure Round3(var W: LongInt; X, Y, Z, Data: LongInt; S: Byte);
begin
Inc(W, (X xor Y xor Z) + Data);
W := (W shl S) or (W shr (32 - S));
Inc(W, X)
end;

procedure Round4(var W: LongInt; X, Y, Z, Data: LongInt; S: Byte);
begin
Inc(W, (Y xor (X or not Z)) + Data);
W := (W shl S) or (W shr (32 - S));
Inc(W, X)
end;
begin
A := Buf[0];
B := Buf[1];
C := Buf[2];
D := Buf[3];

Round1(A, B, C, D, Data[ 0] + LongInt($d76aa478), 7);
Round1(D, A, B, C, Data[ 1] + LongInt($e8c7b756), 12);
Round1(C, D, A, B, Data[ 2] + LongInt($242070db), 17);
Round1(B, C, D, A, Data[ 3] + LongInt($c1bdceee), 22);
Round1(A, B, C, D, Data[ 4] + LongInt($f57c0faf), 7);
Round1(D, A, B, C, Data[ 5] + LongInt($4787c62a), 12);
Round1(C, D, A, B, Data[ 6] + LongInt($a8304613), 17);
Round1(B, C, D, A, Data[ 7] + LongInt($fd469501), 22);
Round1(A, B, C, D, Data[ 8] + LongInt($698098d8), 7);
Round1(D, A, B, C, Data[ 9] + LongInt($8b44f7af), 12);
Round1(C, D, A, B, Data[10] + LongInt($ffff5bb1), 17);
Round1(B, C, D, A, Data[11] + LongInt($895cd7be), 22);
Round1(A, B, C, D, Data[12] + LongInt($6b901122), 7);
Round1(D, A, B, C, Data[13] + LongInt($fd987193), 12);
Round1(C, D, A, B, Data[14] + LongInt($a679438e), 17);
Round1(B, C, D, A, Data[15] + LongInt($49b40821), 22);

Round2(A, B, C, D, Data[ 1] + LongInt($f61e2562), 5);
Round2(D, A, B, C, Data[ 6] + LongInt($c040b340), 9);
Round2(C, D, A, B, Data[11] + LongInt($265e5a51), 14);
Round2(B, C, D, A, Data[ 0] + LongInt($e9b6c7aa), 20);
Round2(A, B, C, D, Data[ 5] + LongInt($d62f105d), 5);
Round2(D, A, B, C, Data[10] + LongInt($02441453), 9);
Round2(C, D, A, B, Data[15] + LongInt($d8a1e681), 14);
Round2(B, C, D, A, Data[ 4] + LongInt($e7d3fbc8), 20);
Round2(A, B, C, D, Data[ 9] + LongInt($21e1cde6), 5);
Round2(D, A, B, C, Data[14] + LongInt($c33707d6), 9);
Round2(C, D, A, B, Data[ 3] + LongInt($f4d50d87), 14);
Round2(B, C, D, A, Data[ 8] + LongInt($455a14ed), 20);
Round2(A, B, C, D, Data[13] + LongInt($a9e3e905), 5);
Round2(D, A, B, C, Data[ 2] + LongInt($fcefa3f8), 9);
Round2(C, D, A, B, Data[ 7] + LongInt($676f02d9), 14);
Round2(B, C, D, A, Data[12] + LongInt($8d2a4c8a), 20);

Round3(A, B, C, D, Data[ 5] + LongInt($fffa3942), 4);
Round3(D, A, B, C, Data[ 8] + LongInt($8771f681), 11);
Round3(C, D, A, B, Data[11] + LongInt($6d9d6122), 16);
Round3(B, C, D, A, Data[14] + LongInt($fde5380c), 23);
Round3(A, B, C, D, Data[ 1] + LongInt($a4beea44), 4);
Round3(D, A, B, C, Data[ 4] + LongInt($4bdecfa9), 11);
Round3(C, D, A, B, Data[ 7] + LongInt($f6bb4b60), 16);
Round3(B, C, D, A, Data[10] + LongInt($bebfbc70), 23);
Round3(A, B, C, D, Data[13] + LongInt($289b7ec6), 4);
Round3(D, A, B, C, Data[ 0] + LongInt($eaa127fa), 11);
Round3(C, D, A, B, Data[ 3] + LongInt($d4ef3085), 16);
Round3(B, C, D, A, Data[ 6] + LongInt($04881d05), 23);
Round3(A, B, C, D, Data[ 9] + LongInt($d9d4d039), 4);
Round3(D, A, B, C, Data[12] + LongInt($e6db99e5), 11);
Round3(C, D, A, B, Data[15] + LongInt($1fa27cf8), 16);
Round3(B, C, D, A, Data[ 2] + LongInt($c4ac5665), 23);

Round4(A, B, C, D, Data[ 0] + LongInt($f4292244), 6);
Round4(D, A, B, C, Data[ 7] + LongInt($432aff97), 10);
Round4(C, D, A, B, Data[14] + LongInt($ab9423a7), 15);
Round4(B, C, D, A, Data[ 5] + LongInt($fc93a039), 21);
Round4(A, B, C, D, Data[12] + LongInt($655b59c3), 6);
Round4(D, A, B, C, Data[ 3] + LongInt($8f0ccc92), 10);
Round4(C, D, A, B, Data[10] + LongInt($ffeff47d), 15);
Round4(B, C, D, A, Data[ 1] + LongInt($85845dd1), 21);
Round4(A, B, C, D, Data[ 8] + LongInt($6fa87e4f), 6);
Round4(D, A, B, C, Data[15] + LongInt($fe2ce6e0), 10);
Round4(C, D, A, B, Data[ 6] + LongInt($a3014314), 15);
Round4(B, C, D, A, Data[13] + LongInt($4e0811a1), 21);
Round4(A, B, C, D, Data[ 4] + LongInt($f7537e82), 6);
Round4(D, A, B, C, Data[11] + LongInt($bd3af235), 10);
Round4(C, D, A, B, Data[ 2] + LongInt($2ad7d2bb), 15);
Round4(B, C, D, A, Data[ 9] + LongInt($eb86d391), 21);

Inc(Buf[0], A);
Inc(Buf[1], B);
Inc(Buf[2], C);
Inc(Buf[3], D);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure MD5UpdateBuffer(
var MD5Context: TMD5Context;
Buffer: Pointer;
BufSize: Integer);
var
BufTmp : PMD5Buffer;
BufPtr : PChar;
Bytes : Word;
begin
New(BufTmp);
BufPtr := Buffer;
try
repeat
if BufSize > MaxBufSize then
Bytes := MaxBufSize
else
Bytes := BufSize;
Move(BufPtr^, BufTmp^, Bytes);
Inc(BufPtr, Bytes);
Dec(BufSize, Bytes);
if Bytes > 0 then
MD5Update(MD5Context, BufTmp^, Bytes);
until Bytes < MaxBufSize;
finally
Dispose(BufTmp);
end;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function GetMD5(Buffer: Pointer; BufSize: Integer): string;
var
I : Integer;
MD5Digest : TMD5Digest;
MD5Context : TMD5Context;
begin
for I := 0 to 15 do
Byte(MD5Digest) := I + 1;
MD5Init(MD5Context);
MD5UpdateBuffer(MD5Context, Buffer, BufSize);
MD5Final(MD5Digest, MD5Context);
Result := '';
for I := 0 to 15 do
Result := Result + IntToHex(Byte(MD5Digest), 2);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function StrMD5(Buffer : String): string;
begin
Result := GetMD5(@Buffer[1], Length(Buffer));
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}

end.

MD5单元,不可逆加密,请使用最后一个函数
 
后退
顶部