我正在編寫一個使用AES(ECB)模式加密和解密數據的應用程序。 黑莓代碼的加密數據通過php代碼成功解密。 但問題是,當我從PHP加密文本我不能解密它與黑莓代碼..即使我沒有得到任何異常。無法解密AES的黑莓中的php代碼密文
這裏是我的代碼來加密和解密文本。
public static byte[] encrypt(byte[] keyData, byte[] data)
throws CryptoException, IOException
{
// Create the AES key to use for encrypting the data.
// This will create an AES key using as much of the keyData
// as possible.
AESKey key = new AESKey(keyData);
// Now, we want to encrypt the data.
// First, create the encryptor engine that we use for the actual
// encrypting of the data.
AESEncryptorEngine engine = new AESEncryptorEngine(key);
// Since we cannot guarantee that the data will be of an equal block
// length we want to use a padding engine (PKCS5 in this case).
PKCS5FormatterEngine fengine = new PKCS5FormatterEngine(engine);
// Create a BlockEncryptor to hide the engine details away.
ByteArrayOutputStream output = new ByteArrayOutputStream();
BlockEncryptor encryptor = new BlockEncryptor(fengine, output);
encryptor.write(data);
encryptor.close();
output.close();
return output.toByteArray();
}
public static String AESDecryption(byte[] keyData,byte[] cipherText, int dataLength) throws CryptoException, IOException {
// Create the input stream based on the ciphertext
ByteArrayInputStream in = new ByteArrayInputStream(cipherText, 0, dataLength);
// Now create the block decryptor and pass in a new instance
// of an AES decryptor engine with the specified block length
BlockDecryptor cryptoStream = new BlockDecryptor(new AESDecryptorEngine(new AESKey(keyData)), in);
byte[] T= new byte[dataLength];
// Read the decrypted text from the AES decryptor stream and
// return the actual length read
int length= cryptoStream.read(T);
String str= new String(T);
return str;
}
由於事先..
我還用你上面提到的相同的代碼... BT也值得一少...加密文本從PHP犯規獲得decryptd ... 這裏是我的密碼 48b983c4f1575280d244b74cf689efe5 表示,key是123456789試着解密....你無法解密它我的朋友.... –
主要問題是什麼是48b983c4f1575280d244b74cf689efe5?這是你在BB方面得到的字符串嗎?它看起來像一個HASH ..或者它是一個Base64編碼的字符串?在你將它發送給BB之前,你在加密的字節數組中使用PHP做什麼? –
夥計它是六進制代碼...即時通訊將其轉換爲字節,然後使用上述函數解密它...但沒有得到輸出。即使我沒有得到無效的純文本...異常還說「沒有堆棧跟蹤」..所以不知道什麼是問題..如果我把hexacode比48b983c4f1575280d244b74cf689efe5然後我的BB代碼解密它,並給我無效的純文本..所以不知道最新的問題是 –