A person acting or purporting to act in an official capacity or taking advantage of such actual or purported capacity commits a misdemeanor of the second degree if, knowing that his conduct is illegal, he:
(1) subjects another to arrest, detention, search, seizure, mistreatment, dispossession, assessment, lien or other infringement of personal or property rights; or
(2) denies or impedes another in the exercise or enjoyment of any right, privilege, power or immunity.