I have a Java application which stores passwords in database encrypted with PBKDF2 and SHA-1. Actually, I used the function "getEncryptedPassword" shown on this page:
http://blog.jerryorr.com/2012/05/secure-password-storage-lots-of-donts.html#exampleThe encrypted password and salt are stored in database.
Now I need FPC application to log in to same database using same usernames and passwords. Therefore, I need to read Salt stored in DB, encrypt the password provided by the user the same way and then compare the encrypted password with the one stored in db.
The
DCPcrypt wiki page links to PBKDF2 implementation based on DCPcrypt:
http://keit.co/p/dcpcrypt-hmac-rfc2104/Even
PBKDF2 Wikipedia page links to same page as "Delphi/Free Pascal implementation".
I downloaded DCPcrypt package and copied the code from the mentioned page. Now I don't know how to properly use the PBKDF2 function from that page - it is declared this way:
function PBKDF2(pass, salt: ansistring; count, kLen: Integer; hash: TDCP_hashclass): ansistring;
I believe I should call it this way:
uses
..., DCPsha1;
...
var
Pass, Salt, DKey: String;
...
DKey = PBKDF2(Pass, Salt, 20000, 160, TDCP_sha1);
Where Pass is variable of type String which has the password provided by the user, count of 20000 and key length of 160 are what is used in
Java function mentioned above and TDCP_sha1 is the class from DCPcrypt package (unit DCPsha1), which represents SHA-1 algorithm used in Java function.
Now, I do not know how to use Salt, which is in
Java function getEncryptedPassword declared as byte[] (that would be
array of ShortInt in FPC, as Java type byte is signed, unlike Pacal type Byte, so Java byte maps to Pascal ShortInt.
I read the salt from DB and I have array of ShortInt. How should I make the String to use with PBKDF2 Pascal funtion?