burncd Posted November 16, 2009 at 06:45 PM Report Share #296513 Posted November 16, 2009 at 06:45 PM Boa Noite pessoal. Encontrei o vosso forum de programação e pareceu-me o mais indicado apara colocar a minha duvida. Estou a desenvolver uma aplicação de cliente servidor, em que o servidor encontra-se em C#.Net e o cliente em java, e o objectivo é a troca de Chaves publicas dos algoritmos para depois estabelecer uma ligação segura entre ambos para realizar troca de comandos. A parte de enviar comandos do cliente para o servidor encontra-se feita e a funcionar a 100%. O problema vem quando é para realizar a troca de chaves publicas dos algoritmo RSA entre ambos. Consigo enviar a stream com as chaves para ambos os lados, e parece-me que ambas estão feitas de forma correcta. Mas o servidor quando tento criar o algoritmo rsa a partir de uma XmlString diz-me o seguinte erro: (protocol.GetStringFromData()) “The input is not a valid base-64 string as it contains a non-base 64 character, more the 2 padding characters, or a non-white space character among the padding characters.” O conteúdo que o servidor está a receber é o seguinte: <?xml version="1.0" encoding="UTF-8" standalone="no"?><RSAKeyvalue><Modulus>AIKTJ+GUABnqQ422G7nmMdVyy38smuWFzrwlZ3mmdg5nqNeDPp76Vst/yNiddLc4Xpsi2AqbyKTm +RfOEDER2up05p6EVMluwg26io5/4IeVzZhWXff9BKHmY0YmmQqsN9uuJYch7Jy6pbGuY7k6B+uF i1xRIGoJ1zmobibslF8f</Modulus><Exponent>AQAB</Exponent></RSAKeyvalue> O codigo gerado a partir das seguintes instruções em Java: public static String getRSAPublicKeyAsXMLString(RSAPublicKey key) throws UnsupportedEncodingException, ParserConfigurationException, TransformerException, SAXException, IOException { Document xml = getRSAPublicKeyAsXML(key); Transformer transformer = TransformerFactory.newInstance().newTransformer(); StringWriter sw = new StringWriter(); transformer.transform(new DOMSource(xml), new StreamResult(sw)); return sw.getBuffer().toString(); } public static Document getRSAPublicKeyAsXML(RSAPublicKey key) throws ParserConfigurationException, SAXException, IOException { Document result = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element rsaKeyValue = result.createElement("RSAKeyvalue"); result.appendChild(rsaKeyValue); Element modulus = result.createElement("Modulus"); rsaKeyValue.appendChild(modulus); byte[] modulusBytes = key.getModulus().toByteArray(); //modulusBytes = stripLeadingZeros(modulusBytes); System.out.println("Modulus: " + new String(modulusBytes)); modulus.appendChild(result.createTextNode(new String(new sun.misc.BASE64Encoder().encode(modulusBytes)))); Element exponent = result.createElement("Exponent"); rsaKeyValue.appendChild(exponent); byte[] exponentBytes = key.getPublicExponent().toByteArray(); //exponentBytes = stripLeadingZeros(exponentBytes); System.out.println("Exponent: " + new String(exponentBytes)); exponent.appendChild(result.createTextNode(new String(new sun.misc.BASE64Encoder().encode(exponentBytes)))); return result; } Não consigo obter o algoritmo do lado do servidor para poder continuar com a resolução do problema. Será que me podiam ajudar? Desculpem se alguma informação está mal explicada. Obrigado pela atenção, Burncd Link to comment Share on other sites More sharing options...
burncd Posted November 24, 2009 at 02:15 PM Author Report Share #297403 Posted November 24, 2009 at 02:15 PM Problema resolvido. 😄 Link to comment Share on other sites More sharing options...
bruno1234 Posted November 24, 2009 at 09:19 PM Report Share #297461 Posted November 24, 2009 at 09:19 PM Coloca a solução, para quem tiver a mesma dúvida. Matraquilhos para Android. Gratuito na Play Store. https://play.google.com/store/apps/details?id=pt.bca.matraquilhos Link to comment Share on other sites More sharing options...
burncd Posted November 25, 2009 at 11:57 AM Author Report Share #297512 Posted November 25, 2009 at 11:57 AM O código não é muito necessário, pois a diferença está em em vez de criar o XML do lado do java, basta enviar os dados do da chave publica em BASE64Encoder(), ou seja, enviar o Modulus e a Exponent a parte para o .NET e criar o XML do lado do .NET. Mas se quiserem posso postar mais tarde o código, pois ainda não o tenho funcional mas foi assim que um dos meus colegas de trabalho conseguiu. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now