Skip to Content
author's profile photo Former Member
Former Member

java.security.NoSuchAlgorithmException exception while encrypting the input

Hi Experts,

While encrypting the input message using public key we are getting the below error exception .

" java.security.NoSuchAlgorithmException: No such algorithm: RSA/ECB/PKCS1Padding" .

Here is the small piece of code we used for encryption .

inKey = PGPUtil.getDecoderStream(inKey); // inKey contains public key info

PGPPublicKeyRingCollection pkCol = new PGPPublicKeyRingCollection(inKey);

Iterator it = pkCol.getKeyRings();

while (it.hasNext()) {pkRing = (PGPPublicKeyRing) it.next();

Iterator pkIt = pkRing.getPublicKeys();

while (pkIt.hasNext()) {

temp = (PGPPublicKey) pkIt.next();

if (temp.isEncryptionKey()) {

pubkey = temp;

break; } }

out = new DataOutputStream(out);

ByteArrayOutputStream bOut = new ByteArrayOutputStream();

PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(PGPCompressedDataGenerator.ZIP);

PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator();

OutputStream pOut = lData.open(comData.open(bOut),PGPLiteralData.BINARY, "", inputString.length(),new Date());

pOut.write(inputString.getBytes());

lData.close();

comData.close();

cPk.close(); out.close();

PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(PGPEncryptedDataGenerator.CAST5, new SecureRandom(),"BC");

cPk.addMethod(pubkey);

byte[] bytes = bOut.toByteArray();

OutputStream cOut = cPk.open(out, bytes.length); //<-- Here we are getting the above exception

cOut.write(bytes);

cPk.close();

out.close();

Could any one plz guide us ???

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 19, 2012 at 02:48 PM

    Hi,

    The above exception has resolved by restarting the java stack.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 30, 2011 at 05:27 PM

    Hello,

    You could check if you are using the unlimited strength jurisdiction policy files.

    #739043 How to Check for Full Strength Jurisdiction Policies:

    Regards,

    Sarah

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 30, 2011 at 05:51 PM

    This exception usually means that the chosen enc algorithm (CAST5) is not available on the Bouncy Castle provider. Therefore, please try:

    1. Update the JDK to latest hotfix. For example, if using JDK 1.4.2_11, install 1.4.2_30.

    2. Apply Sarah's recommendation of updating the policy files;

    3. Change the BC provider. Try using SUN's provider, for example.

    BR,

    Lucas

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Sarah/Lucas,

      We are using below java version

      java version "1.5.0_14"

      Java(TM) 2 Runtime Environment, Standard Edition (build 5.1.027)

      SAP Java 64-Bit Server VM (build 5.1.027, Dec 12 2008 04:31:57 - 51_REL - optU - aix ppc64 - bas2:113000 (mixed mode))

      u2022Below mentioned jar files are downloaded from http://www.bouncycastle.org/latest_releases.html

      u2022bcpg-jdk15-146 , bcprov-ext-jdk15-146, bcprov-jdk15-146

      As you guys suggested we have checked for security file access .

      There is no restriction to any algorithm.

      1. cat default_US_export.policy

      // Manufacturing policy file.

      grant {

      // There is no restriction to any algorithms.

      permission javax.crypto.CryptoAllPermission;

      };

      1. pwd

      /usr/java14_64/jre/lib/security

      We are getting the below exception while we are doing encryption.Could you please suggest?

      Error: javax.ejb.TransactionRolledbackLocalException: (Failed in component: sap.com/PGPEncryptionEAR) Exception raised from invocation of public com.sap.aii.af.lib.mp.module.ModuleData com.ngrid.sap.module.crypto.PGPDecryptionBean.process(com.sap.aii.af.lib.mp.module.ModuleContext,com.sap.aii.af.lib.mp.module.ModuleData) throws com.sap.aii.af.lib.mp.module.ModuleException method on bean instance com.ngrid.sap.module.crypto.PGPDecryptionBean-53db2a8 for bean sap.com/PGPEncryptionEARxml|PGPEncryption.jarxml|PGPDecryptionBean in application sap.com/PGPEncryptionEAR.; nested exception is: java.lang.ClassCastException: class java.lang.NullPointerException:null incompatible with class org.bouncycastle.openpgp.PGPException:sap.com/PGPEncryptionEAR-com.sap.engine.boot.loader.ResourceMultiParentClassLoader-3ac72a8c-alive; nested exception is: javax.ejb.EJBException: (Failed in component: sap.com/PGPEncryptionEAR) Exception raised from invocation of public com.sap.aii.af.lib.mp.module.ModuleData com.ngrid.sap.module.crypto.PGPDecryptionBean.process(com.sap.aii.af.lib.mp.module.ModuleContext,com.sap.aii.af.lib.mp.module.ModuleData) throws com.sap.aii.af.lib.mp.module.ModuleException method on bean instance com.ngrid.sap.module.crypto.PGPDecryptionBean-53db2a8 for bean sap.com/PGPEncryptionEARxml|PGPEncryption.jarxml|PGPDecryptionBean in application sap.com/PGPEncryptionEAR.; nested exception is: java.lang.ClassCastException: class java.lang.NullPointerException:null incompatible with class org.bouncycastle.openpgp.PGPException:sap.com/PGPEncryptionEAR-com.sap.engine.boot.loader.ResourceMultiParentClassLoader-3ac72a8c-alive; nested exception is: javax.ejb.EJBTransactionRolledbackException: (Failed in component: sap.com/PGPEncryptionEAR) Exception raised from invocation of public com.sap.aii.af.lib.mp.module.ModuleData com.ngrid.sap.module.crypto.PGPDecryptionBean.process(com.sap.aii.af.lib.mp.module.ModuleContext,com.sap.aii.af.lib.mp.module.ModuleData) throws com.sap.aii.af.lib.mp.module.ModuleException method on bean instance com.ngrid.sap.module.crypto.PGPDecryptionBean-53db2a8 for bean sap.com/PGPEncryptionEARxml|PGPEncryption.jarxml|PGPDecryptionBean in application sap.com/PGPEncryptionEAR.; nested exception is: java.lang.ClassCastException: class java.lang.NullPointerException:null incompatible with class org.bouncycastle.openpgp.PGPException:sap.com/PGPEncryptionEAR-com.sap.engine.boot.loader.ResourceMultiParentClassLoader-3ac72a8c-alive; nested exception is: javax.ejb.EJBException: (Failed in component: sap.com/PGPEncryptionEAR) Exception raised from invocation of public com.sap.aii.af.lib.mp.module.ModuleData com.ngrid.sap.module.crypto.PGPDecryptionBean.process(com.sap.aii.af.lib.mp.module.ModuleContext,com.sap.aii.af.lib.mp.module.ModuleData) throws com.sap.aii.af.lib.mp.module.ModuleException method on bean instance com.ngrid.sap.module.crypto.PGPDecryptionBean-53db2a8 for bean sap.com/PGPEncryptionEARxml|PGPEncryption.jarxml|PGPDecryptionBean in application sap.com/PGPEncryptionEAR.; nested exception is: java.lang.ClassCastException: class java.lang.NullPointerException:null incompatible with class org.bouncycastle.openpgp.PGPException:sap.com/PGPEncryptionEAR-com.sap.engine.boot.loader.ResourceMultiParentClassLoader-3ac72a8c-alive

      At this below step it is going to catch block and throwing above exception

      OutputStream cOut = cPk.open(out, bytes.length);// Return an output stream which will encrypt the data as it is written to it.

      Thanks in Advance

      Regards

      Venkat

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.