How to decrypt EncryptedAssertion manually

前端 未结 2 936
再見小時候
再見小時候 2021-01-26 00:07

I want to decrypt the EncryptedAssertion. I tried with OpenSaml Decrypter but its not working for me.I am getting Failed to decrypt EncryptedData I have already ask that questio

2条回答
  •  面向向阳花
    2021-01-26 00:17

        public static byte[] decrypt(byte[] cryptoBytes, byte[] aesSymKey)
            throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
            InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
        // https://github.com/onelogin/java-saml/issues/23
        String cipherMethod = "AES/CBC/ISO10126Padding"; // This should be derived from Cryptic Saml
    
        AlgorithmParameterSpec iv = new IvParameterSpec(cryptoBytes, 0, 16);
        
        // Strip off the the first 16 bytes because those are the IV
        byte[] cipherBlock = Arrays.copyOfRange(cryptoBytes,16, cryptoBytes.length);
                
        // Create a secret key based on symKey
        SecretKeySpec secretSauce = new SecretKeySpec(aesSymKey, "AES");
    
        // Now we have all the ingredients to decrypt
        Cipher cipher = Cipher.getInstance(cipherMethod);
        cipher.init(Cipher.DECRYPT_MODE, secretSauce, iv);
    
        // Do the decryption
        byte[] decrypedBytes = cipher.doFinal(cipherBlock);
        return decrypedBytes;
    }
    

    ISO10126Padding should work....

提交回复
热议问题