passwd 암호화

 | JAVA
2012. 5. 15. 18:33

 

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *
 *
 * @author
 */
public class strEnDeConvert {

    private  byte[] hexaMap = {0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68};

    protected  byte[] getHexaEncodingBytes(byte[] src)
 {
        byte[] buffer=new byte[src.length*2];
        int index=0;

  System.out.println("src.length="+ src.length);  

        for (int i=0; i < src.length; i++)
  {   buffer[index++] = hexaMap[ ( (src[i]&0xf0) >> 4 ) ];
            buffer[index++] = hexaMap[ ( src[i]&0x0f ) ];
        }
  return buffer;
    }

    protected  String getHexaEncoding(byte[] src,String charSet) throws UnsupportedEncodingException
 {
        byte[] strBytes=getHexaEncodingBytes(src);
        return new String(strBytes,charSet);
    }

    protected  String getHexaEncoding(byte[] src)
 {
        byte[] strBytes=getHexaEncodingBytes(src);
        return new String(strBytes);
    }

    /**
     * Digest 알고리즘을 수행한다.
     */
    public String getDigest(String str, String digest, String charset) {
        try
  {   MessageDigest md = MessageDigest.getInstance(digest);
            try
   {   byte[]      raw = str.getBytes(charset);
                byte[] digested = md.digest(raw);
                System.out.println("digested.length="+ digested.length); 
    System.out.println("str.length="+ str.length());

    return getHexaEncoding(digested, charset);
            } catch (UnsupportedEncodingException e) {
            } 
  } catch (NoSuchAlgorithmException e) {
        }       
        return str;
    }
 
 // Test
 public static void main(String[] args) throws Exception
 {
  strEnDeConvert ec = new strEnDeConvert();
  Defines        df = new Defines();
  System.out.println(ec.getDigest("1111122222333334445",df.PASSWORD_DIGEST, df.PASSWORD_CHARSET));
 }

}

 

이 글은 스프링노트에서 작성되었습니다.

'JAVA' 카테고리의 다른 글

SMS 보내기  (0) 2012.05.15
Printf 수식 모음  (0) 2012.05.15
OS CPU MEMORY 값 보여주기  (0) 2012.05.15
유니코드 표  (0) 2012.05.08
SqlExploler(eclipse)  (0) 2012.05.08
Posted by 사라링
BLOG main image
.. by 사라링

카테고리

사라링님의 노트 (301)
JSP (31)
J-Query (41)
JAVA (24)
VM-WARE (0)
디자인패턴 (1)
스크랩 (0)
스트러츠 (3)
안드로이드 (11)
오라클 (45)
우분투-오라클 (1)
이클립스메뉴얼 (6)
스프링3.0 (23)
자바스크립트 (10)
HTML5.0 (17)
정보처리기사 (1)
기타(컴퓨터 관련) (1)
문제점 해결 (3)
프로젝트 (2)
AJAX (4)
하이버네이트 (3)
트러스트폼 (11)
Jeus (2)
재무관리(회계) (5)
정규식 (5)
아이바티스 (8)
취미 (2)
소프트웨어 보안 관련모음 (0)
정보보안기사 (6)
C언어 베이직 및 프로그램 (3)
보안 관련 용어 정리 (2)
넥사크로 (6)
Total :
Today : Yesterday :