2

Java での復号化に関して、かなり奇妙な動作に直面しています。以下のコードを使用して

public void decrypt(File file, String output_file_path) throws FileNotFoundException, IOException, GeneralSecurityException {
    String hex_enc_key = "346a23652a46392b4d73257c67317e352e3372482177652c";
    Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
    SecretKeySpec keySpec = new SecretKeySpec(HexParser.fromHexString(hex_enc_key), "AES");
    cipher.init(Cipher.DECRYPT_MODE, keySpec);
    CipherOutputStream cos = new CipherOutputStream(new FileOutputStream(new File(output_file_path)), cipher);
    FileInputStream fis = new FileInputStream(file);
    doCopy(fis, cos);
}

ランダムな例外が発生します

java.security.InvalidKeyException: 不正なキー サイズまたはデフォルト パラメータ

私は問題をグーグルで検索し、JCE 無制限の強度について知りましたが、常に同じキーを使用している場合でも、これらのランダムな例外が発生する理由を理解できません(必要な入力ファイルに基づいて、機能する場合と機能しない場合があります)解読します)。

明確にするために、私が使用している

Cipher.getMaxAllowedKeyLength("AES")

JCE の制限を確認し、同じ設定で暗号化しても問題はありません。

public void encrypt(File file, String output_file_path) throws FileNotFoundException, IOException, GeneralSecurityException {
    Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); 
    SecretKeySpec keySpec = new SecretKeySpec(HexParser.fromHexString(db_enc_key), "AES");
    cipher.init(Cipher.ENCRYPT_MODE, keySpec);
    CipherInputStream cis = new CipherInputStream(new FileInputStream(file), cipher);
    FileOutputStream os = new FileOutputStream(new File(output_file_path));
    doCopy(cis, os);
    cis.close();
    os.close();
}

誰かが私を正しい方向に向けることができますか?

どうもありがとう、ニコラ

4

0 に答える 0