我有下一個麻煩。 在數據庫日期從日期存儲爲md5。當我在JAVA中使用同一日期的md5時,我有另一個散列。 例如:日期 - 1980年1月2日的java 哈希addaf0f9a1fb3699871293f888f6e46e(與從字符串預言MD5散列) oracle的散列是DF0919EA828A77DC2CCF68474ED703AC如何在JAVA中從日期獲得md5總和,例如在oracle中?
我試圖重複oracle的結果在Java:
System.out.println(streamConvertor.getHash("01.02.1980", Boolean.TRUE));
System.out.println("");
System.out.println(streamConvertor.getHash("01.02.1980", Boolean.FALSE));
public String getMD5(String input, Boolean is_date) throws ParseException {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] mdinput;
Boolean pr;
if (input.equals("01.02.1980")) {
pr = true;
} else {
pr = false;
}
if (is_date == Boolean.TRUE) {
SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy");
Date day = df.parse(input);
mdinput = df.format(day).getBytes();
} else {
mdinput = input.getBytes();
}
if (pr == Boolean.TRUE) {
System.out.println("Is date " + is_date + " - " + mdinput);
}
byte[] messageDigest = md.digest(mdinput);
if (pr == Boolean.TRUE) {
System.out.println("message - " + messageDigest);
}
BigInteger number = new BigInteger(1, messageDigest);
if (pr == Boolean.TRUE) {
System.out.println("Number - " + number);
}
String hashtext = number.toString(16);
// Now we need to zero pad it if you actually want the full 32 chars.
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}
if (pr == Boolean.TRUE) {
System.out.println("hashtext - " + hashtext);
}
return hashtext;
}
catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
和輸出是不同的,但直到字節[]轉換爲BigInteger的:
Is date true - [[email protected]
message - [[email protected]
Number - 231093251542199165689934828427325924462
hashtext - addaf0f9a1fb3699871293f888f6e46e
Is date false - [[email protected]
message - [[email protected]
Number - 231093251542199165689934828427325924462
hashtext - addaf0f9a1fb3699871293f888f6e46e
是否有任何可能使MD5哈希如在Oracle?
你在Oracle中做什麼以獲得你的日期的MD5哈希值? –
存儲在bd中的日期被如此散列化 select DBMS_CRYPTO.hash(UTL_RAW.CAST_TO_RAW(UPPER(to_date('01.02.0480','dd.mm.yyyy'))),2)from dual; – Leonid
首頁,你是對的我認爲 – Leonid