我想在C#中實現RSA加密。我把它用小扳手的工作像這樣:C#:RSA實現不能用大鍵
public static int n = 33;
public static int e = 7;
public static int d = 3;
static void Main(string[] args)
{
int A = 9;
int enc = (int)(Math.Pow(A, e) % n);
int dec = (int)(Math.Pow(enc, d) % n);
Console.WriteLine(A);
Console.WriteLine(enc);
Console.WriteLine(dec);
}
此輸出:
9
15
9
我不明白爲什麼它不具有較大的鍵的工作。如果我給這些鍵值:
public static int n = 3233;
public static int e = 17;
public static int d = 2753;
它輸出:
9
1971
-2147483648
根據維基百科(並與一所大學的網站上的RSA計算器檢查),N = 3233 E = 17 d = 2753是一個有效的RSA密鑰集。
有人可以解釋爲什麼我沒有得到預期的輸出?
請注意,有[類](http://msdn.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider .aspx)在.NET Framework中爲您處理RSA加密/解密。不要實施任何家庭安全,這是容易出錯的方法。 – nvoigt 2013-05-02 06:33:22