我今天一直在修补BB RSA Crypto并成功地加密了一个字符串(我认为,无法解密测试)。我的问题在于解密。我已经浏览论坛并尝试了很多代码组合,但似乎没有任何工作。所有调用解密cipertext挂起/阻止应用程序。黑莓RSA解密总是挂起
那么,我只在模拟器上尝试过,它会阻塞超过10分钟。我假设有些事情是错的。
下面我显示了我的代码来加密和解密一个字符串。任何有关我的解密程序有什么问题的见解都将不胜感激。谢谢。
cryptoSystem = new RSACryptoSystem(1024);
byte[] expo = Base64InputStream.decode(exponent, 0, exponent.length());
byte[] modul = Base64InputStream.decode(modulus, 0, modulus.length());
byte[] pArr = Base64InputStream.decode(p, 0, p.length());
byte[] qArr = Base64InputStream.decode(q, 0, q.length());
byte[] dpArr = Base64InputStream.decode(dp, 0, dp.length());
byte[] dqArr = Base64InputStream.decode(dq, 0, dq.length());
byte[] inverseQArr = Base64InputStream.decode(inverseQ, 0, inverseQ.length());
byte[] dArr = Base64InputStream.decode(d, 0, d.length());
// Public Key Setup
RSAPublicKey publicKey = new RSAPublicKey(cryptoSystem, expo, modul);
RSAEncryptorEngine eEngine = new RSAEncryptorEngine(publicKey);
fEngine = new PKCS1FormatterEngine(eEngine);
// Private Key Setup
RSAPrivateKey privateKey = new RSAPrivateKey(cryptoSystem, expo, pArr, qArr, dpArr, dqArr, inverseQArr);
dEngine = new RSADecryptorEngine(privateKey);
ufEngine = new PKCS1UnformatterEngine(dEngine);
// ################################ ENCRYPTION ################################
BlockEncryptor cryptoStream = new BlockEncryptor(fEngine, out);
cryptoStream.write(data, 0, data.length);
cryptoStream.close();
out.close();
// ################################ END ENCRYPTION ################################
// Convert encrypted bytes to text;
int finalLength = out.size();
byte[] cipherText = new byte[finalLength];
System.arraycopy(out.getByteArray(), 0, cipherText, 0, finalLength);
cipherText = out.toByteArray();
// ################################ DECRYPTION ################################
ByteArrayInputStream inputStream = new ByteArrayInputStream(cipherText);
byte[] plainText = new byte[finalLength];
BlockDecryptor decryptor = new BlockDecryptor(new PKCS1UnformatterEngine(new RSADecryptorEngine(privateKey)), inputStream);
decryptor.read(plainText, 0, finalLength); // THIS HANGS APP
//IOUtilities.streamToBytes(decryptor); // AND ALSO THIS
String strPlaintText = new String(plainText);
// ################################ END DECRYPTION ################################
hi conor。我建议你使用bouncycastle,因为BB库有很多意想不到的行为:只需要在项目中为j2me导入bouncycastle。 – rosco 2012-03-02 19:49:25
我开始认为我自己。谢谢。 – conor 2012-03-02 20:14:05