编程语言
首页 > 编程语言> > java – 如何删除模糊函数调用

java – 如何删除模糊函数调用

作者:互联网

请帮我解决这段代码中的模糊调用.

fac.newtransform()和fac.new signedinfo()给出错误说:

reference to newTransform is ambiguous, both method newTransform(String,TransformParameterSpec) in XMLSignatureFactory and method newTransform(String,XMLStructure) in XMLSignatureFactory match

如何在XMLSignatureFactory中调用实际函数?

   XMLSignatureFactory fac =XMLSignatureFactory.getInstance("DOM",
                (Provider) Class.forName(providerName).newInstance());

   Reference ref =fac.newReference("",fac.newDigestMethod(DigestMethod.SHA1, null),
    Collections.singletonList(fac.newTransform(Transform.ENVELOPED, null)),null, null);


   SignedInfo si = fac.newSignedInfo
       (fac.newCanonicalizationMethod
         (CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS, 
             null), 
        fac.newSignatureMethod(SignatureMethod.DSA_SHA1, 
            null),
        Collections.singletonList(ref));

解决方法:

你必须施放第二个参数:

newTransform("foo", (XMLStructure) null)

您收到模糊警告,因为null是两个方法的有效参数.您需要添加(XMLStructure)强制转换以告诉编译器您要设置为null的对象的类型.

标签:java,function,digital-signature,digital-certificate
来源: https://codeday.me/bug/20190825/1721017.html