JCE unable to authenticate BC

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

JCE unable to authenticate BC

tcboyce

I’m hoping someone can assist me with my problem

 

I am in process of testing out several encryption methods and running into an issue I'm hoping someone can help me with. I am getting this error:

“JCE cannot authenticate the provider BC”

 

Full console output:

 

BC version 1.36

Exception in thread "main" java.lang.SecurityException: JCE cannot authenticate the provider BC

      at javax.crypto.Cipher.getInstance(DashoA12275)

      at javax.crypto.Cipher.getInstance(DashoA12275)

      at com.trial.encrypt.SimpleAESSymmetric.aesEncrypt(SimpleAESSymmetric.java:40)

      at com.trial.encrypt.SimpleAESSymmetric.main(SimpleAESSymmetric.java:23)

Caused by: java.util.jar.JarException: Class is on the bootclasspath

      at javax.crypto.SunJCE_d.a(DashoA12275)

      at javax.crypto.SunJCE_b.b(DashoA12275)

      at javax.crypto.SunJCE_b.a(DashoA12275)

      ... 4 more
I installed the bcprov-jdk15-138.jar file in the ext folder in the JRE and made the following entry in the java.security file:

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

This is the last provider in the provider list. I am using MyEclipse 5.5.1 with the supplied JRE and compiler.  You can see from the output the version of Bouncy Castle I’m using which is printed with the following code in the class:

 

String provName = Security.getProvider("BC").toString();

                  System.out.println(provName);

 

 

 

***************************************************

And here is the code that is throwing the error:

 

***************************************************

 


package com.trial.encrypt;

import java.security.InvalidKeyException;

import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import java.security.NoSuchAlgorithmException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.BadPaddingException;
import javax.crypto.NoSuchPaddingException;
import java.security.NoSuchProviderException;

public class SimpleAESSymmetric
{

/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
aesEncrypt();

}

public static void aesEncrypt()
{
byte[] input = new byte[] {
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, (byte)0x88, (byte)0x99, (byte)0xaa,
(byte)0xbb, (byte)0xcc, (byte)0xdd, (byte)0xee, (byte)0xff };
byte[] keyBytes = new byte[] {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 };
try
{
SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");

 

//added this to see if it could see the BC jar file.

String provName = Security.getProvider("BC").toString();

System.out.println(provName);

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

System.out.println("input text: " + Utils.toHex(input));

//encryption pass

byte[] cipherText = new byte[input.length];
cipher.init(Cipher.ENCRYPT_MODE, key);
int ctLength = cipher.update(input, 0, input.length, cipherText, 0);
ctLength += cipher.doFinal(cipherText, ctLength);
System.out.println("Cipher text: " + Utils.toHex(cipherText) + " bytes: " + ctLength);
}
catch(InvalidKeyException ike)
{
ike.printStackTrace();
}
catch(IllegalBlockSizeException ibse)
{
ibse.printStackTrace();
}
catch(BadPaddingException bpe)
{
bpe.printStackTrace();
}
catch(ShortBufferException sbe)
{
sbe.printStackTrace();
}
catch(NoSuchProviderException nspe)
{
nspe.printStackTrace();
}
catch(NoSuchAlgorithmException nsae)
{
nsae.printStackTrace();
}
catch(NoSuchPaddingException nspe)
{
nspe.printStackTrace();
}
}



}

 

Tom Boyce

SOA Architect

SOA Software, Inc.

12100 Wilshire Blvd

Suite 1800

Los Angeles, CA

Cell: 678-477-5631

FAX: 1-702-446-4605

 

Reply | Threaded
Open this post in threaded view
|

Re: JCE unable to authenticate BC

