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.

inside custom component

Java Development

Reply
Contributor
vidhi_thakrar
Posts: 12
Registered: ‎04-07-2010
My Device: 9530

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?

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

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.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Regular Visitor
yogesh_mangrulkar
Posts: 1
Registered: ‎02-23-2011
My Device: Blackberry OS 5.0 6.0 - All devices

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.

Regular Visitor
halip007
Posts: 1
Registered: ‎10-15-2012
My Device: Curve 9300

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.