kr.co.hit.live.security.codec
Class CipherHelper

java.lang.Object
  extended by kr.co.hit.live.security.codec.CipherHelper

public class CipherHelper
extends Object

암호문 작성 관련 기능을 제공하는 유틸리티 클래스이다.

암호화/복호화를 하기 위한 암호키는 다음과 같은 방식으로 생성할 수 있다.

     // RSA Asymmetric key
     KeyPair keyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair();
 
     PublicKey pubKey = keyPair.getPublic();
     PrivateKey priKey = keyPair.getPrivate();
 
     // DES
     SecretKey desKey = KeyGenerator.getInstance("DES").generateKey();
 
     // Blowfish
     SecretKey blowfishKey = KeyGenerator.getInstance("Blowfish").generateKey();
 
     // Triple DES
     SecretKey desedeKey = KeyGenerator.getInstance("DESede").generateKey();
 

Author:
kimhd

Constructor Summary
CipherHelper()
           
 
Method Summary
static byte[] decode(String s, long kk)
           
static byte[] decode(String s, String kk)
          암호화된 문자열을 원래 데이터로 복호화한다.
static PrivateKey decodePrivateKey(byte[] encodedKey)
          인코딩되어 있는 byte[]로부터 RSA용 개인키 객체를 가져온다.
static PublicKey decodePublicKey(byte[] encodedKey)
          인코딩되어 있는 byte[]로부터 RSA용 공개키 객체를 가져온다.
static SecretKey decodeSecretKey(byte[] encodedKey, String algorithm)
          대칭키 방식용 키 객체를 생성한다.
static byte[] decrypt(byte[] input, Key key, String algorithm)
          주어진 key를 사용하여 암호문을 푼다.
static String encode(byte[] b, long kk)
           
static String encode(byte[] b, String kk)
          byte[]를 문자열을 자체 암호문으로 인코딩한다.
static byte[] encode(Key key)
          Key 객체를 byte[]로 반환한다.
static String encode(String s, long kk)
           
static String encode(String s, String kk)
           
static byte[] encrypt(byte[] input, Key key, String algorithm)
          주어진 key를 사용하여 평문을 암호화한다.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CipherHelper

public CipherHelper()
Method Detail

encode

public static byte[] encode(Key key)
Key 객체를 byte[]로 반환한다.

Parameters:
key -
Returns:

decodePrivateKey

public static PrivateKey decodePrivateKey(byte[] encodedKey)
                                   throws GeneralSecurityException
인코딩되어 있는 byte[]로부터 RSA용 개인키 객체를 가져온다.

Parameters:
encodedKey -
Returns:
Throws:
GeneralSecurityException

decodePublicKey

public static PublicKey decodePublicKey(byte[] encodedKey)
                                 throws GeneralSecurityException
인코딩되어 있는 byte[]로부터 RSA용 공개키 객체를 가져온다.

Parameters:
encodedKey -
Returns:
Throws:
GeneralSecurityException

decodeSecretKey

public static SecretKey decodeSecretKey(byte[] encodedKey,
                                        String algorithm)
                                 throws GeneralSecurityException
대칭키 방식용 키 객체를 생성한다.

Parameters:
encodedKey -
algorithm - 적용 알고리즘
Returns:
Throws:
GeneralSecurityException

encrypt

public static byte[] encrypt(byte[] input,
                             Key key,
                             String algorithm)
                      throws GeneralSecurityException
주어진 key를 사용하여 평문을 암호화한다. 비대칭암호인 경우에는 공개키를 사용하여야 한다.

Parameters:
input -
key -
algorithm -
Returns:
Throws:
GeneralSecurityException

decrypt

public static byte[] decrypt(byte[] input,
                             Key key,
                             String algorithm)
                      throws GeneralSecurityException
주어진 key를 사용하여 암호문을 푼다. 비대칭암호인 경우에는 개인키를 사용하여야 한다.

Parameters:
input -
key -
algorithm -
Returns:
Throws:
GeneralSecurityException

encode

public static String encode(byte[] b,
                            String kk)
byte[]를 문자열을 자체 암호문으로 인코딩한다.

Parameters:
b -
kk - 암호키
Returns:

encode

public static String encode(byte[] b,
                            long kk)

encode

public static String encode(String s,
                            String kk)

encode

public static String encode(String s,
                            long kk)

decode

public static byte[] decode(String s,
                            String kk)
암호화된 문자열을 원래 데이터로 복호화한다.

Parameters:
s -
kk -
Returns:

decode

public static byte[] decode(String s,
                            long kk)


Copyright © 2014. All Rights Reserved.