I think the methods used in /etc/shadow (classic unix-crypt or MD5) and the like would not work for you, as these methods are one-way. You cannot decrypt anything, you can only check if a password is valid by putting the user-supplied password though the hashing (
encrypting) algorithm and comparing the result to the stored value in /etc/shadow.