Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Contributor
vidhi_thakrar
Posts: 12
Registered: ‎04-07-2010
My Carrier: N/A

Problem with PKCS1FormatterEngine

Hi, Below is my code snippet for RSA Encryption:

 

public static byte[] encryptRSA(byte[] modulus, byte[] exponent, byte[] data) {
        try {

            // First, it is necessary to create an RSA crypto system in order
            // to specify the bit size of the key
            RSACryptoSystem cryptoSystem = new RSACryptoSystem( 1024 );
            
            // Now create the public key for encryption
            RSAPublicKey publicKey = new RSAPublicKey( cryptoSystem, exponent, modulus );
            
            // Create the output stream to store the encrypted data
            NoCopyByteArrayOutputStream out = new NoCopyByteArrayOutputStream();
            
            // Finally, create the block encryptor, passing in a new instance of
            // a PKCS1 encoder engine containing an RSA encryptor engine
            BlockEncryptor cryptoStream = new BlockEncryptor(
                new PKCS1FormatterEngine( new RSAEncryptorEngine( publicKey ) ), out );
            
            // Write the plaintext to the RSA encryption stream        
            cryptoStream.write(data);
            cryptoStream.close();
            
            // Copy the encrypted data from the output stream to the ciphertext
            // buffer and return the number of bytes actually in the buffer
            return out.getByteArray();


        } catch (Throwable e) {
            System.err.println(e.toString());
        }

        return null;
    }

 

The code throws java.lang.Error while creating PKCS1FormatterEngine and there is no detail message for it.

 

Any one has an idea that what causes this problem?

Please use plain text.
Administrator
MSohm
Posts: 13,065
Registered: ‎07-09-2008
My Carrier: Bell

Re: Problem with PKCS1FormatterEngine

I assume this is being thrown on the line that creates a new PKCS1FormatterEngine...?  If so, break that line into multiple lies, storing each item you are creating in its own variable.  This may allow you to receive a more informative error message.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Please use plain text.
Regular Visitor
yogesh_mangrulkar
Posts: 1
Registered: ‎02-23-2011

Re: Problem with PKCS1FormatterEngine

I'm facing the same issue when using a OS 5.0 device. I have no issues using the latest 6.0 OS.

Has anyone found a reson for this? I understand that this is supported since OS 3.6.

Please use plain text.
Regular Visitor
halip007
Posts: 1
Registered: ‎10-15-2012
My Carrier: Telkomsel, Indonesia

Re: Problem with PKCS1FormatterEngine

Hi I'm facing the same issue as well. I've got the NoClassDefFound exception for PKCS1FormatterEngine. It was happened on 8900 device after upgraded into OS 5.0.0.411. Please help. Urgent.
Please use plain text.