久久久久久久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网站免费看 | 国产一级大片 | 国产精品美女久久久久久免费 | 亚洲视频在线观看一区二区三区 | 看片地址 | 亚洲午夜视频 | 国产japanhdxxxx麻豆 | 激情国产在线 | caoporn国产精品免费公开 | 欧美日韩国产一区二区 | 欧美一区二区另类 | 偷拍自拍网 | 91一区二区三区在线观看 | 久久久国产精品视频 | 欧美日韩一本 | 国产精品一二三区 | 羞羞网站在线免费观看 | 日本精品一区二区在线观看 | 日韩在线视频一区二区三区 | 91精品国产综合久久久久久 | 国产超碰人人爽人人做人人爱 | 日本精品一区二区三区在线观看视频 | 日韩在线观看中文字幕 | 久久aⅴ乱码一区二区三区 亚洲欧美综合精品另类天天更新 | 亚洲区一区二区 | 中文字幕在线一区 | 91精品国产欧美一区二区 | 国产日韩欧美一区 | 美女久久视频 | 综合国产第二页 | 成人免费视频 | 日韩欧美国产一区二区三区 | 亚洲人成人一区二区在线观看 | 一本一道久久a久久精品蜜桃 | 精品久久久久久久久久久久久久 | 日韩在线免费视频 |