Ideally, do not store the password/key, even as cyphertext (in an encrypted form).
Instead, store a salted hash (say SHA256) of the password/key. For example, for each user, you could store:
sha256 hash of the user name.
randomly generated salt for this user.
sha256 salted hash of the password/key.
To validate a user name and password/key:
a. compute the sha256 hash of user name
b. look up hash and get the salt for this user
c. append the salt to the password/key
d. compute its sha256 hash
e. verify against the stored hash.
> and what is the best library for this perpess?
The best library for this would be a cross-platform cryptographic hash library, that is easy to installl and use.
For instance hashlib++
http://hashlib2plus.sourceforge.net/index.html