Saml 2.0 request encoding

风流意气都作罢 提交于 2019-12-12 03:29:37

问题


I'm trying to encode a Saml 2.0 request in Java but when i decode it using tools online i get weird characters.

This is the input string:

<samlp:AuthnRequest 
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" 
ID="_8d7bd828-6f91-477a-b158-22d693f56972" 
Version="2.0" 
IssueInstant="2013-04-19T14:07:53Z" 
AssertionConsumerServiceURL="http://test">
<saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
test
</saml:Issuer>
<samlp:NameIDPolicy 
Format="urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified" 
AllowCreate="true" />
</samlp:AuthnRequest>

Here's the code I'm using:

byte[] xmlBytes = baos.toByteArray();

//Deflate
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(
                                                byteOutputStream);
try {
    deflaterOutputStream.write(xmlBytes, 0, xmlBytes.length);
    deflaterOutputStream.close();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

//BASE64 encode
Base64 base64Encoder = new Base64();
byte[] base64EncodedByteArray = base64Encoder.encode(xmlBytes);
String base64EncodedMessage = new String(base64EncodedByteArray);

// URL encode
String urlEncodedMessage = null;
try {
    urlEncodedMessage = URLEncoder.encode(base64EncodedMessage,"utf-8");
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
}
return urlEncodedMessage;

When i run the resulting string through the online decoding tools i get the following result:

x?}?Mk?@??J????ILL@??`?0??^"??B???Gm?}W?`/^?03????,,­????
?=Z}??pT??[iA?-8??q
?I
??N
?h???GYN?\pZ?"?Y:??Pt9mS??<-D?$zCc?V                 
Ah?A??+Zq??8??|?d??$ZZ???J+?4
?/)?u????Kf?d>9??2.cf?-X?<?&??zq?K??A?O???ImZ??`76W???n?~???6
w?m?????
^???$????ie?;??3-I??k??7????Srtion">
test
</saml:Issuer>
<samlp:NameIDPolicy 
Format="urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified" 
AllowCreate="true" />
</samlp:AuthnRequest>

回答1:


You need to use URL decoder first and then Base64 decoder, is that what you are doing?



来源:https://stackoverflow.com/questions/16105477/saml-2-0-request-encoding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!