private static String encodePem(String type, byte[] encoded) { return "-----BEGIN " + type + "-----\n" + getMimeEncoder(64, new byte[] {'\n'}).encodeToString(encoded) + '\n' + "-----END " + type + "-----\n"; } }
public String getPemEncoded() { return "-----BEGIN CERTIFICATE REQUEST-----\n" + getMimeEncoder(64, new byte[] {'\n'}).encodeToString(encoded) + '\n' + "-----END CERTIFICATE REQUEST-----\n"; }
throws Exception byte[] sharedSecret = Base64.getMimeEncoder().encode("test secret".getBytes(US_ASCII)); sharedSecretFile = Files.createTempFile("secret", "txt"); Files.write(sharedSecretFile, sharedSecret);
/** * Set the clipboard text. * * @param text The actual text to be set. */ default void setClipboardText(String text) { setClipboard(ClipboardContentType.PLAINTEXT, Base64 .getMimeEncoder() .encode(text.getBytes(StandardCharsets.UTF_8))); }
/** * Set an URL to the clipboard. * * @param url the actual URL to set. */ default void setClipboardUrl(URL url) { setClipboard(ClipboardContentType.URL, Base64 .getMimeEncoder() .encode(checkNotNull(url).toString().getBytes(StandardCharsets.UTF_8))); }
/** * Set an image to the clipboard. * * @param img the actual image to be set. * @throws IOException if the image cannot be decoded in PNG representation */ default void setClipboardImage(BufferedImage img) throws IOException { try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) { ImageIO.write(checkNotNull(img), "png", os); setClipboard(ClipboardContentType.IMAGE, Base64 .getMimeEncoder() .encode(os.toByteArray())); } }
public AwsProxyRequestBuilder binaryBody(InputStream is) throws IOException { this.request.setIsBase64Encoded(true); return body(Base64.getMimeEncoder().encodeToString(IOUtils.toByteArray(is))); }
private static String encodePem(String type, byte[] encoded) { return "-----BEGIN " + type + "-----\n" + getMimeEncoder(64, new byte[] {'\n'}).encodeToString(encoded) + '\n' + "-----END " + type + "-----\n"; } }
private static String encodePem(String type, byte[] encoded) { return "-----BEGIN " + type + "-----\n" + getMimeEncoder(64, new byte[] {'\n'}).encodeToString(encoded) + '\n' + "-----END " + type + "-----\n"; } }
public String getPemEncoded() { return "-----BEGIN CERTIFICATE REQUEST-----\n" + getMimeEncoder(64, new byte[] {'\n'}).encodeToString(encoded) + '\n' + "-----END CERTIFICATE REQUEST-----\n"; }
public AwsProxyRequestBuilder authorizerPrincipal(String principal) { if (this.request.getRequestSource() == AwsProxyRequest.RequestSource.API_GATEWAY) { if (this.request.getRequestContext().getAuthorizer() == null) { this.request.getRequestContext().setAuthorizer(new ApiGatewayAuthorizerContext()); } this.request.getRequestContext().getAuthorizer().setPrincipalId(principal); if (this.request.getRequestContext().getAuthorizer().getClaims() == null) { this.request.getRequestContext().getAuthorizer().setClaims(new CognitoAuthorizerClaims()); } this.request.getRequestContext().getAuthorizer().getClaims().setSubject(principal); } if (this.request.getRequestSource() == AwsProxyRequest.RequestSource.ALB) { header("x-amzn-oidc-identity", principal); try { header( "x-amzn-oidc-accesstoken", Base64.getMimeEncoder().encodeToString( "test-token".getBytes(ContainerConfig.DEFAULT_CONTENT_CHARSET) ) ); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } return this; }
/** * Calculate mime base64. Return null if bytes is null. */ public static String mimeBase64(byte[] bytes) { if (bytes == null) { return null; } Base64.Encoder encoder = Base64.getMimeEncoder(); return new String(encoder.encode(bytes)); }
public static String encodeToString(byte[] bytes) { if (ignoreLineBreaks) { return Base64.getEncoder().encodeToString(bytes); } return Base64.getMimeEncoder().encodeToString(bytes); }
/** * Set the clipboard text. * * @param text The actual text to be set. */ default void setClipboardText(String text) { setClipboard(ClipboardContentType.PLAINTEXT, Base64 .getMimeEncoder() .encode(text.getBytes(StandardCharsets.UTF_8))); }
/** * Set an URL to the clipboard. * * @param url the actual URL to set. */ default void setClipboardUrl(URL url) { setClipboard(ClipboardContentType.URL, Base64 .getMimeEncoder() .encode(checkNotNull(url).toString().getBytes(StandardCharsets.UTF_8))); }
@Override public AwsProxyResponse writeResponse(AwsHttpServletResponse containerResponse, Context lambdaContext) throws InvalidResponseObjectException { Timer.start("SERVLET_RESPONSE_WRITE"); AwsProxyResponse awsProxyResponse = new AwsProxyResponse(); if (containerResponse.getAwsResponseBodyString() != null) { String responseString; if (!isBinary(containerResponse.getContentType()) && isValidUtf8(containerResponse.getAwsResponseBodyBytes())) { responseString = containerResponse.getAwsResponseBodyString(); } else { responseString = Base64.getMimeEncoder().encodeToString(containerResponse.getAwsResponseBodyBytes()); awsProxyResponse.setBase64Encoded(true); } awsProxyResponse.setBody(responseString); } awsProxyResponse.setMultiValueHeaders(containerResponse.getAwsResponseHeaders()); awsProxyResponse.setStatusCode(containerResponse.getStatus()); if (containerResponse.getAwsProxyRequest().getRequestSource() == AwsProxyRequest.RequestSource.ALB) { awsProxyResponse.setStatusDescription(containerResponse.getStatus() + " " + Response.Status.fromStatusCode(containerResponse.getStatus()).getReasonPhrase()); } Timer.stop("SERVLET_RESPONSE_WRITE"); return awsProxyResponse; }
byte[] bytes = new byte[57]; String enc1 = new sun.misc.BASE64Encoder().encode(bytes); String enc2 = new String(java.util.Base64.getMimeEncoder().encode(bytes), StandardCharsets.UTF_8); System.out.println("enc1 = <" + enc1 + ">"); System.out.println("enc2 = <" + enc2 + ">"); System.out.println(enc1.equals(enc2));
private static String createPlainTextResponse() { Random r = new Random(); byte[] b = new byte[1500]; r.nextBytes(b); return java.util.Base64.getMimeEncoder().encodeToString(b); }
private static String createPlainTextResponse() { Random r = new Random(); byte[] b = new byte[1500]; r.nextBytes(b); return java.util.Base64.getMimeEncoder().encodeToString(b); }
private static String createPlainTextResponse() { Random r = new Random(); byte[] b = new byte[1500]; r.nextBytes(b); return java.util.Base64.getMimeEncoder().encodeToString(b).intern(); }