我正在使用WSS4J签署一条肥皂消息。在构建WSSecSignature时,我收到以下错误:
java.security.UnrecoverableKeyException: Cannot recover key
此处特别出现错误:
sun.security.provider.KeyProtector.recover(KeyProtector.java:328)
我已经三次检查我使用了正确的密码,它是完全相同的。如果我为不同的密码更改它,我会得到一个关于无法访问密钥库的错误。查看代码后,可以在此处看到其副本:
/*
* Check the integrity of the recovered key by concatenating it with
* the password, digesting the concatenation, and comparing the
* result of the digest operation with the digest provided at the end
* of <code>protectedKey</code>. If the two digest values are
* different, throw an exception.
*/
md.update(passwdBytes);
Arrays.fill(passwdBytes, (byte)0x00);
passwdBytes = null;
md.update(plainKey);
digest = md.digest();
md.reset();
for (i = 0; i < digest.length; i++) {
if (digest[i] != protectedKey[SALT_LEN + encrKeyLen + i]) {
throw new UnrecoverableKeyException("Cannot recover key");
}
}
似乎在给定密码进行哈希处理并与passwdBytes变量进行比较时,它会得到不同的结果,因此会抛出错误。我不确定得到这个结果我做错了什么?