简体   繁体   English

充气城堡没有这样的提供者例外

[英]Bouncy castle no such provider exception

I have added the bouncy castle jar file to my application class path in android and in java. 我已将弹性城堡jar文件添加到android和java中的应用程序类路径中。 This is the code that I've used in both of them. 这是我在他们两个中使用的代码。 But it doesn't seem to recognize the provider "BC". 但它似乎没有认识到提供者“BC”。

SecureRandom sr1=new SecureRandom().getInstance("SHA1PRNG", "BC");
      System.out.println(sr1.getProvider());
      sr1.setSeed(12);
      byte[] a=new byte[0];
      sr1.nextBytes(a);
      int ai=a[0];
      System.out.println(ai);


It throws the following exception in both android and in java: 它在android和java中抛出以下异常:

java.security.NoSuchProviderException: no such provider: BC


How to correct this? 怎么纠正这个?
I had not added the provider in the policy file. 我没有在策略文件中添加提供程序。 After doing that I am getting the following exception. 这样做后,我得到以下异常。

java.security.NoSuchAlgorithmException: no such algorithm: SHA1PRNG for provider
 BC<br>

Does it mean that bouncy castle does not provide an implementation of "SHA1PRNG" algorithm? 这是否意味着充气城堡不提供“SHA1PRNG”算法的实现? But the whole reason I imported bouncy castle was to have a common provider in both android and in java, so that the sequence of random numbers generated with the same seed are the same in both android and java. 但是我导入充气城堡的全部原因是在android和java中都有一个共同的提供者,所以用同一种子生成的随机数序列在android和java中是相同的。

Did you add the following line? 你添加了以下行吗?

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

The default Java Security does not contain the Bouncy Castle implementation, so you need to add the Bouncy Castle Provider to the list of providers available in memory before you can use it. 默认的Java安全性不包含Bouncy Castle实现,因此您需要将Bouncy Castle Provider添加到内存中可用的提供程序列表中,然后才能使用它。

http://www.java2s.com/Code/Java/Security/SecureRandomSHA1PRNG.htm http://www.java2s.com/Code/Java/Security/SecureRandomSHA1PRNG.htm

Apparently it doesn't provide a SecureRandom implementation at all. 显然它根本不提供SecureRandom实现。 You can get the system implementation (from Harmony) like this (no need to create an instance to call static method): 您可以像这样获得系统实现(来自Harmony)(无需创建实例来调用静态方法):

SecureRandom.getInstance("SHA1PRNG")

BouncyCastle has DigestRandomGenerator which could probably used in a similar manner, but may or may not be compatible with the Sun SHA1PRNG (which appears to be proprietary, and really well defined) BouncyCastle有DigestRandomGenerator ,它可能以类似的方式使用,但可能与Sun SHA1PRNG兼容,也可能不兼容(它似乎是专有的,并且确实定义得很好)

Re: generating OTPs using SecureRandom : SecureRandom with a fixed seed is not the right tool for this. Re:使用SecureRandom生成OTP:使用固定种子的SecureRandom 不是正确的工具。 To generate OTPs, you should use a secret key combined with a predictable element (time or a counter). 要生成OTP,您应该使用与可预测元素(时间或计数器)相结合的密钥。 A standard way is using an HMAC as specified by eg OATH. 标准方法是使用例如OATH指定的HMAC。 Read RFC 4226 for details. 有关详细信息,请阅读RFC 4226

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Bouncy Castle作为提供者v / s Bouncy Castle API - Bouncy Castle as provider v/s Bouncy Castle API J2me的充气城堡提供程序jar - bouncy castle provider jar for j2me 在 Java 版本“15.0.1”中安装 Bouncy Castle Provider - Installing the Bouncy Castle Provider in java version "15.0.1" 使用 Bouncy Castle 提供程序创建 SSLContext 实例 - create an SSLContext instance using a Bouncy Castle provider PKIXCertPathBuilder与Bouncy Castle提供程序失败,但与默认(SUN)提供程序一起使用 - PKIXCertPathBuilder fails with Bouncy Castle provider but works with default (SUN) provider java bouncy-castle KeyAgreement.getInstance 适用于 eclipse 但抛出异常:JCE 在 jared 时无法验证提供者 BC - java bouncy-castle KeyAgreement.getInstance works in eclipse but throws Exception: JCE cannot authenticate the provider BC when jared Java忽略的类路径中的Bouncy Castle JCA提供程序版本 - Bouncy Castle JCA Provider Version In Classpath Ignored by Java 将Bouncy Castle提供程序集成到Java程序中的最佳方法是什么? - What's the best way to integrate the Bouncy Castle provider in a Java program? 在EJBCA中安装Bouncy Castle提供程序时出错。 - Error while installing Bouncy Castle provider in EJBCA. 在 Android 上使用哪个 JCE 提供程序? 充气城堡,Conscrypt,...? - Which JCE provider to use on Android ? Bouncy Castle, Conscrypt,…?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM