【发布时间】:2020-03-26 17:58:37
【问题描述】:
我正在使用充气机解压缩 SAMLRequest。由于这个值是用 GZIP 压缩的,我设法将“true”传递给 inflater 构造函数,以提供与这种格式的兼容性。但是,膨胀的行会引发 DataFormatException。
private String decodeMessage(String SAMLContent) {
try {
//URLDecode, Base64 and inflate data
//URLDecode
SAMLContent = URLDecoder.decode(SAMLContent, "UTF-8");
//Base64 decoding
byte[] decode = Base64.getDecoder().decode(SAMLContent);
SAMLContent = new String(decode, "UTF-8");
//SAMLContent = new String(Base64.getDecoder().decode(SAMLContent), "UTF-8");
//Inflating data
try {
byte[] inflated = new byte[(10 * SAMLContent.getBytes("UTF-8").length)];
Inflater i = new Inflater(true);
i.setInput(SAMLContent.getBytes("UTF-8"), 0, SAMLContent.getBytes("UTF-8").length);
//The following line throws DFException
int finalSize = i.inflate(inflated);
SAMLContent = new String(SAMLContent.getBytes("UTF-8"), 0, finalSize, "UTF-8");
i.end();
} catch (DataFormatException ex) {
JOptionPane.showMessageDialog(null, "DFE: " + ex.getMessage()); //Returns "invalid code length set"
}
} catch (UnsupportedEncodingException ex) {
JOptionPane.showMessageDialog(null, "UEE: " + ex.getMessage());
}
return SAMLContent;
}
在第 20 行引发了异常。我尝试复制的工作流是
- 复制请求的值 (This one for instance)
- 使用this URL decoder to decode it(左下角的文本框)
- 将第二步的结果粘贴到这个Base64decoder + inflater中以获得原始XML,如最后一页的第三个文本框所示。
【问题讨论】:
-
因为这是一个简单的步骤,而且目前是我唯一需要的函数,所以我想在不使用外部库的情况下编写它。我正在使用工作算法添加答案。但是,如果需要,我一定会记住 OpenSAML。谢谢。