@Test public void testIncorrectPassword() throws Exception { CloseableHttpClient httpclient = null; try { String username = "user1"; String password = "aaaa"; httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet("http://" + host + ":" + webUIPort); String authB64Code = B64Code.encode(username + ":" + password, StringUtil.__ISO_8859_1); httpGet.setHeader(HttpHeader.AUTHORIZATION.asString(), "Basic " + authB64Code); CloseableHttpResponse response = httpclient.execute(httpGet); Assert.assertTrue(response.toString().contains(Integer.toString(HttpURLConnection.HTTP_UNAUTHORIZED))); } finally { if (httpclient != null) { httpclient.close(); } } }
if ("basic".equalsIgnoreCase(method)) { credentials = credentials.substring(space + 1); credentials = B64Code.decode(credentials, StandardCharsets.ISO_8859_1); int i = credentials.indexOf(':'); if (i > 0) {
public static byte[] decodeRFC4648URL(String encoded) { if (encoded==null) return null; ByteArrayOutputStream bout = new ByteArrayOutputStream(4*encoded.length()/3); decodeRFC4648URL(encoded, bout); return bout.toByteArray(); }
@Test public void testIncorrectUser() throws Exception { CloseableHttpClient httpclient = null; try { String username = "nouser"; String password = "aaaa"; httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet("http://" + host + ":" + webUIPort); String authB64Code = B64Code.encode(username + ":" + password, StringUtil.__ISO_8859_1); httpGet.setHeader(HttpHeader.AUTHORIZATION.asString(), "Basic " + authB64Code); CloseableHttpResponse response = httpclient.execute(httpGet); Assert.assertTrue(response.toString().contains(Integer.toString(HttpURLConnection.HTTP_UNAUTHORIZED))); } finally { if (httpclient != null) { httpclient.close(); } } }
/** * Base 64 decode as described in RFC 2045. * <p>Unlike {@link #decode(char[])}, extra whitespace is ignored. * @param encoded String to decode. * @return byte array containing the decoded form of the input. * @throws IllegalArgumentException if the input is not a valid * B64 encoding. */ public static byte[] decode(String encoded) { if (encoded==null) return null; ByteArrayOutputStream bout = new ByteArrayOutputStream(4*encoded.length()/3); decode(encoded, bout); return bout.toByteArray(); }
public static byte[] decodeRFC4648URL(String encoded) { if (encoded==null) return null; ByteArrayOutputStream bout = new ByteArrayOutputStream(4*encoded.length()/3); decodeRFC4648URL(encoded, bout); return bout.toByteArray(); }
@Test public void testAuthorizedConnection() throws Exception { CloseableHttpClient httpclient = null; try { String username = "user1"; String password = "1"; httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet("http://" + host + ":" + webUIPort); String authB64Code = B64Code.encode(username + ":" + password, StringUtil.__ISO_8859_1); httpGet.setHeader(HttpHeader.AUTHORIZATION.asString(), "Basic " + authB64Code); CloseableHttpResponse response = httpclient.execute(httpGet); Assert.assertTrue(response.toString().contains(Integer.toString(HttpURLConnection.HTTP_OK))); } finally { if (httpclient != null) { httpclient.close(); } } }
/** * Base 64 decode as described in RFC 2045. * <p>Unlike {@link #decode(char[])}, extra whitespace is ignored. * @param encoded String to decode. * @param charEncoding Character encoding * used to map the decoded bytes into a String. If null * the platforms default charset is used. * @return String decoded byte array. * @throws IllegalArgumentException if the input is not a valid * B64 encoding. */ @SuppressWarnings("DefaultCharset") public static String decode(String encoded, Charset charEncoding) { byte[] decoded=decode(encoded); if (charEncoding==null) return new String(decoded); return new String(decoded, charEncoding); }
/** * Base 64 encode as described in RFC 1421. * <p>Does not insert whitespace as described in RFC 1521. * @param s String to encode. * @return String containing the encoded form of the input. */ public static String encode(String s) { return encode(s, (Charset)null); }
/** * Base 64 decode as described in RFC 2045. * <p>Unlike {@link #decode(char[])}, extra whitespace is ignored. * @param encoded String to decode. * @param charEncoding String representing the character encoding * used to map the decoded bytes into a String. If null * the platforms default charset is used. * @return String decoded byte array. * @throws UnsupportedCharsetException if the encoding is not supported * @throws IllegalArgumentException if the input is not a valid * B64 encoding. */ @SuppressWarnings("DefaultCharset") public static String decode(String encoded,String charEncoding) { byte[] decoded=decode(encoded); if (charEncoding==null) return new String(decoded); return new String(decoded,Charset.forName(charEncoding)); }
/** * Base 64 encode as described in RFC 1421. * <p>Does not insert whitespace as described in RFC 1521. * @param s String to encode. * @param charEncoding The character encoding of the provided input String. * @return String containing the encoded form of the input. */ public static String encode(String s, Charset charEncoding) { byte[] bytes=s.getBytes(charEncoding==null ? StandardCharsets.ISO_8859_1 : charEncoding); return new String(encode(bytes)); }
@Override public int read() throws IOException { if (_buffer==null || _pos>= _buffer.length) { //Any CR and LF will be consumed by the readLine() call. //We need to put them back into the bytes returned from this //method because the parsing of the multipart content uses them //as markers to determine when we've reached the end of a part. _line = _in.readLine(); if (_line==null) return -1; //nothing left if (_line.startsWith("--")) _buffer=(_line+"\r\n").getBytes(); //boundary marking end of part else if (_line.length()==0) _buffer="\r\n".getBytes(); //blank line else { ByteArrayOutputStream baos = new ByteArrayOutputStream((4*_line.length()/3)+2); B64Code.decode(_line, baos); baos.write(13); baos.write(10); _buffer = baos.toByteArray(); } _pos=0; } return _buffer[_pos++]; } }
return null; if (!rfc2045) return encode(b);
credentials = B64Code.decode(credentials, StandardCharsets.ISO_8859_1); int i = credentials.indexOf(':'); if (i>0)
/** * Base 64 encode as described in RFC 1421. * <p>Does not insert whitespace as described in RFC 1521. * @param s String to encode. * @param charEncoding String representing the name of * the character encoding of the provided input String. * @return String containing the encoded form of the input. */ public static String encode(String s,String charEncoding) { byte[] bytes; if (charEncoding==null) bytes=s.getBytes(StandardCharsets.ISO_8859_1); else bytes=s.getBytes(Charset.forName(charEncoding)); return new String(encode(bytes)); }
public byte[] getToken() { if ( _token == null ) { _token = B64Code.decode(_encodedToken); } return _token; }
public String newNonce(Request request) { Nonce nonce; do { byte[] nounce = new byte[24]; _random.nextBytes(nounce); nonce = new Nonce(new String(B64Code.encode(nounce)), request.getTimeStamp(), getMaxNonceCount()); } while (_nonceMap.putIfAbsent(nonce._nonce, nonce) != null); _nonceQueue.add(nonce); return nonce._nonce; }
public byte[] getToken() { if ( _token == null ) { _token = B64Code.decode(_encodedToken); } return _token; }
public String getWeakETag(String suffix) { try { StringBuilder b = new StringBuilder(32); b.append("W/\""); String name=getName(); int length=name.length(); long lhash=0; for (int i=0; i<length;i++) lhash=31*lhash+name.charAt(i); B64Code.encode(lastModified()^lhash,b); B64Code.encode(length()^lhash,b); b.append(suffix); b.append('"'); return b.toString(); } catch (IOException e) { throw new RuntimeException(e); } }
public byte[] getToken() { if ( _token == null ) { _token = B64Code.decode(_encodedToken); } return _token; }