/** * Encodes an entire byte array into a Base64 string, with optional newlines * after every 76 characters. * * @param bytes * The byte array to encode. * @param newlines * Indicates whether or not newlines are desired. * @return The encoded string. */ public static String encode(byte[] bytes, boolean newlines) { return encode(bytes, 0, bytes.length, newlines); }
/** * Encodes an entire byte array into a Base64 string, with optional newlines * after every 76 characters. * * @param bytes * The byte array to encode. * @param newlines * Indicates whether or not newlines are desired. * @return The encoded string. */ public static String encode(byte[] bytes, boolean newlines) { return encode(bytes, 0, bytes.length, newlines); }
/** * Encodes an entire chars array into a Base64 string, with optional * newlines after every 76 characters. * * @param chars * The characters array to encode. * @param newlines * Indicates whether or not newlines are desired. * @return The encoded string. */ public static String encode(char[] chars, boolean newlines) { return encode(/*IoUtils.*/toByteArray(chars), newlines); }
/** * Encodes an entire chars array into a Base64 string, with optional * newlines after every 76 characters. * * @param chars * The characters array to encode. * @param newlines * Indicates whether or not newlines are desired. * @return The encoded string. */ public static String encode(char[] chars, boolean newlines) { return encode(IoUtils.toByteArray(chars), newlines); }
/** * Encodes an entire chars array into a Base64 string, with optional * newlines after every 76 characters. * * @param chars * The characters array to encode. * @param charset * The character set to use for the character to byte conversion. * @param newlines * Indicates whether or not newlines are desired. * @return The encoded string. */ public static String encode(char[] chars, String charset, boolean newlines) { return encode(IoUtils.toByteArray(chars, charset), newlines); }
/** * Encodes an entire chars array into a Base64 string, with optional * newlines after every 76 characters. * * @param chars * The characters array to encode. * @param charset * The character set to use for the character to byte conversion. * @param newlines * Indicates whether or not newlines are desired. * @return The encoded string. */ public static String encode(char[] chars, String charset, boolean newlines) { return encode(/*IoUtils.*/toByteArray(chars, charset), newlines); }
/** * Generates a nonce as recommended in section 3.2.1 of RFC-2617, but * without the ETag field. The format is: <code><pre> * Base64.encodeBytes(currentTimeMS + ":" * + md5String(currentTimeMS + ":" + secretKey)) * </pre></code> * * @param secretKey * a secret value known only to the creator of the nonce. It's * inserted into the nonce, and can be used later to validate the * nonce. */ public static String makeNonce(String secretKey) { final long currentTimeMS = System.currentTimeMillis(); return Base64.encode( (currentTimeMS + ":" + DigestUtils.toMd5(currentTimeMS + ":" + secretKey)).getBytes(), true); }
@Override public void formatResponse(ChallengeWriter cw, ChallengeResponse challenge, Request request, Series<Header> httpHeaders) { try { final CharArrayWriter credentials = new CharArrayWriter(); credentials.write("^@"); credentials.write(challenge.getIdentifier()); credentials.write("^@"); credentials.write(challenge.getSecret()); cw.append(Base64.encode(credentials.toCharArray(), "US-ASCII", false)); } catch (UnsupportedEncodingException e) { throw new RuntimeException( "Unsupported encoding, unable to encode credentials"); } catch (IOException e) { throw new RuntimeException( "Unexpected exception, unable to encode credentials", e); } }
private StringRepresentation generateEncodedImage( String layer, int width, int height, boolean renderHorizontally, JSONObject query ) { try { BufferedImage tile = _service.getLegend( layer, width, height, renderHorizontally, query ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(tile, "png", baos); baos.flush(); String encodedImage = Base64.encode(baos.toByteArray(), true); baos.close(); encodedImage = "data:image/png;base64," + URLEncoder.encode(encodedImage, "ISO-8859-1"); return new StringRepresentation( encodedImage ); } catch (IOException e) { throw new ResourceException(Status.CONNECTOR_ERROR_INTERNAL, "Unable to encode legend image.", e); } } }
@Override public void formatResponse(ChallengeWriter cw, ChallengeResponse challenge, Request request, Series<Header> httpHeaders) { try { if (challenge == null) { throw new RuntimeException( "No challenge provided, unable to encode credentials"); } else { CharArrayWriter credentials = new CharArrayWriter(); credentials.write(challenge.getIdentifier()); credentials.write(":"); credentials.write(challenge.getSecret()); cw.append(Base64.encode(credentials.toCharArray(), "ISO-8859-1", false)); } } catch (UnsupportedEncodingException e) { throw new RuntimeException( "Unsupported encoding, unable to encode credentials"); } catch (IOException e) { throw new RuntimeException( "Unexpected exception, unable to encode credentials", e); } }
private String setupState(Response response) { String sessionId = UUID.randomUUID().toString(); byte[] secret = new byte[20]; random.nextBytes(secret); String state = Base64.encode(secret, false); CookieSetting cs = new CookieSetting("_state", sessionId); response.getCookieSettings().add(cs); getContext().getAttributes().put(sessionId, state); return state; }
clientSecret = Base64.encode(secret, false).toCharArray();
clientSecret = Base64.encode(secret, false).toCharArray();
sb.append(isb); return Base64.encode( CryptoUtils.encrypt(this.getEncryptAlgorithm(), this.getEncryptSecretKey(), sb.toString()), false);
addHeader( HEADER_CONTENT_MD5, new String(org.restlet.engine.util.Base64.encode(entity .getDigest().getValue(), false)), headers);