我已经写了一个使用AES加密的BlackBerry应用程序。我正在尝试使用C#中的AesCryptoServiceProvider来解密它。
BlackBerry代码似乎没有使用IV,这意味着我没有什么可以传递给AesCryptoServiceProvider的。
我有没有可能在没有静脉输液器的情况下解密AES,如果可能,如何解密?
发布于 2012-03-15 02:48:18
阅读黑莓java加密文档,似乎你不应该直接使用AESEncryptionEngine。如果你直接使用它,你最终会得到(我假设) ECB模式,这会导致对企鹅图像进行以下加密。不要这样做。

相反,要使用某种安全的操作模式,您实际上需要在基本的AESEncrypt /解密引擎周围使用包装器。您希望使用CBCEncryptionEngine来完成此操作。以下是来自here的一些示例代码。请注意,IV在创建时是随机的,因此您不需要设置它或担心重用。只需在此处用AES替换DES即可。
// sampleDESCBCEncryption
private static int sampleDESCBCEncryption(
byte[] secretKey, byte[] initVector, byte[] plainText, byte[] cipherText, int
dataLength )
throws CryptoException, IOException
{
// Create a new DES key based on the 8 bytes in the secretKey array
DESKey key = new DESKey( secretKey );
// Create a new initialization vector using the 8 bytes in initVector
InitializationVector iv = new InitializationVector( initVector );
// Create a new byte array output stream for use in encryption
NoCopyByteArrayOutputStream out = new NoCopyByteArrayOutputStream();
// Create a new instance of a BlockEncryptor passing in an instance of a CBC encryptor engine
// (containing an instance of a DES encryptor engine), the initialization vector, and the
// output stream
BlockEncryptor cryptoStream = new BlockEncryptor(
new CBCEncryptorEngine( new DESEncryptorEngine( key ), iv ), out );
// Write dataLength bytes from plainText to the CFB encryptor stream
cryptoStream.write( plainText, 0, dataLength );
cryptoStream.close();
// Now copy the encrypted bytes from out into cipherText and return the length
int finalLength = out.size();
System.arraycopy( out.getByteArray(), 0, cipherText, 0, finalLength );
return finalLength;
} https://stackoverflow.com/questions/9700215
复制相似问题