日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

本文介紹了SAML加密的Assertion解密失敗的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用SAML實現SP。當我嘗試解密EncryptedAssertion時,收到以下錯誤。

org.opensaml.xml.encryption.DecryptionException: Failed to decrypt EncryptedData
at org.opensaml.xml.encryption.Decrypter.decryptDataToDOM(Decrypter.java:546)
at org.opensaml.xml.encryption.Decrypter.decryptDataToList(Decrypter.java:453)
at org.opensaml.xml.encryption.Decrypter.decryptData(Decrypter.java:414)
at org.opensaml.saml2.encryption.Decrypter.decryptData(Decrypter.java:141)
at org.opensaml.saml2.encryption.Decrypter.decrypt(Decrypter.java:69)

我尋找了這個錯誤,但沒有找到太多。
我還更新了我的JCE JAR。我正在使用opensaml

我能夠獲得SAML響應,并且能夠驗證/驗證簽名。
在解密斷言的時候,我得到了上面的錯誤。

代碼詳細信息

//迭代加密的斷言

List<EncryptedAssertion> encryptedAssertions = response.getEncryptedAssertions();
    if (encryptedAssertions.size() > 0) {
        for (EncryptedAssertion encryptedAssertion : encryptedAssertions) {
            Assertion assertion = decryptAssertion(encryptedAssertion);
            ... 
        }
    }

此方法解密斷言。此方法出錯

private Assertion decryptAssertion(EncryptedAssertion assertion) throws 
 CertificateException, KeyException
        {
    Assertion ast = null;
    Decrypter decrypter = buildAssertionDecrypter();
 try{
    ast = decrypter.decrypt(assertion);  // <-- Getting ERROR Here  
    }catch (DecryptionException e) {
        e.printStackTrace();
    }
   return ast;
}

下面的方法生成解密器

    private  Decrypter buildAssertionDecrypter() throws CertificateException, KeyException {

    List<EncryptedKeyResolver> list = new ArrayList<>();
    list.add(new InlineEncryptedKeyResolver());
    list.add(new EncryptedElementTypeEncryptedKeyResolver());
    list.add(new SimpleRetrievalMethodEncryptedKeyResolver());
    final ChainingEncryptedKeyResolver encryptedKeyResolver = new ChainingEncryptedKeyResolver();
    encryptedKeyResolver.getResolverChain().addAll(list);
    final KeyInfoCredentialResolver resolver = new StaticKeyInfoCredentialResolver(buildCredentials());       
    Decrypter decrypter = new Decrypter(null, resolver, encryptedKeyResolver);
    return decrypter;
}

生成憑據方法

public Credential buildCredentials() throws CertificateException, KeyException {
    X509Certificate cert = getPublicCert();
    PrivateKey privateKey = getPrivateKey();
    BasicX509Credential decryptionCredential = SecurityHelper.getSimpleCredential(cert, privateKey);
     return decryptionCredential;       
}

加載公鑰/私鑰

public X509Certificate getPublicCert(){
    X509Certificate cer = null;
    try{
        CertificateFactory fact = CertificateFactory.getInstance("X.509");
        FileInputStream is = new FileInputStream ("pubkey.cer");
        cer = (X509Certificate) fact.generateCertificate(is);

    } catch (Exception e) {
        e.printStackTrace();
    } 
    return cer;
}

public RSAPrivateKey getPrivateKey(){
    Key key = null;
    RSAPrivateKey privateKey = null;
    try {
        KeyStore ks = KeyStore.getInstance("pkcs12", "SunJSSE");         
        ks.load(new FileInputStream("prvkey.pfx"),"".toCharArray());
         Enumeration<String> aliases = ks.aliases();
         while(aliases.hasMoreElements()){
             String alias = aliases.nextElement();
             key  = ks.getKey(alias, "".toCharArray());
        }
         privateKey = (RSAPrivateKey)key;
} catch (Exception e) {
    e.printStackTrace();
} 
    return privateKey;
}

我已驗證公鑰和私鑰。我獲取示例SAML并使用公鑰進行加密,然后獲取加密的SAML令牌并使用私鑰進行解密。我得到了相同的SAML樣本。我使用在線SAML工具來完成此操作。

EncryptedAssertion SAML

<saml:EncryptedAssertion>
<xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" Type="http://www.w3.org/2001/04/xmlenc#Element">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
<dsig:KeyInfo xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">
<xenc:EncryptedKey>
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
<xenc:CipherData>
<xenc:CipherValue>Some Value</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedKey>
</dsig:KeyInfo>
<xenc:CipherData>
<xenc:CipherValue>Value</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedData>
</saml:EncryptedAssertion>

推薦答案

對于我來說,當我的未加密樣本響應無效時,我也遇到了類似的問題。這是因為&lt;SAML:Assertion&gt;沒有有效的名稱空間定義。我不得不插入命名空間聲明&lt;saml:Assertion xmlns=”urn:oasis:names:tc:SAML:2.0:assertion”&gt;…才能讓它發揮作用。見問題2HERE。我不確定你是否也有同樣的問題。但這就是我的問題所在。

這篇關于SAML加密的Assertion解密失敗的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,

分享到:
標簽:Assertion SAML 加密 失敗 解密
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定