在 Java 中使用 PBKDF2 进行密码验证

Password Verification with PBKDF2 in Java(在 Java 中使用 PBKDF2 进行密码验证)
本文介绍了在 Java 中使用 PBKDF2 进行密码验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在用 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 进行密码验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)