Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MEID transformation to ESN (mobile equipment identifier)

Status
Not open for further replies.

puntito

Programmer
Mar 22, 2006
18
I have this information ...

For nearly two decades, electronic serial numbers (ESN) have served CDMA and other wireless technologies well, providing a mechanism to uniquely identify each mobile device. But just as IP address pool depletion is leading the change from IPv4 to IPv6, the impending exhaustion of available ESNs necessitates a replacement. That replacement is the mobile equipment identifier (MEID).

This page, provide more info.

My Question is, I have to transform de MEID to a psedi ESN (electronic Serial Number), but I cant find a way to do it.

I have this code

Code:
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();
		    }

public static String SHA1(String text)
		    throws NoSuchAlgorithmException, UnsupportedEncodingException  {
		        MessageDigest md;
		        md = MessageDigest.getInstance("SHA-1");
		        byte[] sha1hash = new byte[20];
		        md.update(text.getBytes("iso-8859-1"),  0, text.length());
		        sha1hash = md.digest();
		        String yy =convertToHex(sha1hash);
		        
		        //return yy;
		        return convertirlo(yy);
		    }

		    public static String convertirlo(String toHex){
		    	String x = toHex;
		        //String y = x.substring(0,6);
		        String y = x.substring(x.length()-6,x.length());
		        
		        byte[] bait = new byte[20];
		    	try {
					bait = y.getBytes("iso-8859-1");
				} catch (UnsupportedEncodingException e) {
					// TODO Bloque catch generado automáticamente
					e.printStackTrace();
				}

				x = convertToHex(bait);
				return y;
		    
		    }

to Execute: cad = ConvierteExaDec.SHA1("FF000001123456");


------------------------
I was told that I have to take a 56 bit hex number (MEID) and convert it to a 32 bit hex number (pESN).
The end result should look like this..
*The upper 8 bits of pseudo-ESN shall be set to 0x80.
* The lower 24 bits of pseudo-ESN shall be the 24 least significant bits of the SHA-1 digest of the MEID.
So the pESN should be 80 XX XX XX.

An example is this..
Example:
if the 56-bit MEID is (hexadecimal) FF 00 00 01 12 34 56, the pseudo-ESN is (hexadecimal) 80 07 37 E1.
I can't get this to compute..

So I need to get the 24 least significant bits and convert it to hex and some how it'll equal 07 37 E1.

Somebody could help me please !!
I hope I could explain me well!!!!!
 
Sorry, the String result that I obtain is 9894af3b8638b3e14d7313c726ccddd9319124e
nothing compare to .... 07 37 E1
 
Well, a few weeks later, I found a solution !!!!
The point was to send the data in the correct format to the digest, just like this:

Code:
public static String SHA1(String text)
    throws NoSuchAlgorithmException, UnsupportedEncodingException  {
		 
        MessageDigest md;
        md = MessageDigest.getInstance("SHA-1");
        byte[] sha1hash = new byte[20];
        sha1hash = md.digest(HexBin.decode(text));      
        String yy =convertToHex(sha1hash);
        return yy;

    }
Because, I receive the data like a String, from the html page, so, I have to tell the digest that this is a hexadecimal value, so I use HexBin.decode(text)
then transform the digest result into hexadecomal value:

Code:
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();
    }

And now I have the correct result.
From A0000000002329
to e3be267a2cd5c861f3c7ea4224df829a3551f1ab
and taking the 24 least significant bits 51 f1 ab

From FF000001123456
to ffce4beab4c2a7933c0d6d21b21cf21a0e0737e1
and taking the 24 least significant bits 07 37 e1

Hope this'll be useful for somebody.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top