【发布时间】:2014-01-31 20:03:36
【问题描述】:
基本上是这样。 我想使用密码的哈希来加密主密钥。 目前我使用的代码是这样的
try {
//Conservazione delle chiavi!
//Secure PRNG
SecureRandom m = SecureRandom.getInstance("SHA1PRNG");
//Secure HASH
MessageDigest hash = MessageDigest.getInstance("SHA-1");
//KeyGenerator
KeyGenerator keyGenerator = KeyGenerator.getInstance("DES");
keyGenerator.init(m);
//Want to obtain a random masterkey that need to encrypt
Key key = keyGenerator.generateKey();
//Get DES cipher
Cipher cipher = Cipher.getInstance("DES");
//AND NOW?
cipher.init(Cipher.ENCRYPT_MODE, KEY); // THAT's the problem.
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchPaddingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
密钥是我密码的哈希值..
像 hash.digest(passphrase.getBytes());
其中密码是一个简单的字符串。
关于如何使用散列作为键的任何建议?
我应该使用密码的哈希来初始化 keyGenerator 吗?
【问题讨论】:
-
通过代码中的 cmets 阅读您的问题有点困难。你能在问题的散文中提出一个明确的问题吗?
标签: java hash key encryption