MakeSignature.signDetached抛出IllegalArgumentException

时间:2014-09-11 11:34:56

标签: java pdf-generation itext digital-signature hsm

使用MakeSignature.signDetached使用LUNA HSM 1700将数字签名应用于PDF。

请指导我解决此问题。

提前致谢。

方法如下:

public static void Digital_signed(String SRC,String DEST) 
throws IOException, GeneralSecurityException, DocumentException , Exception{
    try {
        char[] pkcs11PIN = "devicepassword".toCharArray();
        Provider p = null;
        FileInputStream fis = new FileInputStream(configFileName);
        p = new SunPKCS11(fis);
        String provide_name =p.getName();
        Security.addProvider(p);
        KeyStore ks =  KeyStore.getInstance("PKCS11","SunPKCS11-Luna");
        ks.load(null, pkcs11PIN);
        String alias = (String)ks.aliases().nextElement();
        PrivateKey pk = (PrivateKey) ks.getKey(alias, pkcs11PIN);
        Certificate[] chain = ks.getCertificateChain(alias);
        TSAClient tsaClient = null;
        for (int i = 0; i < chain.length; i++) {
            X509Certificate cert = (X509Certificate)chain[i];
            String tsaUrl = CertificateUtil.getTSAURL(cert);
            if (tsaUrl != null) {
                tsaClient = new TSAClientBouncyCastle(tsaUrl);
                break;
            }
        }

        List <CrlClient> crlList = new ArrayList<CrlClient>();

        PdfReader reader = new PdfReader(SRC);
        FileOutputStream os = new FileOutputStream(DEST);
        PdfStamper stamper = PdfStamper.createSignature(reader, os, '\0');
        PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
        appearance.setVisibleSignature(new Rectangle(700, 820, 760, 780), 1, "sig");
        ExternalSignature pks = new PrivateKeySignature(pk,  DigestAlgorithms.SHA256, provide_name);
        ExternalDigest digest = new BouncyCastleDigest();

        MakeSignature.signDetached(appearance, digest, pks, chain, crlList, null, tsaClient, 0, CryptoStandard.CMS);
    }  
    catch(Exception e)
    {}
    finally{ }
}

以下错误:

  

java.lang.IllegalArgumentException:名称&#39; iText? 5.5.0?2000-2013 iText Group NV(AGPL-version)(AGPL-version)(AGPL-version)(AGPL-version)(AGPL-version)(AGPL-version)(AGPL-version)&#39;太长(143个字符)。

1 个答案:

答案 0 :(得分:0)

您使用的iText版本中的Version类存在问题。我们现在有synchronized操作,从iText 5.5.3开始,问题应该已经消失了。如果没有:请让我知道,我们将再看一下这个问题。