我今天一直在修補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