Delphi and Java are generate totally different values.
I have MD5 list and I need to encode them with Base64 then URLEncode.
Here is the delphi and java output of the same hash values.
How can I get same as Java output with Delphi?
MD5 Input Value:
BB8C890E3E6372F2720709262BD42BF4
Java Base64 Encoded Output Value :
vIRYPbGf3toJDQehgv3SOamnTNk=
Delphi Base64 Encoded Output Value:
QkI4Qzg5MEUzRTYzNzJGMjcyMDcwOTI2MkJENDJCRjQ=
The delphi code line is:
IdEncoderMIME1.EncodeString('BB8C890E3E6372F2720709262BD42BF4');
And the Java Source is:
String md5 = new String(Base64.encodeBase64(decodedHex));
Full Java Code (That I want to have same results with Delphi): public static void main(String[] args) throws Exception { if ( args.length != 8 ) { usage(); return; }
WebClient webClient = null;
try
{
byte[] decodedHex = Hex.decodeHex(args[0].toCharArray());
String sha1 = new String(Base64.encodeBase64(decodedHex));
decodedHex = Hex.decodeHex(args[1].toCharArray());
String md5 = new String(Base64.encodeBase64(decodedHex));
String rep = args[2];
String comment = args[3];
String Server = args[4];
String ServerPort = args[5];
String username = args[6];
String password = args[7];
String params = "[{\"sha1\":\"" + sha1 + "\",\"md5\":\"" + md5 + "\",\"rep\":\"" + rep + "\",\"comment\":\"" + comment + "\"}]";
// Note the usage of URLEncoder to ensure special characters can be used within the parameters.
String url = "https://" + Server + ":" + ServerPort + "/setRep?fileReps=" + URLEncoder.encode(params, "UTF-8");
System.out.println("\nWeb API params with Base64 values but are not yet URL encoded:");
System.out.println("\n" + params + "\n");
System.out.println("\nWeb API URL call with URL encoded parameters:");
System.out.println("\n" + url + "\n");
webClient = new WebClient(BrowserVersion.FIREFOX_24);
webClient.getOptions().setUseInsecureSSL(true);
DefaultCredentialsProvider userCredentials = (DefaultCredentialsProvider)webClient.getCredentialsProvider();
userCredentials.addCredentials(username, password);
webClient.setCredentialsProvider(userCredentials);
Page setFileRepResponsePage = webClient.getPage(url);
String pageResponse = setFileRepResponsePage.getWebResponse().getContentAsString();
System.out.println("HTTP Status code: " + setFileRepResponsePage.getWebResponse().getStatusCode());
System.out.println(pageResponse);
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
try
{
webClient.closeAllWindows();
}
catch(Exception ex) {}
}
}