【发布时间】:2010-10-15 10:38:41
【问题描述】:
我有一个专有应用程序,它使用扩展来处理密码学。为了加密字符串,我将指数、模数、基数和字符串作为参数提供给它。它返回加密的字符串。
我需要能够在与专有应用程序对话的 c# 应用程序中复制此功能。我不确定从哪里开始——如果你能提供任何帮助,我将不胜感激。
这是我目前拥有的;
public class Cryptography
{
public static RSACryptoServiceProvider rsa;
public static void AssignParameter()
{
const int PROVIDER_RSA_FULL = 1;
const string CONTAINER_NAME = "SpiderContainer";
CspParameters cspParams;
cspParams = new CspParameters(PROVIDER_RSA_FULL);
cspParams.KeyContainerName = CONTAINER_NAME;
//cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
cspParams.ProviderName = "Microsoft Strong Cryptographic Provider";
rsa = new RSACryptoServiceProvider(cspParams);
}
public static string Sencrypt(string input)
{
RSAParameters parameters = new RSAParameters();
parameters.Modulus = System.Text.Encoding.Unicode.GetBytes("nononomonomnomfoononmo");
parameters.Exponent = System.Text.Encoding.Unicode.GetBytes("b");
rsa.ImportParameters(parameters);
byte[] plainbytes = System.Text.Encoding.UTF8.GetBytes(input);
byte[] cipherbytes = rsa.Encrypt(plainbytes, false);
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
//return enc.GetString(cipherbytes);
return Convert.ToBase64String(cipherbytes);
}
}
当我使用专有应用程序加密数据,然后尝试使用上述代码 - 生成的加密数据不同。
我不知道如何继续。
编辑;每次运行它都会返回一个不同的字符串。使用相同的输入字符串。
【问题讨论】:
-
您需要显示您尝试匹配的扩展代码。使用“指数、模数、基数和字符串”作为参数的加密留下了无限的可能性。尝试和猜测对我们来说毫无意义。您的模数和指数 C# 代码有点难以置信。你从哪里得到这些字符串的?
标签: c# encryption cryptography