internal string Decrypt(string cryptText, string encryptionKey, bool isPrivate)
{
RsaKeyParameters key;
byte[] data = null;
List<byte> output = new List<byte>();
string result = null;
try
{
if (isPrivate)
key = RsaPrivateStringToRsaKey(encryptionKey);
else
key = RsaPublicStringToRsaKey(encryptionKey);
data = Hex.Decode(cryptText);
IAsymmetricBlockCipher e = new Pkcs1Encoding(new RsaEngine()).GetUnderlyingCipher();
e.Init(false, key);
int blockSize = e.GetInputBlockSize();
if (data != null)
{
for (int chunkPosition = 0; chunkPosition < data.Length; chunkPosition += blockSize)
{
int chunkSize;
if (data.Length <= blockSize)
chunkSize = data.Length;
else if ((chunkPosition + blockSize) > data.Length)
chunkSize = data.Length - chunkPosition;
else
chunkSize = blockSize;
if (chunkSize <= 0)
break;
output.AddRange(e.ProcessBlock(data, chunkPosition, chunkSize));
}
result = ByteArrayToString(output.ToArray());
}
}
catch (Exception ex)
{
Debug.Write(ex.ToString());
}
return result;
}