久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 JAVA 中使用 AES/GCM 檢測不正確的密鑰

Detecting incorrect key using AES/GCM in JAVA(在 JAVA 中使用 AES/GCM 檢測不正確的密鑰)
本文介紹了在 JAVA 中使用 AES/GCM 檢測不正確的密鑰的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 AESGCM 模式下使用 BouncyCastle 加密/解密一些文件.
雖然我證明了錯誤的解密密鑰,但也不例外.
我應該如何檢查密鑰是否不正確?
我的代碼是這樣的:

I'm using AES to encrypt/decrypt some files in GCM mode using BouncyCastle.
While I'm proving wrong key for decryption there is no exception.
How should I check that the key is incorrect?
my code is this:

    SecretKeySpec   incorrectKey = new SecretKeySpec(keyBytes, "AES");
    IvParameterSpec ivSpec = new IvParameterSpec(ivBytes);
    Cipher          cipher = Cipher.getInstance("AES/GCM/NoPadding", "BC");
    byte[] block = new byte[1048576];
    int i;

    cipher.init(Cipher.DECRYPT_MODE, incorrectKey, ivSpec);

    BufferedInputStream fis=new BufferedInputStream(new ProgressMonitorInputStream(null,"Decrypting ...",new FileInputStream("file.enc")));
    BufferedOutputStream ro=new BufferedOutputStream(new FileOutputStream("file_org"));        
    CipherOutputStream dcOut = new CipherOutputStream(ro, cipher);

    while ((i = fis.read(block)) != -1) {
        dcOut.write(block, 0, i);
    }

    dcOut.close();
    fis.close();

謝謝

推薦答案

在 GCM 模式下沒有方法可以檢測到不正確的鍵.您可以檢查的是身份驗證標簽是否有效,這意味著您使用了正確的密鑰.問題是,如果身份驗證標簽不正確,那么這可能表明以下各項(或所有內容的組合,直至并包括完全替換密文和身份驗證標簽):

There is no method that you can detect incorrect key in GCM mode. What you can check is if the authentication tag validates, which means you were using the right key. The problem is that if the authentication tag is incorrect then this could indicate each of the following (or a combination of all, up to and including the full replacement of the ciphertext and authentication tag):

  1. 使用了不正確的密鑰;
  2. 計數器模式加密數據在傳輸過程中被更改;
  3. 其他經過身份驗證的數據已更改;
  4. 身份驗證標簽本身在傳輸過程中被更改.

您可以做的是發送額外的數據來識別所使用的密鑰.這可能是一個可讀的標識符 ("encryption-key-1"),但它也可能是一個 KCV,一個密鑰檢查值.KCV 通常由使用密鑰加密的零塊或密鑰上的加密安全哈希(也稱為指紋)組成.因為零塊上的加密會泄漏信息,所以您不應該使用它來識別加密密鑰.

What you could do is send additional data to identify the secret key used. This could be a readable identifier ("encryption-key-1") but it could also be a KCV, a key check value. A KCV normally consists of a zero-block encrypted with the key, or a cryptographically secure hash over the key (also called a fingerprint). Because the encryption over a zero block leaks information you should not use that to identify the encryption key.

您實際上可以使用 GCM 模式的 AAD 功能來計算密鑰標識數據上的身份驗證標簽.請注意,您無法區分指紋泄露和使用不正確的密鑰.但是指紋被意外損壞的可能性比IV、AAD、密文和認證標簽的整個結構要小.

You could actually use the AAD feature of GCM mode to calculate the authentication tag over the key identification data. Note that you cannot distinguish between compromise of the fingerprint and using an incorrect key. It's however less likely that the fingerprint is accidentally damaged than the entire structure of IV, AAD, ciphertext and authentication tag.

這篇關于在 JAVA 中使用 AES/GCM 檢測不正確的密鑰的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Java Remove Duplicates from an Array?(Java從數組中刪除重復項?)
How to fix Invocation failed Unexpected Response from Server: Unauthorized in Android studio(如何修復調用失敗來自服務器的意外響應:在 Android 工作室中未經授權)
AES encryption, got extra trash characters in decrypted file(AES 加密,解密文件中有多余的垃圾字符)
AES Error: Given final block not properly padded(AES 錯誤:給定的最終塊未正確填充)
AES-256-CBC in Java(Java 中的 AES-256-CBC)
Using BouncyCastle to encrypt with ECIES in Java(在 Java 中使用 BouncyCastle 使用 ECIES 進行加密)
主站蜘蛛池模板: 成人一级黄色毛片 | 中文字幕男人的天堂 | 日日夜夜精品视频 | 日韩视频国产 | 中文字幕av亚洲精品一部二部 | 91看片免费版 | 波多野结衣中文字幕一区二区三区 | 国产一区视频在线 | 国产xxx在线观看 | 自拍第1页| 羞羞视频在线观免费观看 | 欧美激情综合五月色丁香小说 | 欧美日韩在线精品 | 天天插天天操 | 综合九九 | 成人欧美一区二区三区白人 | 国产精品九九九 | 亚洲精品视频在线播放 | 欧美性久久 | 亚洲精品中文字幕 | 欧美激情视频一区二区三区免费 | 日韩在线精品视频 | 国产精品久久久久久久午夜片 | 日韩毛片在线观看 | 欧美色综合一区二区三区 | 日韩和的一区二区 | 国产精品福利网 | 国产高清不卡 | 91大神在线资源观看无广告 | 激情毛片 | 日本黄色不卡视频 | 激情五月婷婷丁香 | 中文字幕在线一区二区三区 | 九九久久精品 | 国产一区二区av | 亚洲日韩中文字幕一区 | 男女午夜激情视频 | 亚洲免费观看视频 | 韩日一区二区三区 | 日批日韩在线观看 | 国产日韩欧美 |