クラス CryptUtil

java.lang.Object
  └ CryptUtil

public class CryptUtil
extends java.lang.Object

DES方式の秘密鍵(非公開鍵)を用いて暗号化・復号化を行う。


フィールドの概要
private  int buffSize
          エンコード/デコードする単位バッファサイズ
private  java.lang.String DEFAULT_ALGORITHM
          暗号化方式
private  byte[] keyMaterial
          デフォルトのSecretKeyを作成するためのbyte[]
private  javax.crypto.SecretKey secretKey
          SecretKey
 
コンストラクタの概要
CryptUtil()
          デフォルトコンストラクタ
CryptUtil(byte[] keyMaterial)
          byte[]から秘密鍵を生成して設定するコンストラクタ
CryptUtil(javax.crypto.SecretKey key)
          秘密鍵を受け取って設定するコンストラクタ
 
メソッドの概要
private  javax.crypto.SecretKey createDESCryptKey(byte[] keyMaterial)
          DES方式の秘密鍵を生成する
private  void crypt(int opmode, java.security.Key key, java.io.InputStream in, java.io.OutputStream out)
          モードに従って、InputStreamの内容をKeyを用いて、 暗号化/復号化してOutputStreamに書き出す
 void decrypt(java.io.InputStream in, java.io.OutputStream out)
          InputStreamの内容を復号化してOutputStreamに書き出す
 java.lang.String decryptString(java.lang.String str)
          文字列のHex逆変換、及びDES複合化
 void encrypt(java.io.InputStream in, java.io.OutputStream out)
          InputStreamの内容を暗号化してOutputStreamに書き出す
 java.lang.String encryptString(java.lang.String str)
          文字列のDES暗号化、及びHex変換
private  byte[] getKeyMaterial()
          キーマテリアルを取得する
private  javax.crypto.SecretKey getSecretKey()
          秘密鍵を取得する
static void main(java.lang.String[] args)
          テストメインメソッド
private  void setKeyMaterial(byte[] keyMaterial)
          キーマテリアルを設定する
private  void setSecretKey(javax.crypto.SecretKey key)
          秘密鍵を設定する
 java.lang.String simpleDecryptString(java.lang.String str)
          文字列のHex逆変換
 java.lang.String simpleEncryptString(java.lang.String str)
          文字列のHex変換
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

DEFAULT_ALGORITHM

private final java.lang.String DEFAULT_ALGORITHM
暗号化方式

関連項目:
定数フィールド値

buffSize

private int buffSize
エンコード/デコードする単位バッファサイズ


keyMaterial

private byte[] keyMaterial
デフォルトのSecretKeyを作成するためのbyte[]


secretKey

private javax.crypto.SecretKey secretKey
SecretKey

コンストラクタの詳細

CryptUtil

public CryptUtil()
          throws java.security.InvalidKeyException,
                 java.security.NoSuchAlgorithmException,
                 java.security.spec.InvalidKeySpecException
デフォルトコンストラクタ

例外:
java.security.InvalidKeyException
java.security.NoSuchAlgorithmException
java.security.spec.InvalidKeySpecException

CryptUtil

public CryptUtil(javax.crypto.SecretKey key)
秘密鍵を受け取って設定するコンストラクタ

パラメータ:
key - 秘密鍵

CryptUtil

public CryptUtil(byte[] keyMaterial)
          throws java.security.InvalidKeyException,
                 java.security.NoSuchAlgorithmException,
                 java.security.spec.InvalidKeySpecException
byte[]から秘密鍵を生成して設定するコンストラクタ

パラメータ:
keyMaterial - 秘密鍵生成のためのバイト配列
例外:
java.security.InvalidKeyException
java.security.NoSuchAlgorithmException
java.security.spec.InvalidKeySpecException
メソッドの詳細

setSecretKey

private final void setSecretKey(javax.crypto.SecretKey key)
秘密鍵を設定する

パラメータ:
key - 秘密鍵

getSecretKey

private final javax.crypto.SecretKey getSecretKey()
秘密鍵を取得する

戻り値:
秘密鍵

setKeyMaterial

private final void setKeyMaterial(byte[] keyMaterial)
キーマテリアルを設定する

パラメータ:
keyMaterial - 秘密鍵生成のためのバイト配列

getKeyMaterial

private final byte[] getKeyMaterial()
キーマテリアルを取得する

戻り値:
キーマテリアル

encrypt

public void encrypt(java.io.InputStream in,
                    java.io.OutputStream out)
             throws javax.crypto.NoSuchPaddingException,
                    java.security.NoSuchAlgorithmException,
                    java.security.InvalidKeyException,
                    javax.crypto.BadPaddingException,
                    javax.crypto.IllegalBlockSizeException,
                    java.io.IOException
