- 암호화 -
public final static String encodeSun(byte[] str) {

        String b64enc="";
        sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
        b64enc  = encoder.encode(str);

        return b64enc;
 }


- 복호화 -
 public final static byte[] decodeSun(String str) {

  byte[] b64dec = null;

  try {

       sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
       b64dec = decoder.decodeBuffer(str);

  } catch (IOException ex) { }
        return b64dec;
 }


======================================================================



-jsp-
<script type="text/javascript" language="javascript" src="${contextPath }/js/base64.js"></script>
form.s_pw1.value = "1234";
form.s_pw2.value = Base64.encode(s_pw1);
-java-
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
BASE64Decoder decoder = new BASE64Decoder();
String pw1 = new String(request.getParameter("pw1"));
String pw2 = new String(request.getParameter("pw2"));
String pw3 = new String(decoder.decodeBuffer(request.getParameter("pw2")));
BASE64Encoder encoder = new BASE64Encoder();
String pw = encoder.encode(decoder.decodeBuffer(request.getParameter("pw2")));

'Java' 카테고리의 다른 글

[Java] Java - Jabook.chm 문서  (0) 2011.05.17
[Java] DES, TripleDES 암.복호화  (0) 2011.03.24
[Java] Base64 - 1  (0) 2011.03.24
[Java] java warning: no definition of serialVersionUID  (0) 2011.03.02
[Java] JDBC -> Java DataBase Connection  (0) 2011.03.02

+ Recent posts