Windows IAP Verify RRS feed

  • 问题

  • Hi,

    About Windows IAP receipt verify, I found this document:


    But this document code is .NET(C#), my server is written by Java, I test a lot way to verify this, but failed, I paste my Java logic code and hope someone can help me solve it.

    public static boolean verifyReceipt(String _receiptXml){
    			DocumentBuilderFactory t_factory = DocumentBuilderFactory.newInstance();
    			DocumentBuilder builder = t_factory.newDocumentBuilder();
    			Document t_doc 		= builder.parse(new InputSource(new StringReader(_receiptXml)));
    			PublicKey t_pubKey	= getPublicKey(t_doc.getDocumentElement().getAttribute("CertificateId"));
    			// TODO improve following method to verfy
    			// we cannot use this function to verify
    			NodeList nl = t_doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
    			DOMValidateContext valContext = new DOMValidateContext(t_pubKey,nl.item(0));
    			XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");
    			XMLSignature signature = fac.unmarshalXMLSignature(valContext);
    			return signature.validate(valContext);
    		}catch (Exception e){
    			log.error("verify error \n {} \n {}",_receiptXml,e);
    			return false;
    	private static PublicKey getPublicKey(String _certificateId)throws Exception{
    		PostParameter[] t_params =
    			new PostParameter("LinkId", "246509"),
    			new PostParameter("cid",URLEncoder.encode(_certificateId, "UTF-8")),
    		String t_result = PostAnswer.requestURL("https://go.microsoft.com/fwlink/", "GET", null, t_params,true);
    		CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
    		return certificateFactory.generateCertificate(new ByteArrayInputStream(t_result.getBytes("UTF-8"))).getPublicKey();

    2016年3月9日 3:11


  • Hello yuchgame,

    After reading that C# code you may know that the code is about how to validate your xml file use Algorithm. However, since you want to do the same thing within java code. MSDN forum is not the right forum. Please switch to post your question to Java related forum to consult this issue.

    Thanks for your understanding.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2016年3月10日 1:54