English 中文(简体)
Why java.security.NoSuchProviderException 没有这样的提供者:商业公司。
原标题:Why java.security.NoSuchProviderException No such provider: BC?

该项目增列了J.J.(bcprov-jdk16-145.jar)“安全”编码,并添加了<条码>。 BouncyCastleProvider.PROVIDER_NAME do 回去“BC”但AesFileIo.writeFile()仍然投掷java.security.NoSuchProviderException 无此种提供者:BC。 任何想法?

import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

public class AesFileIo {

    private static final String AES_ALGORITHM = "AES/CTR/NoPadding";
    private static final String PROVIDER = BouncyCastleProvider.PROVIDER_NAME;
    private static final byte[] AES_KEY_128 = { // Hard coded for now
        78, -90, 42, 70, -5, 20, -114, 103,
        -99, -25, 76, 95, -85, 94, 57, 54};
    private static final byte[] IV = { // Hard coded for now
        -85, -67, -5, 88, 28, 49, 49, 85,
        114, 83, -40, 119, -65, 91, 76, 108};
    private static final SecretKeySpec secretKeySpec =
            new SecretKeySpec(AES_KEY_128, "AES");
    private static final IvParameterSpec ivSpec = new IvParameterSpec(IV);

    public void AesFileIo() {
        Security.addProvider(new org.bouncycastle.jce.provider
                .BouncyCastleProvider());
    }

    public void writeFile(String fileName, String theFile) {
        try {
            Cipher cipher = Cipher.getInstance(AES_ALGORITHM, PROVIDER);
            cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivSpec);
            byte[] encrypted = cipher.doFinal(theFile.getBytes());
            ObjectOutputStream os = new ObjectOutputStream(
                new FileOutputStream(fileName));
            os.write(encrypted);
            os.flush();
            os.close();
        } catch (Exception e) {
            StackTraceElement se = new Exception().getStackTrace()[0];
            System.err.println(se.getFileName() + " " + se.getLineNumber()
                    + " " + e);
        }
    }
}
最佳回答

并不十分熟悉Anderson sdk,但似乎android-sdk。 地址是:BouncyCastle提供商已经增加了安全。

在PC环境中,你必须做的是人工添加。

Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

如果能查阅<条码>政策文档,仅添加一个条目,如:

security.provider.5=org.bouncycastle.jce.provider.BouncyCastleProvider 

通知<代码>.5等于已添加的供应商的顺序编号。

问题回答

你可以通过编辑java来增加安保提供者。 采用以下代码制造静态块的安全:

static {
    Security.addProvider(new BouncyCastleProvider());
}

www.un.org/Depts/DGACM/index_spanish.htm 如果你使用Maven项目,那么你将不得不增加对的依赖。 BouncyCastleProvider, as follows in pom.xml file of their project.

<dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk15on</artifactId>
            <version>1.47</version>
</dependency>

www.un.org/Depts/DGACM/index_spanish.htm 如果你使用正常的java项目,那么你可以从以下链接中增加下载bcprov-jdk15on-147.jar,并编辑你的班次。

http://www.java2s.com/Code/Jar/b/Downloadbcprovextjdk15on147jar.htm“rel=” http://www.java2s.com/Code/Jar/b/Downloadbcprovextjdk15on147jar.htm

you can add security provider by editing java.security by adding security.provider.=org.bouncycastle.jce.provider.BouncyCastleProvider

或增加贵阶层一线

Security.addProvider(new BouncyCastleProvider());

您可在下文中具体指明提供方,同时具体说明算法。

Cipher cipher = Cipher.getInstance("AES", "SunJCE");

如果你使用像博恩奇卡斯这样的其他供应商的话,

Cipher cipher =  Cipher.getInstance("AES", "BC");

我在这方面的经验是,当我每次执行时都这样做时,用提供人作为这种扼杀手段,就会被罚款。

Security.addProvider(new BounctCastleProvider());
new JcaPEMKeyConverter().setProvider("BC");

但是,当我优化并在施工人员中采取下列措施时:

   if(bounctCastleProvider == null) {
      bounctCastleProvider = new BouncyCastleProvider();
    }

    if(Security.getProvider(bouncyCastleProvider.getName()) == null) {
      Security.addProvider(bouncyCastleProvider);
    }

然后,我不得不像现在这样使用供应商,否则我会发现上述错误:

new JcaPEMKeyConverter().setProvider(bouncyCastleProvider);

我正在使用1.65版本。

对于那些使用网络服务器的人来说,确保bcprov-jdk16-145。 jar已安装在服务器校准上,因为必须把jar放在:

<weblogic_jdk_home>jrelibext




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签