java - 编译错误bouncycastle java

java - 编译错误bouncycastle java,第1张

这是我第一次申请认证,我对此完全陌生。 我在编译期间遇到了一个错误,我在互联网上没有发现任何关于它的信息,没有找到相同的错误。我4天以来一直在努力奋斗,我什么都做不了:(我真的很感谢你的帮助。谢谢。

这是我的代码: 主要课程

package tn.ance.signature;
import java.security.*;
import java.security.cert.X509Certificate;
public class main_project {
    public static void main(String[] args) {
        chargement_fichier cf = new chargement_fichier();
        KeyStore ks = cf.charger_fichier();
        char[] password = cf.getPassword();
        // RECUPERATION DU COUPLE CLE PRIVEE/PUBLIQUE ET DU CERTIFICAT PUBLIQUE
        X509Certificate cert = null;
        PrivateKey privatekey = null;
        PublicKey publickey = null;

        recuperation_cles_cert recup =new recuperation_cles_cert(); 
        privatekey = recup.getPrivatekey();
        publickey = recup.getPublickey();
        cert = recup.getCert();

        System.out.println("Private Key Format:");
        System.out.println(privatekey.getFormat());
        System.out.println("Private Key Algorithme:");
        System.out.println(privatekey.getAlgorithm());
        System.out.println("Public Key Format:");
        System.out.println(publickey.getFormat());
        System.out.println("Public Key Algorithme:");
        System.out.println(publickey.getAlgorithm());
        System.out.println("Certification:");
        System.out.println("SubjectDN:");
        System.out.println(cert.getSubjectDN());
        System.out.println("Not After:");
        System.out.println(cert.getNotAfter());
        System.out.println("Not Before:");
        System.out.println(cert.getNotBefore());

    }
}

**

文件上传课程

package tn.ance.signature;
import java.io.FileInputStream;
import java.security.KeyStore;
import java.security.Security;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public class chargement_fichier {
     private char[] password = null;
    // CHARGEMENT DU FICHIER PKCS#12
     public KeyStore charger_fichier(){
            KeyStore ks = null;
            Security.addProvider(new BouncyCastleProvider());
            try {
                ks = KeyStore.getInstance("PKCS12");
                // Password pour le fichier personnal_nyal.p12
                password = "123456".toCharArray();
                FileInputStream fl = new FileInputStream("T:/Stage/150722/syrine.p12");
                ks.load(fl, password);
                return  ks;
            } catch (Exception e) {
                System.out.println("Erreur: fichier "  
                                   "syrine.p12"  
                                   " n'est pas un fichier pkcs#12 valide ou passphrase incorrect");
                return null ;
            }
         }
      public char[] getPassword(){
             return password;
             }
}

密钥和证书加载

package tn.ance.signature;
    import java.security.KeyStore;
    import java.security.PrivateKey;
    import java.security.PublicKey;
    import java.security.cert.X509Certificate;
    import java.util.Enumeration;
    import java.util.Vector;
    public class recuperation_cles_cert {
        private X509Certificate cert = null;
        private PrivateKey privatekey = null;
        private PublicKey publickey = null;
        private KeyStore ks;
        private char[] password;

    public PrivateKey getPrivatekey(){

        chargement_fichier cf = new chargement_fichier(); 
        ks = cf.charger_fichier();
        password = cf.getPassword();

        try {
            Enumeration en = ks.aliases();
            String ALIAS = "";
            Vector vectaliases = new Vector();
            while (en.hasMoreElements())
                vectaliases.add(en.nextElement());
            String[] aliases = (String []) (vectaliases.toArray(new String[0]));
            for (int i = 0; i < aliases.length; i  )
                if (ks.isKeyEntry(aliases[i]))
                {
                    ALIAS = aliases[i];
                    break;
                }

            privatekey = (PrivateKey)ks.getKey(ALIAS, password);
            return privatekey;

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        }



    public PublicKey getPublickey(){

        chargement_fichier cf = new chargement_fichier(); 
        ks = cf.charger_fichier();
        password = cf.getPassword();

        try {
            Enumeration en = ks.aliases();
            String ALIAS = "";
            Vector vectaliases = new Vector();
            while (en.hasMoreElements())
                vectaliases.add(en.nextElement());
            String[] aliases = (String []) (vectaliases.toArray(new String[0]));
            for (int i = 0; i < aliases.length; i  )
                if (ks.isKeyEntry(aliases[i]))
                {
                    ALIAS = aliases[i];
                    break;
                }

            publickey = ks.getCertificate(ALIAS).getPublicKey();
            return publickey;
        } catch (Exception e) {
            e.printStackTrace();
            return null ;
        }
         }

    public X509Certificate getCert(){

        chargement_fichier cf = new chargement_fichier(); 
        ks = cf.charger_fichier();
        password = cf.getPassword();

        try {
            Enumeration en = ks.aliases();
            String ALIAS = "";
            Vector vectaliases = new Vector();
            while (en.hasMoreElements())
                vectaliases.add(en.nextElement());
            String[] aliases = (String []) (vectaliases.toArray(new String[0]));
            for (int i = 0; i < aliases.length; i  )
                if (ks.isKeyEntry(aliases[i]))
                {
                    ALIAS = aliases[i];
                    break;
                }
            cert = (X509Certificate)ks.getCertificate(ALIAS);
            return cert;

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        }

}

**

这是错误

Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/asn1/cryptopro/CryptoProObjectIdentifiers
    at org.bouncycastle.jcajce.provider.digest.GOST3411$Mappings.configure(Unknown Source)
    at org.bouncycastle.jce.provider.BouncyCastleProvider.loadAlgorithms(Unknown Source)
    at org.bouncycastle.jce.provider.BouncyCastleProvider.setup(Unknown Source)
    at org.bouncycastle.jce.provider.BouncyCastleProvider.access

**

0(Unknown Source) at org.bouncycastle.jce.provider.BouncyCastleProvider.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at org.bouncycastle.jce.provider.BouncyCastleProvider.<init>(Unknown Source) at tn.ance.signature.chargement_fichier.charger_fichier(chargement_fichier.java:16) at tn.ance.signature.main_project.main(main_project.java:13) Caused by: java.lang.ClassNotFoundException: org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers at java.net.URLClassLoader.run(Unknown Source) at java.net.URLClassLoader.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader. loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 9 more
更新

Exception in thread "main" java.lang.NoSuchFieldError: gostR3411 at org.bouncycastle.jcajce.provider.digest.GOST3411$Mappings.configure(Unknown Source) at org.bouncycastle.jce.provider.BouncyCastleProvider.loadAlgorithms(Unknown Source) at org.bouncycastle.jce.provider.BouncyCastleProvider.setup(Unknown Source) at org.bouncycastle.jce.provider.BouncyCastleProvider.access最佳答案:0(Unknown Source) at org.bouncycastle.jce.provider.BouncyCastleProvider.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at org.bouncycastle.jce.provider.BouncyCastleProvider.<init>(Unknown Source) at tn.ance.signature.chargement_fichier.charger_fichier(chargement_fichier.java:15) at tn.ance.signature.main_project.main(main_project.java:13) 我将bcprov-jdk16-1.45添加到文件夹C:\ Program Files \ Java \ jdk1.7.0_75 \ lib并将其添加到项目中的外部jar的路径,但现在我收到此错误

1 个答案:

答案 0 :(得分:3)

尝试使用jdk15on-152 - 1.45版本已经过期。名字中带有jdk15on的jar版本是JDK 1.5到JDK 1.8(我们最初尝试过jdk15 ,但结果发现maven无法应对 )。

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复