如何删除模糊函数调用

时间:2013-07-01 07:18:13

标签: java function digital-signature digital-certificate

请帮我解决此代码中的含糊不清的电话。

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

  

newTransform的引用含糊不清,newTransform(String,TransformParameterSpec)中的方法XMLSignatureFactorynewTransform(String,XMLStructure)中的方法XMLSignatureFactory匹配

如何在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));

2 个答案:

答案 0 :(得分:4)

你必须施放第二个参数:

newTransform("foo", (XMLStructure) null)

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

答案 1 :(得分:2)

newTransform(Transform.ENVELOPED, null);

此调用不明确,因为null将匹配方法签名newTransform(java.lang.String algorithm, XMLStructure params)newTransform(java.lang.String algorithm, TransformParameterSpec params)。投下null

newTransform("foo", (XMLStructure) null)