我在http://ace.ulyssis.student.kuleuven.ac.be/~triade/上下载了RSA控件,下面是它的一个例子:
请问:
1: Base10StringToFGInt('102336547456161301', p);
Base256StringToFGInt('AEFAFGhdhsgoi!?ty!a', q);
Base10StringToFGInt('65537', e);
// just an odd starting point
程序中的这三句话,是否要根据自已的情况修改?它们是不是私有密钥?
2:如果明文已知,是不是只要有人破解出上面三句话中的'102336547456161301','AEFAFGhdhsgoi!?ty!a'
'65537'字符串,就能生成密文?从而做出注册机?
3:RSAEncrypt(test, e, n, test)语句生成的密文是乱码,请问谁能提供一个函数编码为十六进制的数,使之成为可以读的字符串?
4:RSASign(test, d, n, Nilgint, Nilgint, Nilgint, Nilgint, signature);
RSAVerify(test, signature, e, n, ok);
上面两句是不是另外一种RSA加密算法?
//-----------------------------------------------------------------------------------------
uses FGInt, FGIntPrimeGeneration, FGIntRSA;
Procedure RSAEncryptAndDecrypt_SignAndVerify;
var
n, e, d, dp, dq, p, q, phi, one, two, gcd, temp, nilgint : TFGInt;
test, signature : String;
ok : boolean;
begin
// Enter a random number to generate a prime, i.e.
// incremental search starting from that number
Base10StringToFGInt('102336547456161301', p);
PrimeSearch(p);
Base256StringToFGInt('AEFAFGhdhsgoi!?ty!a', q);
PrimeSearch(q);
// Compute the modulus
FGIntMul(p, q, n);
// Compute p-1, q-1 by adjusting the last digit of the GInt
p.Number[1] := p.Number[1] - 1;
q.Number[1] := q.Number[1] - 1;
// Compute phi
FGIntMul(p, q, phi);
// Choose a public exponent e such that GCD(e,phi)=1
// common values are 3, 65537 but if these aren 't coprime
// to phi, use the following code
Base10StringToFGInt('65537', e);
// just an odd starting point
Base10StringToFGInt('1', one);
Base10StringToFGInt('2', two);
FGIntGCD(phi, e, gcd);
While FGIntCompareAbs(gcd, one) <> Eq do
begin
FGIntadd(e, two, temp);
FGIntCopy(temp, e);
FGIntGCD(phi, e, gcd);
end;
FGIntDestroy(two);
FGIntDestroy(one);
FGIntDestroy(gcd);
// Compute the modular (multiplicative) inverse of e, i.e. the secret exponent (key)
FGIntModInv(e, phi, d);
FGIntModInv(e, p, dp);
FGIntModInv(e, q, dq);
p.Number[1] := p.Number[1] + 1;
q.Number[1] := q.Number[1] + 1;
FGIntDestroy(phi);
FGIntDestroy(nilgint);
// Now everything is set up to start Encrypting/Decrypting, Signing/Verifying
test := 'eagles may soar high, but weasles do
not get sucked into jet engines';
RSAEncrypt(test, e, n, test);
RSADecrypt(test, d, n, Nilgint, Nilgint, Nilgint, Nilgint, test);
// this Is faster : RSADecrypt(test, nilGInt, n, dp, dq, p, q, test);
RSASign(test, d, n, Nilgint, Nilgint, Nilgint, Nilgint, signature);
// this Is faster : RSASign(test, nilgint, n, dp, dq, p, q, signature);
RSAVerify(test, signature, e, n, ok);
FGIntDestroy(p);
FGIntDestroy(q);
FGIntDestroy(dp);
FGIntDestroy(dq);
FGIntDestroy(e);
FGIntDestroy(d);
FGIntDestroy
;
end;
//---------------------------------------------------------------------------------------