예제 #1
0
        public void should_get_xml_contains_essential_nodes_after_encrypt_and_sign()
        {
            string result = AlipaySignature.EncryptAndSign("test", TestAccount.Sandbox.AlipayPublicKey,
                                                           TestAccount.Sandbox.AppPrivateKey, "UTF-8", true, true, "RSA2", false);

            Assert.AreEqual(result.Contains("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"), true);
            Assert.AreEqual(result.Contains("<alipay>"), true);
            Assert.AreEqual(result.Contains("<response>"), true);
            Assert.AreEqual(result.Contains("<encryption_type>RSA2</encryption_type>"), true);
            Assert.AreEqual(result.Contains("<sign>"), true);
        }
예제 #2
0
        public static void EncryptAndSign()
        {
            // 参数构建
            string bizContent = "<XML><ToUserId><![CDATA[2088102122494786]]></ToUserId><AppId><![CDATA[2013111100036093]]></AppId><AgreementId><![CDATA[20131111000001895078]]></AgreementId>"
                                + "<CreateTime>12334349884</CreateTime>"
                                + "<MsgType><![CDATA[image-text]]></MsgType>"
                                + "<ArticleCount>1</ArticleCount>"
                                + "<Articles>"
                                + "<Item>"
                                + "<Title><![CDATA[[回复测试加密解密]]></Title>"
                                + "<Desc><![CDATA[测试加密解密]]></Desc>"
                                + "<Url><![CDATA[http://m.taobao.com]]></Url>"
                                + "<ActionName><![CDATA[立即前往]]></ActionName>"
                                + "</Item>"
                                + "</Articles>" + "<Push><![CDATA[false]]></Push>" + "</XML>";
            string publicKeyPem    = GetCurrentPath() + "public-key.pem";
            string privateKeyPem   = GetCurrentPath() + "aop-sandbox-RSA-private-c#.pem";
            string responseContent = AlipaySignature.EncryptAndSign(bizContent, publicKeyPem, privateKeyPem, "UTF-8", true, true);

            System.Console.Write("resultContent=" + responseContent + "\n\r");
        }