Refine search
/** * Base64-encode the given byte array. * @param src the original byte array * @return the encoded byte array */ public static byte[] encode(byte[] src) { if (src.length == 0) { return src; } return Base64.getEncoder().encode(src); }
String toMessage() { if (error != null) return "e=" + error; else return "v=" + Base64.getEncoder().encodeToString(serverSignature); } }
public String hmacAsBase64String() { return Base64.getEncoder().encodeToString(hmac); }
public String clientFinalMessageWithoutProof() { return String.format("c=%s,r=%s", Base64.getEncoder().encodeToString(channelBinding), nonce); } String toMessage() {
@Override public void serialize(byte[] value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeString(Base64.getEncoder().encodeToString(value)); } }
String toMessage() { return String.format("r=%s,s=%s,i=%d", nonce, Base64.getEncoder().encodeToString(salt), iterations); } }
/** * Base64-encode the given byte array. * @param src the original byte array * @return the encoded byte array */ public static byte[] encode(byte[] src) { if (src.length == 0) { return src; } return Base64.getEncoder().encode(src); }
public static String encodeViewData(String data) { return VIEW_PREFIX + Base64.getEncoder().encodeToString(data.getBytes(UTF_8)) + VIEW_SUFFIX; }
/** * Add a binary value to the JSON array. * <p> * JSON has no notion of binary so the binary will be base64 encoded to a String, and the String added. * * @param value the value * @return a reference to this, so the API can be used fluently */ public JsonArray add(byte[] value) { Objects.requireNonNull(value); list.add(Base64.getEncoder().encodeToString(value)); return this; }
// create new key SecretKey secretKey = KeyGenerator.getInstance("AES").generateKey(); // get base64 encoded version of the key String encodedKey = Base64.getEncoder().encodeToString(secretKey.getEncoded());
/** * Put a byte[] into the JSON object with the specified key. * <p> * JSON extension RFC7493, binary will first be Base64 encoded before being put as a String. * * @param key the key * @param value the value * @return a reference to this, so the API can be used fluently */ public JsonObject put(String key, byte[] value) { Objects.requireNonNull(key); map.put(key, value == null ? null : Base64.getEncoder().encodeToString(value)); return this; }
private static String computeBasicAuthentication(String principal, String password, Charset charset) { String s = principal + ":" + password; return "Basic " + Base64.getEncoder().encodeToString(s.getBytes(charset)); }
import java.util.Base64; byte[] bytes = "Hello, World!".getBytes("UTF-8"); String encoded = Base64.getEncoder().encodeToString(bytes); byte[] decoded = Base64.getDecoder().decode(encoded);
private String authorizationHeader(String user, String password) { String base = user + ":" + password; return "Basic " + Base64.getEncoder().encodeToString(base.getBytes(StandardCharsets.UTF_8)); }
public static String encodeStringToBase64(String string) { return new String(java.util.Base64.getEncoder().encode(string.getBytes(UTF_8)), UTF_8); }
private String authorizationHeader(String user, String password) { String base = user + ":" + password; return "Basic " + Base64.getEncoder().encodeToString(base.getBytes(StandardCharsets.UTF_8)); }
byte[] message = "hello world".getBytes(StandardCharsets.UTF_8); String encoded = Base64.getEncoder().encodeToString(message); byte[] decoded = Base64.getDecoder().decode(encoded); System.out.println(encoded); System.out.println(new String(decoded, StandardCharsets.UTF_8));
String toMessage() { return String.format("%s,p=%s", clientFinalMessageWithoutProof(), Base64.getEncoder().encodeToString(proof)); } }
public static String encryptUsingAES(SecretKey secretKey, String dataToEncrypt) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { Cipher aesCipher = Cipher.getInstance("AES"); aesCipher.init(Cipher.ENCRYPT_MODE, secretKey); byte[] byteCipherText = aesCipher.doFinal(dataToEncrypt.getBytes()); return Base64.getEncoder().encodeToString(byteCipherText); }
private String createCursor(int offset) { byte[] bytes = (prefix + Integer.toString(offset)).getBytes(StandardCharsets.UTF_8); return getEncoder().encodeToString(bytes); } }