我想在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