List of usage examples for java.util Base64 getEncoder
public static Encoder getEncoder()
From source file:org.hyperledger.fabric_ca.sdk.HFCAClient.java
String getHTTPAuthCertificate(Enrollment enrollment, String method, String url, String body) throws Exception { Base64.Encoder b64 = Base64.getEncoder(); String cert = b64.encodeToString(enrollment.getCert().getBytes(UTF_8)); body = b64.encodeToString(body.getBytes(UTF_8)); String signString;//from w ww . j a va 2s .c om // Cache the version, so don't need to make info call everytime the same client is used if (newPayloadType == null) { newPayloadType = true; // If CA version is less than 1.4.0, use old payload String caVersion = info().getVersion(); logger.info(format("CA Version: %s", caVersion)); if (Utils.isNullOrEmpty(caVersion)) { newPayloadType = false; } String version = caVersion + "."; if (version.startsWith("1.1.") || version.startsWith("1.2.") || version.startsWith("1.3.")) { newPayloadType = false; } } if (newPayloadType) { url = addCAToURL(url); String file = b64.encodeToString(new URL(url).getFile().getBytes(UTF_8)); signString = method + "." + file + "." + body + "." + cert; } else { signString = body + "." + cert; } byte[] signature = cryptoSuite.sign(enrollment.getKey(), signString.getBytes(UTF_8)); return cert + "." + b64.encodeToString(signature); }
From source file:org.sakaiproject.contentreview.turnitin.oc.ContentReviewServiceTurnitinOC.java
public static String base64Encode(String src) { return Base64.getEncoder().encodeToString(src.getBytes()); }
From source file:com.amalto.workbench.utils.Util.java
public static String getResponseFromURL(String url, TreeObject treeObj) throws Exception { InputStreamReader doc = null; try {/*from ww w .j a v a 2 s.c o m*/ Encoder encoder = Base64.getEncoder(); StringBuffer buffer = new StringBuffer(); String credentials = encoder.encodeToString((new String(treeObj.getServerRoot().getUsername() + ":"//$NON-NLS-1$ + treeObj.getServerRoot().getPassword()).getBytes())); URL urlCn = new URL(url); URLConnection conn = urlCn.openConnection(); conn.setAllowUserInteraction(true); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestProperty("Authorization", "Basic " + credentials);//$NON-NLS-1$//$NON-NLS-2$ conn.setRequestProperty("Expect", "100-continue");//$NON-NLS-1$//$NON-NLS-2$ doc = new InputStreamReader(conn.getInputStream()); BufferedReader reader = new BufferedReader(doc); String line = reader.readLine(); while (line != null) { buffer.append(line); line = reader.readLine(); } return buffer.toString(); } finally { if (doc != null) { doc.close(); } } }