List of usage examples for java.util Base64 getEncoder
public static Encoder getEncoder()
From source file:org.apache.sling.sli.SubCommand.java
public void execute() throws Exception { Config cfg = sli.getConfig();//from ww w . j a va 2 s . co m URL url = new URL(cfg.getProtocol(), cfg.getHostName(), cfg.getPort(), getURI()); URLConnection connection = url.openConnection(); String decodedAuth = cfg.getUser() + ":" + cfg.getPassword(); String basicAuth = "Basic " + new String(Base64.getEncoder().encode(decodedAuth.getBytes())); connection.setRequestProperty("Authorization", basicAuth); JSONParser parser = new JSONParser(); InputStream response = connection.getInputStream(); computeJSON(parser.parse(new BufferedReader(new InputStreamReader(response)))); }
From source file:de.kaiserpfalzEdv.commons.encoding.EncodingHelper.java
/** * Encodes the serializable object into a BASE64 encoded string. * * @param obj The object to be serialized * @return The BASE64 encoded string containing the object. * @throws EncodingException If an {@link IOException} has been thrown. *//*from w ww . j ava 2s. com*/ public static String encode(final Serializable obj) { LOG.trace("Trying to encode: {}", obj); checkArgument(obj != null, "Can't encode a null!"); String out = Base64.getEncoder().encodeToString(SerializationUtils.serialize(obj)); LOG.debug("Encoded serializable object. Now returning string containing BASE64 encoded object ..."); return out; }
From source file:com.googlesource.gerrit.plugins.its.jira.restapi.JiraRestApi.java
private static String encode(String user, String pass) { return Base64.getEncoder().encodeToString((user + ":" + pass).getBytes()); }
From source file:com.github.ffremont.microservices.springboot.node.security.BasicAuthorizationInterceptor.java
@Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { byte[] token = Base64.getEncoder().encode((this.username + ":" + this.password).getBytes()); request.getHeaders().add("Authorization", "Basic " + new String(token)); return execution.execute(request, body); }
From source file:org.hyperledger.jackson.ScriptSerializer.java
@Override public void serialize(Script value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeString(Base64.getEncoder().encodeToString(value.toByteArray())); }
From source file:tk.jomp16.plugin.codecutils.ui.EncodeDecodePanel.java
public EncodeDecodePanel(boolean encode) { base64Button.addActionListener(e -> { if (encode) { if (inputTextArea.getText().length() != 0) outputTextArea//from w ww . ja v a2s . co m .setText(new String(Base64.getEncoder().encode(inputTextArea.getText().getBytes()))); } else { if (inputTextArea.getText().length() != 0) outputTextArea.setText(new String(Base64.getDecoder().decode(inputTextArea.getText()))); } }); hexadecimalButton.addActionListener(e -> { if (encode) { if (inputTextArea.getText().length() != 0) outputTextArea.setText(String.valueOf(Hex.encodeHex(inputTextArea.getText().getBytes()))); } else { if (inputTextArea.getText().length() != 0) { try { outputTextArea.setText(new String(Hex.decodeHex(inputTextArea.getText().toCharArray()))); } catch (DecoderException e1) { e1.printStackTrace(); } } } }); binaryButton.addActionListener(e -> { if (encode) { if (inputTextArea.getText().length() != 0) outputTextArea.setText(CodecUtils.getBinary(inputTextArea.getText())); } else { if (inputTextArea.getText().length() != 0) outputTextArea.setText( new String(BinaryCodec.fromAscii(inputTextArea.getText().replace(" ", "").getBytes()))); } }); }
From source file:ai.susi.tools.JsonSignature.java
/** * Create and add a signature to a JSONObject * @param obj the JSONObject/*from w w w . ja v a 2s .com*/ * @param key the private key to use * @throws InvalidKeyException if the key is not valid (for example not RSA) * @throws SignatureException if something with the JSONObject is bogus */ public static void addSignature(JSONObject obj, PrivateKey key) throws InvalidKeyException, SignatureException { removeSignature(obj); Signature signature; try { signature = Signature.getInstance("SHA256withRSA"); } catch (NoSuchAlgorithmException e) { return; //does not happen } signature.initSign(key); signature.update(obj.toString().getBytes(StandardCharsets.UTF_8)); byte[] sigBytes = signature.sign(); obj.put(signatureString, new String(Base64.getEncoder().encode(sigBytes))); }
From source file:com.searchcode.app.util.AESEncryptor.java
public String encryptToBase64String(String plainText) throws Exception { byte[] cipherText = this.encrypt(plainText.getBytes()); return new String(Base64.getEncoder().encode(cipherText)); }
From source file:com.thoughtworks.go.websocket.MessageEncoding.java
public static String encodeWork(Work work) { try {//from w w w . jav a2s .com try (ByteArrayOutputStream binaryOutput = new ByteArrayOutputStream()) { try (ObjectOutputStream objectStream = new ObjectOutputStream(binaryOutput)) { objectStream.writeObject(work); } return Base64.getEncoder().encodeToString(binaryOutput.toByteArray()); } } catch (IOException e) { throw bomb(e); } }
From source file:org.apache.james.util.SerializationUtil.java
/** * Serialize the input object using standard mechanisms then encodes result using base64 encoding. * * @param obj The object that needs to be serialized. * * @return The base64 representation of {@code obj}. *///from w w w . j av a2s. c o m public static String serialize(Serializable obj) { return Optional.ofNullable(obj).map(SerializationUtils::serialize).map(Base64.getEncoder()::encodeToString) .orElse(null); }