1

mkyong の JCE Encryption – Data Encryption Standard (DES) Tutorialに従って、DES Util クラスを作成しました。

これが私のクラスです:

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

import tw.com.januarytc.android.singularsdk.lib.JsLib;
import android.util.Log;

public class DESUtil
{
  private KeyGenerator keyGen=null;
  private SecretKey sKey=null;
  private Cipher desCip=null;

  /**
   * Init. DES utility class
   * @return boolean
   */
  public boolean init()
  {
    boolean b=false;

    try
    {
      keyGen=KeyGenerator.getInstance("DES");
      sKey=keyGen.generateKey();
      desCip=Cipher.getInstance("DES/ECB/PKCS5Padding");
      b=true;
    }
    catch(Exception e)
    {
      Log.d(JsLib.TAG, "Init DESUtil failed: "+e.toString());
      e.printStackTrace();
      b=false;
    }
    return b;
  }

  /**
   * Encrypt string with DES
   * @param str - Original string
   * @return java.lang.String DES encrypted string
   * @throws IllegalStateException
   */
  public String encryptString(String str) throws IllegalStateException
  {
    if(keyGen==null || sKey==null || desCip==null){throw new IllegalStateException("DESUtil class has not been initialized.");}
    String ret="";
    try
    {
      desCip.init(Cipher.ENCRYPT_MODE, sKey);
      ret=new String(desCip.doFinal(str.getBytes("UTF-8")));
    }
    catch(Exception e)
    {
      e.printStackTrace();
      ret="";
    }
    return ret;
  }

  /**
   * Decrypt string which encrypted by DES
   * @param str - DES encrypted string
   * @return java.lang.String Original string
   * @throws IllegalStateException
   */
  public String decryptString(String strDes) throws IllegalStateException
  {
    if(keyGen==null || sKey==null || desCip==null){throw new IllegalStateException("DESUtil class has not been initialized.");}
    String ret="";
    try
    {
      desCip.init(Cipher.DECRYPT_MODE, sKey);
      ret=new String(desCip.doFinal(strDes.getBytes("UTF-8")));
    }
    catch(Exception e)
    {
      e.printStackTrace();
      ret="";
    }
    return ret;
  }
}

そしてWiKiが言ったように:

暗号化では、Triple DES は Triple Data Encryption Algorithm (TDEA または Triple DEA) ブロック暗号の一般名であり、Data Encryption Standard (DES) 暗号アルゴリズムを各データ ブロックに 3 回適用します

文字列を DES で 3 回暗号化するとどうなるか疑問に思っています... 3DES と同じでしょうか?

提案をありがとう、そして私の下手な英語でごめんなさい〜

4

2 に答える 2

4

DES は、ブルート フォース攻撃に対して脆弱な短い 56 ビット キーを使用します。3DES は 168 ビット キー (56x3) を使用し、次のように暗号化を実行します。

  1. キーの最初の 56 ビットを使用してクリア テキストを暗号化し、output1 を生成します。
  2. 鍵の 2 番目の 56 ビットを使用して output1 を復号化し、output2 を生成します。
  3. それらの 3 番目の 56 ビットを使用して output2 を暗号化し、暗号化されたテキストを生成します。

彼女は参照です: http://en.wikipedia.org/wiki/Triple_DES

于 2013-11-06T03:35:40.840 に答える
3

3DESDESは3 回実行しますが、3 つの異なるキーを使用します。このアルゴリズムは、元のキー サイズに関連する DES 固有のセキュリティの欠如を回避するために設計されました。

于 2013-11-06T03:22:52.193 に答える