問題描述
我正在用 Java 進行基于密碼的文件加密;我使用 AES 作為底層加密算法和 PBKDF2WithHmacSHA1
使用以下代碼(我從本網站上的另一張慷慨的海報中獲得)從鹽和密碼組合中派生密鑰.
I'm doing password based file encryption in Java; I'm using AES as the underlying encryption algorithm and PBKDF2WithHmacSHA1
to derive a key from a salt and password combination using the following code (which I got from another generous poster on this site).
SecretKeyFactory f = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
KeySpec ks = new PBEKeySpec(password,salt,1024,128);
SecretKey s = f.generateSecret(ks);
Key k = new SecretKeySpec(s.getEncoded(),"AES");
我共享鹽,用戶在每一端輸入他們的密碼,加密和解密工作正常:-) 我的問題是我希望能夠在開始之前驗證用戶輸入的密碼是否正確(可能很長)解密過程.我知道 PBKD 規范包含一個可選的 2 字節驗證值,但我不確定如何使用上述方法生成該值.Java 是否為此提供支持,或者如果不提供支持,那將是一個安全的替代方案嗎?
I share the salt, the user enters their password at each end and encryption and decryption work fine :-) My problem is that i would like to be able to verify that the password the user enters is correct before embarking on the (potentially long) decryption process. I know the PBKD spec includes an optional 2 byte verification value but I'm not sure how to generate this value using the above approach. Does Java provide support for this or if not what would be a secure alternative?
感謝您的寶貴時間.
推薦答案
嘿,感謝瘋狂的蘇格蘭人和克里斯的幫助.在做了一些挖掘之后,我決定使用 Dr Gladmans 文件加密頁面 上描述的方法用于進行密碼驗證和消息驗證.我相信這種基于 PBKDF2 和 MAC 的方法使得導出密碼的驗證值足夠昂貴以使其安全.再次感謝,我希望這個解決方案對其他人有所幫助.
Hey, thanks to crazy scot and Chris for there help. After doing some digging i decided to use the methods described on Dr Gladmans file encryption page for doing both password verification and message authentication. I believe this method, based on the PBKDF2 and a MAC, makes deriving the verfication value for m the password sufficiently expensive as to make it secure. Thanks again, and i hope this solution aids others.
這篇關于在 Java 中使用 PBKDF2 進行密碼驗證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!