DNunes
> BC version 1.36
>
> Exception in thread "main" java.lang.SecurityException: JCE cannot
> authenticate the provider BC
>
>       at javax.crypto.Cipher.getInstance(DashoA12275)
>
>       at javax.crypto.Cipher.getInstance(DashoA12275)
>
>       at
> com.trial.encrypt.SimpleAESSymmetric.aesEncrypt(SimpleAESSymmetric.java:40)
>
>       at
> com.trial.encrypt.SimpleAESSymmetric.main(SimpleAESSymmetric.java:23)
>
> Caused by: java.util.jar.JarException: Class is on the bootclasspath
>
>       at javax.crypto.SunJCE_d.a(DashoA12275)
>
>       at javax.crypto.SunJCE_b.b(DashoA12275)
>
>       at javax.crypto.SunJCE_b.a(DashoA12275)
>
>       ... 4 more
>  I installed the bcprov-jdk15-138.jar file in the ext folder in the JRE and
> made the following entry in the java.security file:
>
>  security.provider.7=org.bouncycastle.jce.provider.BouncyCastleProvider
>


Well, maybe that's a dumb question , but when you say in the ext
folder in the JRE? Is it inside you $JAVA_HOME, like the documentation
states?

"Where you put the jar is up to mostly up to you, although with jdk1.3
and jdk1.4 the best (and in some cases only) place to have it is in
$JAVA_HOME/jre/lib/ext. Note: under Windows there will normally be a
JRE and a JDK install of Java if you think you have installed it
correctly and it still doesn't work chances are you have added the
provider to the installation not being used."

You should also verify if the jar has been correctly imported to the
Java system libraries in your IDE. Window -> Preferences -> Java ->
Installed JRE -> (click edit and verify if it is there)

Reply | Threaded
Open this post in threaded view
|

Re: JCE unable to authenticate BC

David Hook-4
In reply to this post by tcboyce

It looks like you have two providers installed with one of them in a
classpath between you and the JRE. The 1.38 provider does not print
version 1.36

Regards,

David

On Mon, 2007-11-12 at 06:05 -0800, Thomas Boyce wrote:

