04-26-2010 07:59 AM
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?
04-28-2010 02:22 PM
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.
02-23-2011 08:39 AM
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.
10-15-2012 04:14 AM