InputStreamの内容を暗号化してOutputStreamに書き出す

パラメータ:
in - 入力
out - 出力
例外:
javax.crypto.NoSuchPaddingException
java.security.NoSuchAlgorithmException
java.security.InvalidKeyException
javax.crypto.BadPaddingException
javax.crypto.IllegalBlockSizeException
java.io.IOException

decrypt

public void decrypt(java.io.InputStream in,
                    java.io.OutputStream out)
             throws javax.crypto.NoSuchPaddingException,
                    java.security.NoSuchAlgorithmException,
                    java.security.InvalidKeyException,
                    javax.crypto.BadPaddingException,
                    javax.crypto.IllegalBlockSizeException,
                    java.io.IOException
InputStreamの内容を復号化してOutputStreamに書き出す

パラメータ:
in - 入力
out - 出力
例外:
javax.crypto.NoSuchPaddingException
java.security.NoSuchAlgorithmException
java.security.InvalidKeyException
javax.crypto.BadPaddingException
javax.crypto.IllegalBlockSizeException
java.io.IOException

crypt

private void crypt(int opmode,
                   java.security.Key key,
                   java.io.InputStream in,
                   java.io.OutputStream out)
            throws javax.crypto.NoSuchPaddingException,
                   java.security.NoSuchAlgorithmException,
                   java.security.InvalidKeyException,
                   javax.crypto.BadPaddingException,
                   javax.crypto.IllegalBlockSizeException,
                   java.io.IOException
モードに従って、InputStreamの内容をKeyを用いて、 暗号化/復号化してOutputStreamに書き出す

パラメータ:
opmode - オペレーションモード
key - 秘密鍵
in - 入力
out - 出力
例外:
javax.crypto.NoSuchPaddingException
java.security.NoSuchAlgorithmException
java.security.InvalidKeyException
javax.crypto.BadPaddingException
javax.crypto.IllegalBlockSizeException
java.io.IOException

createDESCryptKey

private javax.crypto.SecretKey createDESCryptKey(byte[] keyMaterial)
                                          throws java.security.InvalidKeyException,
                                                 java.security.NoSuchAlgorithmException,
                                                 java.security.spec.InvalidKeySpecException
DES方式の秘密鍵を生成する

パラメータ:
keyMaterial - キーマテリアル
戻り値:
秘密鍵
例外:
java.security.InvalidKeyException
java.security.NoSuchAlgorithmException
java.security.spec.InvalidKeySpecException

encryptString

public java.lang.String encryptString(java.lang.String str)
                               throws javax.crypto.NoSuchPaddingException,
                                      java.security.NoSuchAlgorithmException,
                                      java.security.InvalidKeyException,
                                      javax.crypto.BadPaddingException,
                                      javax.crypto.IllegalBlockSizeException,
                                      java.io.IOException
文字列のDES暗号化、及びHex変換

パラメータ:
str - 暗号化する文字列
戻り値:
暗号化された文字列
例外:
javax.crypto.NoSuchPaddingException
java.security.NoSuchAlgorithmException
java.security.InvalidKeyException
javax.crypto.BadPaddingException
javax.crypto.IllegalBlockSizeException
java.io.IOException

decryptString

public java.lang.String decryptString(java.lang.String str)
                               throws javax.crypto.NoSuchPaddingException,
                                      java.security.NoSuchAlgorithmException,
                                      java.security.InvalidKeyException,
                                      javax.crypto.BadPaddingException,
                                      javax.crypto.IllegalBlockSizeException,
                                      java.io.IOException
文字列のHex逆変換、及びDES複合化

パラメータ:
str - 複合化する文字列
戻り値:
複合化された文字列
例外:
javax.crypto.NoSuchPaddingException
java.security.NoSuchAlgorithmException
java.security.InvalidKeyException
javax.crypto.BadPaddingException
javax.crypto.IllegalBlockSizeException
java.io.IOException

simpleEncryptString

public java.lang.String simpleEncryptString(java.lang.String str)
                                     throws java.io.IOException
文字列のHex変換

パラメータ:
str - 変換する文字列
戻り値:
変換された文字列
例外:
java.io.IOException

simpleDecryptString

public java.lang.String simpleDecryptString(java.lang.String str)
                                     throws java.io.IOException,
                                            java.lang.ClassNotFoundException
文字列のHex逆変換

パラメータ:
str - 逆変換する文字列
戻り値:
逆変換された文字列
例外:
java.io.IOException
java.lang.ClassNotFoundException

main

public static void main(java.lang.String[] args)
テストメインメソッド

パラメータ:
args - 引数