0

我正在尝试在 Java (org.opensaml) 中生成 SAML 响应 XML。尝试使用 rsa-sha256 算法生成签名时,出现以下异常:

java.security.NoSuchAlgorithmException: http://www.w3.org/2001/04/xmldsig-more#rsa-sha256 Signature not available

不确定确切的原因。签名对我来说看起来是正确的。我需要添加任何依赖项吗?谁能帮我解决这个问题?添加了代码以生成签名值:

public static String generateSignatureValue(String signatureMessage, String signatureAlgorithm,
            String privateKeyString)
                    throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, SignatureException {

        KeyFactory kf = KeyFactory.getInstance("RSA");

        PKCS8EncodedKeySpec keySpecPKCS8 = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKeyString));
        PrivateKey privateKey = kf.generatePrivate(keySpecPKCS8);

        Signature rsaSha256Signature = Signature.getInstance(signatureAlgorithm);
        rsaSha256Signature.initSign(privateKey);
        rsaSha256Signature.update(signatureMessage.getBytes());
        byte[] signed2 = rsaSha256Signature.sign();

        return Base64.getEncoder().encodeToString(signed2);

    }
4

0 回答 0