2012-03-14 1 views
2

AES暗号化を使用するBlackBerryアプリを作成しました。私はC#でAesCryptoServiceProviderを使用してこれを解読しようとしています。AESCryptoServiceProviderを使用してIVなしで解読する

BlackBerryコードはIVを使用していないようです。つまり、AesCryptoServiceProviderに何も渡す必要がありません。

IVなしでAESを復号化することは可能ですか?

+0

「0」で試すことができます –

+0

タイトルに「C#.NET」などのプレフィックスを付けないでください。それがタグのためのものです。 –

+0

さて、私はゼロを試して報告します。リマインダージョンのおかげで、私は頻繁に私のタイトルが大丈夫なのだろうかと思います。 – conor

答えて

1

ブラックベリーのJava暗号化のドキュメントを読むと、あなたはAESEncryptionEngineを直接使用することは想定されていません。それをまっすぐに使うと、ECBモードになってしまい、その結果、次のペンギンの画像を暗号化します。それをしないでください。

Bad Encryption 安全な動作モードを使用するには、基本的なAESEncrypt/Decrypt Engineのラッパーを実際に使用する必要があります。これを行うにはCBCEncryptionEngineを使用します。 hereのサンプルコードです。 IVは作成時にランダム化されるため、設定する必要はなく、再利用の心配もありません。ここでDESをAESに置き換えてください。

// 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; 
}  
関連する問題