'RSA'에 해당되는 글 1건

  1. 2009.02.16 hex string <-> byte array 변환 7

1. hex string -> byte array

byte[] bytes = new java.math.BigInteger(hexText, 16).toByteArray();


2. byte array -> hex string

String hexText = new java.math.BigInteger(bytes).toString(16);


아래처럼 머리 아픈 코드를 안봐도 되니 편하네요. thanks BigInteger! ^^

    public static String toHexString(byte buf[]){
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < buf.length; i++) {
            sb.append(Integer.toHexString(0x0100 + (buf[i] & 0x00FF)).substring(1));
        }
        return sb.toString();
    }

Posted by 에코지오
,