誰でも次のコードが常に同じハッシュを返さない理由を教えていただけますか?ハッシュは異なる可能性が唯一の方法は、ランダムな塩によるものですが、マニュアルに従って、私はあなたのバグがそのあなたという事実に関連している0sha-256がsaltを使わずに常に同じハッシュを返すとは限りません
public static void main(String[] args) {
char[] password = "test_pass".toCharArray();
String str = encodePassword(password);
System.out.printf(
"Byte digest '%s'\n",
String.valueOf(Hex.encodeHex(Base64.decodeBase64(str)))
);
}
static StandardByteDigester digester = new StandardByteDigester();
{
digester.setAlgorithm("SHA-256");
digester.setIterations(100000);
digester.setSaltSizeBytes(0);
digester.initialize();
}
public static String encodePassword(char[] rawPass) {
return new String(Base64.encodeBase64(digester.digest(toBytes(rawPass))));
}
public static byte[] toBytes(char[] ch) {
Charset charset = Charset.defaultCharset();
ByteBuffer buff = charset.encode(CharBuffer.wrap(ch));
byte[] tmp = new byte[buff.limit()];
buff.get(tmp);
return tmp;
}
jasyptのどのバージョンをお使いですか? – Asoub