Welcome! Log In Create A New Profile

Advanced

Re: Enquiry regarding Sticky Module's hash functions

All files from this thread

File Name File Size   Posted by Date  
1.9 KB open | download Stephan Wolfauer 06/16/2011 Read message
1.1 KB open | download Stephan Wolfauer 06/16/2011 Read message
1.9 KB open | download Dalibor Jotanovic 06/16/2011 Read message
1.1 KB open | download Dalibor Jotanovic 06/16/2011 Read message
1.9 KB open | download Dalibor Jotanovic 06/16/2011 Read message
1.1 KB open | download Dalibor Jotanovic 06/16/2011 Read message
1.9 KB open | download Dalibor Jotanovic 06/16/2011 Read message
1.1 KB open | download Dalibor Jotanovic 06/16/2011 Read message
1.9 KB open | download Dalibor Jotanovic 06/16/2011 Read message
1.1 KB open | download Dalibor Jotanovic 06/16/2011 Read message
October 06, 2011 04:37PM
Merci Jérôme, we resolved the solution by writing the following class. It's not super but does the job:

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class IPEncryptor
{

public static String MD5(String ip)
throws NoSuchAlgorithmException, UnsupportedEncodingException
{
MessageDigest md;
md = MessageDigest.getInstance("MD5");

byte[] md5hash = new byte[32];
byte[] ipParts = parseIP(ip);

md.update(ipParts, 0, ipParts.length);

md5hash = md.digest();
return convertToHex(md5hash);
}


private static String convertToHex(byte[] data)
{
StringBuffer buf = new StringBuffer();

for (int i = 0; i < data.length; i++)
{
int halfbyte = (data[i] >>> 4) & 0x0F;
int two_halfs = 0;
do
{
if ((0 <= halfbyte) && (halfbyte <= 9))
buf.append((char) ('0' + halfbyte));
else
buf.append((char) ('a' + (halfbyte - 10)));
halfbyte = data[i] & 0x0F;
} while(two_halfs++ < 1);
}

return buf.toString();
}

// Parses the input
private static byte[] parseIP(String address)
{
String[] addressParts = address.split(":");

String[] ipParts = addressParts[0].split("\\.");
int portHiByte = Integer.parseInt(addressParts[1]) / 256;
int portLoByte = Integer.parseInt(addressParts[1]) % 256;

int i = 0;
int j = 0;

byte[] ip = new byte[16];
ip[i++] = 0;
ip[i++] = 2;
ip[i++] = (byte)portHiByte;
ip[i++] = (byte)portLoByte;

for (j = 0; j < ipParts.length; j++, i++)
{
ip[i] = (byte)Integer.parseInt(ipParts[j]);
}

// pad the rest with ZEROs
for (; i < ip.length; ++i)
{
ip[i] = 0;
}

return ip;
}
}
Subject Author Posted

nginx sticky module compile error Attachments

Stephan Wolfauer June 16, 2011 03:58AM

Re: nginx sticky module compile error

Maxim Dounin June 16, 2011 04:00AM

Antw: Re: nginx sticky module compile error Attachments

Dalibor Jotanovic June 16, 2011 04:34AM

Re: Antw: Re: nginx sticky module compile error

Maxim Dounin June 16, 2011 05:46AM

Re: Antw: Re: nginx sticky module compile error Attachments

Dalibor Jotanovic June 16, 2011 06:02AM

Re: Antw: Re: nginx sticky module compile error

Maxim Dounin June 16, 2011 06:18AM

Re: Antw: Re: nginx sticky module compile error Attachments

Dalibor Jotanovic June 16, 2011 07:00AM

Re: Antw: Re: nginx sticky module compile error Attachments

Dalibor Jotanovic June 16, 2011 07:22AM

Re: Antw: Re: nginx sticky module compile error

Jérôme Loyet June 16, 2011 02:30PM

Re: Antw: Re: nginx sticky module compile error

Maxim Dounin June 16, 2011 03:48PM

Enquiry regarding Sticky Module's hash functions

ramindeja October 06, 2011 12:31PM

Re: Enquiry regarding Sticky Module's hash functions

Jérôme Loyet October 06, 2011 12:40PM

Re: Enquiry regarding Sticky Module's hash functions

ramindeja October 06, 2011 04:37PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 106
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready