I have a proprietary application that uses an extension to handle cryptography. To encrypt a string I feed it Exponent, Modulus, Base and string as parameters. It returns the encrypted string.
I need to be able to replicate this functionality in a c# application that talks to the proprietary application. I'm unsure where to begin with this – and would appreciate any help you can give.
This is what I have at the moment;
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);
}
}
When I encrypt data using the proprietary application, and then try using the above code - the resulting encrypted data is different.
I'm at a loss at how to proceed.
edit; It returns a different string everytime it's ran. Using the same input string.