|    
			
				06/04/2011, 07:06
			
			
			  | 
  |   |  |  |  Fecha de Ingreso: marzo-2010 
						Mensajes: 5
					 Antigüedad: 15 años, 7 meses Puntos: 0 |  | 
  |  Respuesta: GetResponsebody o getInputStream con Digest authorization y encriptacion m  
  He encontrado la solución para la autenticación md5-sess
 * Primer paso: Calcular el nonce y el realm con una petición:
 
 HttpClient client = new HttpClient();
 GetMethod getMethod = new GetMethod(host+urlStr+parameters);
 client.executeMethod(getMethod);
 Header wwAuthHeader = getMethod.getResponseHeader("WWW-Authenticate");
 for (HeaderElement element : wwAuthHeader.getElements())
 {
 if(element.getName().equals("nonce"))
 nonce = element.getValue();
 if(element.getName().equals("realm"))
 realm = element.getValue();
 }
 
 
 *Segundo paso: Calcular el response:
 
 String user = "usuario";
 String password = "contrasenia";
 String cnonce = "inventado";
 String nc = "00000001";
 String qop = "auth";
 String A1 = MD5Encrypt(user+":"+realm+":"+password)+":"+nonce+  ":"+cnonce;
 String response = MD5Encrypt(MD5Encrypt(A1)+":"+nonce+":"+nc+":"+cno  nce+":"+qop+":"+ MD5Encrypt("GET:"+urlStr));
 
 * La función MD5Encrypt hace lo siguiente:
 private String MD5Encrypt(String text)
 {
 try
 {
 byte b[] = java.security.MessageDigest.getInstance("MD5").dig  est((text).getBytes());
 java.math.BigInteger bi = new java.math.BigInteger(1,b);
 String s = bi.toString(16);
 while(s.length() < 32)
 s="0"+s;
 return s;
 }
 catch(Exception e)
 {
 e.printStackTrace();
 }
 }
 
 
 * Tercer paso: Realizar la peticion y salvarla en un xml (por ejemplo):
 
 URL url = new URL(urlStr);
 URLConnection urlCon = url.openConnection();
 String header = "username=\""+user+"\",realm=\""+realm+"\",nonce=\  ""+nonce+"\",uri=\""+urlStr+"\",cnonce=\""+cnonce+  "\",nc="+nc+",algorithm=MD5-sess,response=\""+response+"\",qop=\""+qop+"\",cha  rset=utf-8";
 urlCon.setRequestProperty("Authorization", "Digest "+header);
 
 InputStream is = urlCon.getInputStream();
 FileOutputStream fos = new FileOutputStream("C:/temp.xml");
 
 byte[] array = new byte[1000];
 int step = is.read(array);
 while (step > 0)
 {
 fos.write(array, 0, step);
 step = is.read(array);
 }
 is.close();
 fos.close();
 
 
 * Ahora mi problema es: ¿Cómo puedo evitar el prompt de IE para poder realizar mi código que muestro arriba?
     |