protected static String toBase64(byte[] bytes) { return new String(Base64Encoder.encode(bytes)); }
/** * Encodes a String into a base 64 String. The resulting encoding is chunked at 76 bytes. * <p/> * * @param s String to encode. * @return encoded string. */ public static String encode(String s) { byte[] sBytes = s.getBytes(); sBytes = encode(sBytes); s = new String(sBytes); return s; }
/** * Encodes a String into a base 64 String. The resulting encoding is chunked at 76 bytes. * <p/> * * @param s String to encode. * @return encoded string. */ public static String encode(String s) { byte[] sBytes = s.getBytes(); sBytes = encode(sBytes); s = new String(sBytes); return s; }
/** * Encodes a String into a base 64 String. The resulting encoding is chunked at 76 bytes. * <p/> * * @param s String to encode. * @return encoded string. */ public static String encode(String s) { return shouldEncodePassword(s) ? PREFIX + Base64Encoder.encode(s) : s; }
/** * Encodes a String into a base 64 String. The resulting encoding is chunked at 76 bytes. * <p/> * * @param s String to encode. * @return encoded string. */ public static String encode(String s) { return shouldEncodePassword(s) ? PREFIX + Base64Encoder.encode(s) : s; }
@Override public String generate() { try { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(512); byte[] publicKey = keyGen.genKeyPair().getPublic().getEncoded(); return new String(Base64Encoder.encode(publicKey)); } catch (Throwable t) { throw new RuntimeException(t); } } },
@Override public String generate() { try { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(512); byte[] publicKey = keyGen.genKeyPair().getPublic().getEncoded(); return new String(Base64Encoder.encode(publicKey)); } catch (Throwable t) { throw new RuntimeException(t); } } };
/** * Prepares an url connection for authentication if necessary. * * @param connection the connection to be prepared * * @return the prepared conection */ public static URLConnection prepareForAuthentication(final URLConnection connection) { NullArgumentException.validateNotNull(connection, "url connection cannot be null"); if (connection.getURL().getUserInfo() != null) { // Need to decode username/password because it may contain encoded // characters (http://www.w3schools.com/tags/ref_urlencode.asp) // A common encoding is to provide a username as an email address // like user%40domain.org String decodedUserInfo = decode(connection.getURL().getUserInfo()); String base64Encoded = io.fabric8.utils.Base64Encoder.encode(decodedUserInfo); // sun bug 6459815: Long passwords cause Basic Auth to fail with a // java.net.Authenticator base64Encoded = base64Encoded.replaceAll("\n", ""); connection.setRequestProperty("Authorization", "Basic " + base64Encoded); } return connection; }
URLConnection connection = url.openConnection(); connection.setDoOutput(true); connection.setRequestProperty("Authorization", "Basic " + Base64Encoder.encode(user + ":" + password)); WritableByteChannel out = Channels.newChannel(connection.getOutputStream()); in.transferTo(0, fileToUpload.length(), out);
byte[] metadataPayload = ObjectUtils.toBytes(metadata); if (metadataPayload != null && metadataPayload.length > 0) { sb.append("copy_node_metadata ").append(name).append(" ").append(new String(Base64Encoder.encode(metadataPayload))).append("\n");
con.setRequestProperty("Authorization", "Basic " + Base64Encoder.encode(login + ":" + password));
byte[] encoded = Base64Encoder.encode(bytes);
@Override public void setContainerMetadata(CreateContainerMetadata metadata) { assertValid(); //We encode the metadata so that they are more friendly to import/export. try { setData(curator.get(), ZkPath.CONTAINER_METADATA.getPath(metadata.getContainerName()), Base64Encoder.encode(ObjectUtils.toBytes(metadata))); } catch (Exception e) { throw FabricException.launderThrowable(e); } }