我有一个PHP函数,它使用saml / xml编码字符串作为内容:
function encodeSamlRequest($samlRequest) {
return addslashes(rawurlencode(base64_encode(gzdeflate($samlRequest))));
}
我创建了可以产生相同输出的Java方法:
private String encodeRequest(String samlRequest) {
byte[] samlRequestBytes = samlRequest.getBytes();
// gzdeflate
Deflater compressor = new Deflater();
compressor.deflate(samlRequestBytes);
// base64_encode
byte[] encodedDeflatedSamlRequest = Base64.getEncoder().encode(samlRequestBytes);
// rawurlenccode
String encodedSamlRequest = null;
try {
encodedSamlRequest = URLEncoder.encode(new String(encodedDeflatedSamlRequest), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return encodedSamlRequest;
}
private byte[] toByteArray(int value) {
return new byte[]{
(byte) (value >> 24),
(byte) (value >> 16),
(byte) (value >> 8),
(byte) value};
}
我尝试使用Deflater,Base64.Encoder,URIEncoder和URI类(最后两个没有网址,因为我的声誉< 10),但输出完全不同。
测试输入:
<samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="_e48eec122b20b6b83702" Version="2.0" IssueInstant="2017-09-28T13:54:16Z" Destination="https://hetman-int.epuap.gov.pl/DracoEngine2/draco.jsf" IsPassive="false" AssertionConsumerServiceURL="http://localhost:8085/index.jsp"><saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">/test12/myapp-12423534</saml:Issuer></samlp:AuthnRequest>
预期产出:
fVHJbsIwEP2VyPfEiRMgtUgkVHpAolIFLYdeKhMG4ioZux4H0b%2BvA6pELz3O8pZ5MyfVd1YuBt%2FiBr4GIB9d%2Bg5JXgcVGxxKo0iTRNUDSd%2FI7eJ5LUWSSuuMN43pWLRaVuwDihKgyYTYi3Q%2F3Zf5LBUs2oEjbbBiAREWiQZYIXmFPrTSbBanD7EoX7NcTgqZTd9ZtAwmNCp%2FRbXeW5Kct%2BB7hbFGn4AdlE1O5pzYji%2BdaswTnjSC4IexSD7pOAq9KCJ9hoodVUfAogURuJH00SANPbgtuLNu4G2zvskElc40qmsNeVmm5YRrPMAl8FlWz8c85NW%2Bu0vo%2F4DUrySruQ9XZYL338raOBOFyCd5Med3tPWt%2BvuN%2Bgc%3D
我的输出:
eJxhbWxwOkF1dGhuUmVxdWVzdCB4bWxuczpzYW1scD0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOnByb3RvY29sIiBJRD0iX2U0OGVlYzEyMmIyMGI2YjgzNzAyIiBWZXJzaW9uPSIyLjAiIElzc3VlSW5zdGFudD0iMjAxNy0wOS0yOFQxMzo1NDoxNloiIERlc3RpbmF0aW9uPSJodHRwczovL2hldG1hbi1pbnQuZXB1YXAuZ292LnBsL0RyYWNvRW5naW5lMi9kcmFjby5qc2YiIElzUGFzc2l2ZT0iZmFsc2UiIEFzc2VydGlvbkNvbnN1bWVyU2VydmljZVVSTD0iaHR0cDovL2xvY2FsaG9zdDo4MDg1L3N1Y2Nlc3MuanNwIj48c2FtbDpJc3N1ZXIgeG1sbnM6c2FtbD0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOmFzc2VydGlvbiI%2BL3Rlc3Rwbi9Eb215nGxuYS0xNDk2MDM0NjAyOTA5PC9zYW1sOklzc3Vlcj48L3NhbWxwOkF1dGhuUmVxdWVzdD4%3D
任何建议或想法?谢谢你的帮助。