> I’m hoping someone can assist me with my problem
>
>  
>
> I am in process of testing out several encryption methods and running
> into an issue I'm hoping someone can help me with. I am getting this
> error:
>
> “JCE cannot authenticate the provider BC”
>
>  
>
> Full console output:
>
>  
>
> BC version 1.36
>
> Exception in thread "main" java.lang.SecurityException: JCE cannot
> authenticate the provider BC
>
>       at javax.crypto.Cipher.getInstance(DashoA12275)
>
>       at javax.crypto.Cipher.getInstance(DashoA12275)
>
>       at
> com.trial.encrypt.SimpleAESSymmetric.aesEncrypt(SimpleAESSymmetric.java:40)
>
>       at
> com.trial.encrypt.SimpleAESSymmetric.main(SimpleAESSymmetric.java:23)
>
> Caused by: java.util.jar.JarException: Class is on the bootclasspath
>
>       at javax.crypto.SunJCE_d.a(DashoA12275)
>
>       at javax.crypto.SunJCE_b.b(DashoA12275)
>
>       at javax.crypto.SunJCE_b.a(DashoA12275)
>
>       ... 4 more
> I installed the bcprov-jdk15-138.jar file in the ext folder in the JRE
> and made the following entry in the java.security file:
>
> security.provider.7=org.bouncycastle.jce.provider.BouncyCastleProvider
>
> This is the last provider in the provider list. I am using MyEclipse
> 5.5.1 with the supplied JRE and compiler.  You can see from the output
> the version of Bouncy Castle I’m using which is printed with the
> following code in the class:
>
>  
>
> String provName = Security.getProvider("BC").toString();
>
>                   System.out.println(provName);
>
>  
>
>  
>
>  
>
> ***************************************************
>
> And here is the code that is throwing the error:
>
>
>
>  
>
> ***************************************************
>
>  
>
>
> package com.trial.encrypt;
>
> import java.security.InvalidKeyException;
>
> import javax.crypto.*;
> import javax.crypto.spec.SecretKeySpec;
> import java.security.NoSuchAlgorithmException;
> import javax.crypto.IllegalBlockSizeException;
> import javax.crypto.BadPaddingException;
> import javax.crypto.NoSuchPaddingException;
> import java.security.NoSuchProviderException;
>
> public class SimpleAESSymmetric
> {
>
> /**
> * @param args
> */
> public static void main(String[] args)
> {
> // TODO Auto-generated method stub
> aesEncrypt();
>
> }
>
> public static void aesEncrypt()
> {
> byte[] input = new byte[] {
> 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, (byte)0x88,
> (byte)0x99, (byte)0xaa,
> (byte)0xbb, (byte)0xcc, (byte)0xdd, (byte)0xee, (byte)0xff };
> byte[] keyBytes = new byte[] {
> 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
> 0x0b, 0x0c, 0x0d,
> 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 };
> try
> {
> SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
>
>  
>
> //added this to see if it could see the BC jar file.
>
> String provName = Security.getProvider("BC").toString();
>
> System.out.println(provName);
>
> Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding", "BC");
>
> System.out.println("input text: " + Utils.toHex(input));
>
> //encryption pass
>
> byte[] cipherText = new byte[input.length];
> cipher.init(Cipher.ENCRYPT_MODE, key);
> int ctLength = cipher.update(input, 0, input.length, cipherText, 0);
> ctLength += cipher.doFinal(cipherText, ctLength);
> System.out.println("Cipher text: " + Utils.toHex(cipherText) + "
> bytes: " + ctLength);
> }
> catch(InvalidKeyException ike)
> {
> ike.printStackTrace();
> }
> catch(IllegalBlockSizeException ibse)
> {
> ibse.printStackTrace();
> }
> catch(BadPaddingException bpe)
> {
> bpe.printStackTrace();
> }
> catch(ShortBufferException sbe)
> {
> sbe.printStackTrace();
> }
> catch(NoSuchProviderException nspe)
> {
> nspe.printStackTrace();
> }
> catch(NoSuchAlgorithmException nsae)
> {
> nsae.printStackTrace();
> }
> catch(NoSuchPaddingException nspe)
> {
> nspe.printStackTrace();
> }
> }
>
>
>
> }
>
>  
>
> Tom Boyce
>
> SOA Architect
>
> SOA Software, Inc.
>
> 12100 Wilshire Blvd
>
> Suite 1800
>
> Los Angeles, CA
>
> Cell: 678-477-5631
>
> FAX: 1-702-446-4605
>
>  
>
>


Reply | Threaded
Open this post in threaded view
|

RE: JCE unable to authenticate BC

tcboyce
Correct!  I didn't realize my ide had an older version in the core libraries.  Once I removed the standard one from the project build path, everything worked fine!

Thank you for responding!

-----Original Message-----
From: David Hook [mailto:[hidden email]]
Sent: Monday, November 12, 2007 5:42 PM
To: Thomas Boyce
Cc: [hidden email]
Subject: Re: [dev-crypto] JCE unable to authenticate BC


It looks like you have two providers installed with one of them in a
classpath between you and the JRE. The 1.38 provider does not print
version 1.36

Regards,

David

On Mon, 2007-11-12 at 06:05 -0800, Thomas Boyce wrote:

> I’m hoping someone can assist me with my problem
>
>  
>
> I am in process of testing out several encryption methods and running
> into an issue I'm hoping someone can help me with. I am getting this
> error:
>
> “JCE cannot authenticate the provider BC”
>
>  
>
> Full console output:
>
>  
>
> BC version 1.36
>
> Exception in thread "main" java.lang.SecurityException: JCE cannot
> authenticate the provider BC
>
>       at javax.crypto.Cipher.getInstance(DashoA12275)
>
>       at javax.crypto.Cipher.getInstance(DashoA12275)
>
>       at
> com.trial.encrypt.SimpleAESSymmetric.aesEncrypt(SimpleAESSymmetric.java:40)
>
>       at
> com.trial.encrypt.SimpleAESSymmetric.main(SimpleAESSymmetric.java:23)
>
> Caused by: java.util.jar.JarException: Class is on the bootclasspath
>
>       at javax.crypto.SunJCE_d.a(DashoA12275)
>
>       at javax.crypto.SunJCE_b.b(DashoA12275)
>
>       at javax.crypto.SunJCE_b.a(DashoA12275)
>
>       ... 4 more
> I installed the bcprov-jdk15-138.jar file in the ext folder in the JRE
> and made the following entry in the java.security file:
>
> security.provider.7=org.bouncycastle.jce.provider.BouncyCastleProvider
>
> This is the last provider in the provider list. I am using MyEclipse
> 5.5.1 with the supplied JRE and compiler.  You can see from the output
> the version of Bouncy Castle I’m using which is printed with the
> following code in the class:
>
>  
>
> String provName = Security.getProvider("BC").toString();
>
>                   System.out.println(provName);
>
>  
>
>  
>
>  
>
> ***************************************************
>
> And here is the code that is throwing the error:
>
>
>
>  
>
> ***************************************************
>
>  
>
>
> package com.trial.encrypt;
>
> import java.security.InvalidKeyException;
>
> import javax.crypto.*;
> import javax.crypto.spec.SecretKeySpec;
> import java.security.NoSuchAlgorithmException;
> import javax.crypto.IllegalBlockSizeException;
> import javax.crypto.BadPaddingException;
> import javax.crypto.NoSuchPaddingException;
> import java.security.NoSuchProviderException;
>
> public class SimpleAESSymmetric
> {
>
> /**
> * @param args
> */
> public static void main(String[] args)
> {
> // TODO Auto-generated method stub
> aesEncrypt();
>
> }
>
> public static void aesEncrypt()
> {
> byte[] input = new byte[] {
> 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, (byte)0x88,
> (byte)0x99, (byte)0xaa,
> (byte)0xbb, (byte)0xcc, (byte)0xdd, (byte)0xee, (byte)0xff };
> byte[] keyBytes = new byte[] {
> 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
> 0x0b, 0x0c, 0x0d,
> 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 };
> try
> {
> SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
>
>  
>
> //added this to see if it could see the BC jar file.
>
> String provName = Security.getProvider("BC").toString();
>
> System.out.println(provName);
>
> Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding", "BC");
>
> System.out.println("input text: " + Utils.toHex(input));
>
> //encryption pass
>
> byte[] cipherText = new byte[input.length];
> cipher.init(Cipher.ENCRYPT_MODE, key);
> int ctLength = cipher.update(input, 0, input.length, cipherText, 0);
> ctLength += cipher.doFinal(cipherText, ctLength);
> System.out.println("Cipher text: " + Utils.toHex(cipherText) + "
> bytes: " + ctLength);
> }
> catch(InvalidKeyException ike)
> {
> ike.printStackTrace();
> }
> catch(IllegalBlockSizeException ibse)
> {
> ibse.printStackTrace();
> }
> catch(BadPaddingException bpe)
> {
> bpe.printStackTrace();
> }
> catch(ShortBufferException sbe)
> {
> sbe.printStackTrace();
> }
> catch(NoSuchProviderException nspe)
> {
> nspe.printStackTrace();
> }
> catch(NoSuchAlgorithmException nsae)
> {
> nsae.printStackTrace();
> }
> catch(NoSuchPaddingException nspe)
> {
> nspe.printStackTrace();
> }
> }
>
>
>
> }
>
>  
>
> Tom Boyce
>
> SOA Architect
>
> SOA Software, Inc.
>
> 12100 Wilshire Blvd
>
> Suite 1800
>
> Los Angeles, CA
>
> Cell: 678-477-5631
>
> FAX: 1-702-446-4605
>
>  
>
>