Encryption OpenSAML 3DES错误的密钥大小:必须等于112或168

Encryption OpenSAML 3DES错误的密钥大小:必须等于112或168,encryption,opensaml,Encryption,Opensaml,我正在使用OpenSAML加密我的SAML响应。我将我的算法从AES更改为三倍,如下所示,现在它开始向我抛出异常 //数据加密参数-密钥 EncryptionParameters encParams = new EncryptionParameters(); encParams.setAlgorithm(EncryptionConstants.ALGO_ID_BLOCKCIPHER_TRIPLEDES); java.security.InvalidParameterException: Wro

我正在使用OpenSAML加密我的SAML响应。我将我的算法从AES更改为三倍,如下所示,现在它开始向我抛出异常

//数据加密参数-密钥

EncryptionParameters encParams = new EncryptionParameters();
encParams.setAlgorithm(EncryptionConstants.ALGO_ID_BLOCKCIPHER_TRIPLEDES);

java.security.InvalidParameterException: Wrong keysize: must be equal to 112 or 168
    com.sun.crypto.provider.DESedeKeyGenerator.engineInit(DashoA13*..)
    javax.crypto.KeyGenerator.init(DashoA13*..)
    javax.crypto.KeyGenerator.init(DashoA13*..)

我知道我需要将密钥大小设置为168,但如何在OpenSAML中设置它?

您不能使用此方法,而是应该使用SecurityHelper的另一个方法generateKey,如下所示:

SecurityHelper.generateKey("DESede", 168, "SunJCE");
这里的区别是您需要提供所有细节,例如算法名称(在SunJCE中,DESede是triple-DES)、密钥长度和JCA提供程序名称(这里是SunJCE)

所以你应该这样做:

//为数据加密生成对称密钥

Credential symmetricCredential = SecurityHelper.getSimpleCredential(

                                SecurityHelper.generateKey("DESede", 168, "SunJCE"));
//指定数据加密参数

    EncryptionParameters encParams = new EncryptionParameters();
    encParams.setAlgorithm(EncryptionConstants.ALGO_ID_BLOCKCIPHER_TRIPLEDES);  
    encParams.setEncryptionCredential(symmetricCredential);

希望这有帮助。

您不能使用此方法,而是应该使用SecurityHelper的另一个方法generateKey,如下所示:

SecurityHelper.generateKey("DESede", 168, "SunJCE");
这里的区别是您需要提供所有细节,例如算法名称(在SunJCE中,DESede是triple-DES)、密钥长度和JCA提供程序名称(这里是SunJCE)

所以你应该这样做:

//为数据加密生成对称密钥

Credential symmetricCredential = SecurityHelper.getSimpleCredential(

                                SecurityHelper.generateKey("DESede", 168, "SunJCE"));
//指定数据加密参数

    EncryptionParameters encParams = new EncryptionParameters();
    encParams.setAlgorithm(EncryptionConstants.ALGO_ID_BLOCKCIPHER_TRIPLEDES);  
    encParams.setEncryptionCredential(symmetricCredential);
希望这有帮助