Reputation: 21
I have a set of rsa keys which I know for a fact are correct.
then I input a byte array into the decrypt and still get an error
this is the data
"145,17,111,244,10,231,164,19,83,89,134,206,115,122,243,61,115,61,214,37,204,2,240,173,251,241,131,226,218,203,153,157,192,45,36,235,203,85,89,151,198,141,225,158,116,3,70,218,88,163,121,19,6,181,231,41,42,171,76,147,197,29,6,215,15,151,197,146,31,3,35,138,136,251,91,249,194,134,131,109,250,106,90,64,227,21,132,121,70,90,21,226,131,36,26,30,223,54,50,163,126,3,5,230,136,32,206,221,0,187,111,187,114,116,44,109,54,41,103,223,26,114,108,200,210,122,58,35,179,225,176,113,133,73,201,38,45,46,133,180,19,58,181,175,67,129,224,85,239,157,123,172,38,182,249,150,78,181,138,126,71,95,192,154,228,183,48,157,206,134,22,122,98,5,61,107,225,149,112,147,62,216,193,167,145,223,173,112,87,148,111,186,8,239,96,55,198,1,111,4,180,20,107,194,94,36,209,70,99,21,132,96,209,17,165,131,155,97,120,20,190,204,189,29,47,70,239,97,13,27,192,123,245,254,28,61,202,160,226,68,106,105,99,10,180,185,98,36,75,41,168,189,83,220,216,138"
this was encrypted using a 2048 bit public key then inputed as a string into a decrypt function
public string Decrypt(string data)
{
try
{
var dataArray = data.Split(',');
byte[] dataByte = new byte[dataArray.Length];
for (int i = 0; i < dataArray.Length; i++)
{
dataByte[i] = Convert.ToByte(dataArray[i]);
}
_rsa.FromXmlString(_privateKey);
var decryptedByte = _rsa.Decrypt(dataByte, false);
return _encoder.GetString(decryptedByte);
}
catch (Exception e)
{
Console.WriteLine(e);
}
return "x";
}
I get the error here var decryptedByte = _rsa.Decrypt(dataByte, false);
Upvotes: 0
Views: 60
Reputation: 144
ASCIIEncoding ByteConverter = new ASCIIEncoding();
byte[] dataByte = new byte[dataArray.Length];
for (int i = 0; i < dataArray.Length; i++)
{
dataByte[i] = ByteConverter.GetBytes(dataArray[i]);
}
Upvotes: 0