public byte[] DecryptData(byte[] EncryptedData)
{
Brunet.Util.MemBlock iv_ref = Brunet.Util.MemBlock.Reference(EncryptedData, 0, BlockSizeByte);
ICryptoTransform dec = (ICryptoTransform) _decryptors[iv_ref];
if(dec == null) {
byte[] iv = new byte[BlockSizeByte];
iv_ref.CopyTo(iv, 0);
dec = _sa.CreateDecryptor(_sa.Key, iv);
} else {
_decryptors.Remove(iv_ref);
}
int count = EncryptedData.Length - BlockSizeByte;
iv_ref = Brunet.Util.MemBlock.Reference(EncryptedData, count, BlockSizeByte);
_decryptors[iv_ref] = dec;
if((count % BlockSizeByte) > 0 || count == 0) {
throw new CryptographicException("Invalid input block size.");
}
byte[] output = new byte[count];
dec.TransformBlock(EncryptedData, BlockSizeByte, count, output, 0);
byte padding = output[count - 1];
int length = count - padding;
for(int i = length; i < count; i++) {
if(output[i] != padding) {
throw new CryptographicException(String.Format("Bad padding at position {0}.", i));
}
}
byte[] res = new byte[length];
Buffer.BlockCopy(output, 0, res, 0, length);
return res;
}