3

Wrox Beginning CryptographywithJavaのサンプルコードを使用しています。コードの24行目(以下)は、Eclipseでのエラーを示しています。

X509CertSelector signerConstraints = signer.getSID();

Eclipseエラー:

タイプの不一致:SignerIdからX509CertSelectorに変換できません

完全な例は次のとおりです。

package chapter9;

import java.security.cert.*;
import java.util.Iterator;

import org.bouncycastle.cms.CMSSignedData;
import org.bouncycastle.cms.SignerInformation;
import org.bouncycastle.cms.SignerInformationStore;

/**
 * Base class for signed examples.
 */
public class SignedDataProcessor {
    /**
     * Return a boolean array representing keyUsage with digitalSignature set.
     */
    static boolean[] getKeyUsageForSignature() {
        boolean[] val = new boolean[9];
        val[0] = true;

        return val;
    }

    /**
     * Take a CMS SignedData message and a trust anchor and determine if
     * the message is signed with a valid signature from a end entity
     * entity certificate recognized by the trust anchor rootCert.
     */
     public static boolean isValid(
         CMSSignedData   signedData,
         X509Certificate rootCert) throws Exception {
        CertStore certsAndCRLs = signedData.getCertificatesAndCRLs("Collection", "BC");
        SignerInformationStore  signers = signedData.getSignerInfos();
        Iterator it = signers.getSigners().iterator();

        if (it.hasNext()) {
            SignerInformation signer = (SignerInformation)it.next();
            X509CertSelector signerConstraints = signer.getSID();

            signerConstraints.setKeyUsage(getKeyUsageForSignature());

            PKIXCertPathBuilderResult result = 
                Utils.buildPath(rootCert, signer.getSID(), certsAndCRLs);

            return signer.verify(result.getPublicKey(), "BC");
        }

        return false;
    }
}
4

1 に答える 1

1

私は答えを見つけました:bcprov-jdk16-145.jar、bcmail-jdk16-145.jarにアップグレードするだけです。

于 2012-11-22T13:32:49.197 に答える