SAML2.0断言解密

时间:2013-04-28 01:08:52

标签: java saml-2.0

我正在尝试在我的学校中将Java Web App与deploied IdP集成。 IdP已经配置好,我发出请求,一切都很好,除了一个。我无法解密IdP回复。

Here you can find the response that I receive after a login

我有一个public_key.crt和一个private_key.pem。 我已经解密了IdP响应中的symetric密钥,该密钥是用我的public_key.crt加密的。之后我得到一个256字节的数组,我认为它是一个AES-256密码,但IdP响应只讨论AES-128-CBC。不过我尝试创建一个Java AES对象来解密SAML断言,但我总是得到错误:无效的AES密钥长度:256字节

以下是代码:

    PrivateKey privKey = ...; // PrivateKey constructed with my private_key.pem file
    System.out.println(privKey); // To show private_key.pem info

    // you can find these two strings on IdP Response, from link above 
    String encAssertion = "5vdtxDD01BUFa438J5EUTebql8Fzf72e39OdBSYd3dcM8RIAdkzKftKhpk5sTU/Ui9swFMbTrL1ptpxUvPa2756yOfqA75eeRdUne939GqYFJUz5ppUY/oHToE06AcGCIxIjG6l8l1a31PwUhkF9LVp9ZK8URF2AGTRvq5R20fcgoIjQBd/tSA6BhQCGx5sa5OEOAGV0blRZlxy9yoPiWn+YdNKCQVtioRrXb5mHL/nFatKmwvoCIw5yVSxcc7BNjlSmUh2cQ86wdRY/ur84k/1D948X5hOJItXAkw70iIVNdE/mwbrjtqssEXHHP46i7YauY27jQ4QSSWXlF93z8mYPAGatUY6q42ZXzrft0tRKg0CjLDTMZfxyCJhZUpjvRx/2y4VxvjBKIOUSwGlhm/BPkt9yV9cge4I3u2DZuqXMP3Gh+cPF3InzA+nTh826owq/cKTNL79h1MSzKK0447nbaBubygcA9E7BOEmwxHvjdySXqGk2m4h1LyRyZjiNq15GphJM1EOjWV6EpC18e7d4FxJjRQ/B5HmXkI/tLJ5BdDxc1Qasqlu7ESIFxmkYKC8YMaBcTLisCe7CVJePg8zUIpPS/pMlm0e/18QW7CHXllGTy63WUZpQtXX2v/rQpz8TdpKkQQUNcAqCD+NDuq3hnWPUEnLVoKstykLkXDY3299k2kXRbsRgvLfCS3v5Gr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QQIomLDpcbo7RQ7bZ/92dnwSEP9IJ5vYlFlcuKAehXRqD/LXNW+7fgmmO85e3JlkGbhD9CAD1wa4/aTH8r7gilNRIZyr80BBKWA6+BMYq7VX68H98Jo7DxSvQwMCyJx/wY3smLGK4f/HNDGCXPPcxW9wH32gWqPkXeNh1SbEdf6xfTAH4vRhno/6RUrmQa7TycPtHE59VHPEUK4d3QmqO9u2vElJyAtsgDYNA3n/4i/kg1fr94KFeAfNkkWATnD809KvR3pEyx2kmRRRXWEEE7ztevb8Pfc3FARRGIvOGw29ROiO1nW7t662wYQROyIXP2Dcfz0SFlRdxHsF5wzuUj9XNTUaIStbIrj0+1yWxixvk6mqkhthAnbWFIpqHyfNPxe+dC2ipVBsoYwibn44u9sH5TQ/HlwEy7C8=";
    String encryptedKey = "qJNLI5UNAVSVwRCI8EHSa5GuhFAxPi9VZleCCrriLHSXWHf79RDG6ocU7slHZaf8zvIc2su41iJsZeb3xXOsg73xbJ2vLOWW5GQCRh97OxFmbd2M0UkYMM57g2YmDlPjTo7L75GrX2LmmL1ko47QmCb60b0um2m6RGNdj32QUIGArUM4TUdamSi0a8+bThe565OUkS25OfrT02z1er1m+VprUa5SPwqLXRqmg9dknCX8pIi5vrD02bRrKP5b+a6FTA77ocOFtYgzPQWPYfAU5jFledHRJA3phwsm7yOFvyjOeWtOVCAKmoYALJ+5rdxnkMGr/SGaI3jjNup7WQJxtw==";

    Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding");
    cipher.init(Cipher.DECRYPT_MODE, privKey);
    byte[] decrypt = cipher.doFinal(Base64.decodeBase64(encryptedKey));

    System.out.println("Decrypted Key length: " + decrypt.length); // Decrypted Key length: 256
    System.out.println(new String(decrypt, "UTF-8")); // Some stupid chars

    SecretKey skeySpec = new SecretKeySpec(decrypt, "AES");

    cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    // cipher = Cipher.getInstance("AES/CBC/NoPadding");
    // cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.DECRYPT_MODE, (Key) skeySpec);
    byte[] decryptedAssertion = cipher.doFinal(encAssertion.getBytes());

最后一行发生错误。 AES密钥长度无效:256字节

0 个答案:

没有答案