==[[Java Base64のデコード]]==
====MimeUtilityを利用====
[[Java]] | {{category [[Category:コード片}}]]
<blockquote>Java8から標準ライブラリに含まれた[[Java]]8から標準ライブラリに含まれた</blockquote>
*http://java.sun.com/j2ee/1.4/docs/api/javax/mail/internet/MimeUtility.html
=====サーブレットフィルターで、Base64エンコードされたBasic認証情報を取得する例=====
public void doFilter(ServletRequest Servlet[[R]]equest request, ServletResponse Servlet[[R]]esponse response, FilterChain filterChain) throws IOException, ServletException {
ByteArrayInputStream bin = null;
BufferedReader Buffered[[R]]eader br = null;
try {
HttpServletRequest httpReq HttpServlet[[R]]equest http[[R]]eq = (HttpServletRequestHttpServlet[[R]]equest)request;
String basicAuthData = httpReq.getHeaderget[[Header]]("authorization"); String basicAuthBody = basicAuthData.substring(6); // ex 'Basic dG9tY2F0OnRvbWNhdAdG9tY2F0On[[R]]vbWNhdA== '
bin = new ByteArrayInputStream(basicAuthBody.getBytes());
br = new BufferedReaderBuffered[[R]]eader( new InputStreamReaderInputStream[[R]]eader(MimeUtility.decode(bin,"base64")));
StringBuilder buf = new StringBuilder();