public byte[] decode(String base64) { return javax.xml.bind.DatatypeConverter.parseBase64Binary(base64); } }
@Override public byte[] decode(final String base64) { return DatatypeConverter.parseBase64Binary(base64); }
public byte[] decode(String base64) { return javax.xml.bind.DatatypeConverter.parseBase64Binary(base64); } }
public byte[] base64StringToBytes(String data) { if (data == null) { return new byte[0]; } if (!data.matches(BASE64_PATTERN)) { return data.getBytes(UTF_8); } return DatatypeConverter.parseBase64Binary(data); }
public static KerberosTicket getTGT(Map<String, String> credentials) { KerberosTicket ret = null; if (credentials != null && credentials.containsKey("TGT") && credentials.get("TGT") != null) { ret = ClientAuthUtils.deserializeKerberosTicket(DatatypeConverter.parseBase64Binary(credentials.get("TGT"))); } return ret; }
protected static byte[] parseDERFromPEM(byte[] pem, String beginDelimiter, String endDelimiter) { String data = new String(pem); String[] tokens = data.split(beginDelimiter); if(tokens.length < 2) { // no results found! return null; } tokens = tokens[1].split(endDelimiter); if(tokens.length < 2) { // no results found! return null; } return DatatypeConverter.parseBase64Binary(tokens[0]); }
public static KerberosTicket getTGT(Map<String, String> credentials) { KerberosTicket ret = null; if (credentials != null && credentials.containsKey("TGT")) { try { ByteArrayInputStream bin = new ByteArrayInputStream(DatatypeConverter.parseBase64Binary(credentials.get("TGT"))); ObjectInputStream in = new ObjectInputStream(bin); ret = (KerberosTicket) in.readObject(); in.close(); } catch (Exception e) { throw new RuntimeException(e); } } return ret; }
private String getUser(HttpHeaders headers) { // this is a very minimalistic and "naive" code; if you plan to use it // add necessary checks (see org.glassfish.jersey.examples.httpsclientservergrizzly.authservergrizzly.SecurityFilter) String auth = headers.getRequestHeader("authorization").get(0); auth = auth.substring("Basic ".length()); String[] values = new String(DatatypeConverter.parseBase64Binary(auth), Charset.forName("ASCII")).split(":"); // String username = values[0]; // String password = values[1]; return values[0]; } }
public static void deserializeSSLFile(String credsKey, String directory, Map<String, String> credentials) { try { LOG.debug("deserializing ssl file with key: {}", credsKey); String resultStr = null; if (credentials != null && credentials.containsKey(credsKey) && credentials.get(credsKey) != null) { resultStr = credentials.get(credsKey); } if (resultStr != null) { byte[] decodedData = DatatypeConverter.parseBase64Binary(resultStr); File f = new File(directory, credsKey); try (FileOutputStream fout = new FileOutputStream(f)) { fout.write(decodedData); } } } catch (Exception e) { throw new RuntimeException(e); } }
import java.io.UnsupportedEncodingException; import javax.xml.bind.DatatypeConverter; public class EncodeString64 { public static void main(String[] args) throws UnsupportedEncodingException { String str = "77+9x6s="; // encode data using BASE64 String encoded = DatatypeConverter.printBase64Binary(str.getBytes()); System.out.println("encoded value is \t" + encoded); // Decode data String decoded = new String(DatatypeConverter.parseBase64Binary(encoded)); System.out.println("decoded value is \t" + decoded); System.out.println("original value is \t" + str); } }
/** * Load PrivateKey from PEM file. */ private RSAPrivateKey loadPrivateKeyFromPEMFile(String filename) { try { String publicKeyFile = FileReader.readFileFromClassPathOrPath(filename); byte[] publicKeyBytes = DatatypeConverter.parseBase64Binary(publicKeyFile.replace("-----BEGIN RSA PRIVATE KEY-----", "").replace("-----END RSA PRIVATE KEY-----", "")); return (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(publicKeyBytes)); } catch (Exception e) { throw new RuntimeException("Exception reading private key from PEM file", e); } }
/** * Retrieve the server key from the database for a given username. */ private byte[] getServerKey(final String username) throws UserNotFoundException { final String serverKey = AuthFactory.getServerKey(username); if (serverKey == null) { return null; } else { return DatatypeConverter.parseBase64Binary( serverKey ); } }
/** * Retrieve the stored key from the database for a given username. */ private byte[] getStoredKey(final String username) throws UserNotFoundException { final String storedKey = AuthFactory.getStoredKey(username); if (storedKey == null) { return null; } else { return DatatypeConverter.parseBase64Binary( storedKey ); } } }
private static Credentials doGetCredentials(CredentialKeyProvider provider, Map<String, String> credentials, String configKey) { Credentials credential = null; String credentialKey = provider.getCredentialKey(configKey); if (credentials != null && credentials.containsKey(credentialKey)) { try { byte[] credBytes = DatatypeConverter.parseBase64Binary(credentialKey); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(credBytes)); credential = new Credentials(); credential.readFields(in); } catch (Exception e) { LOG.error("Could not obtain credentials from credentials map.", e); } } return credential; }
public static byte[] decodeDataFromStream(DataInput in) throws Exception { String str = Bits.readString(in); log.debug(" : Read Encoded Data: \n%s", str); return DatatypeConverter.parseBase64Binary(str); }
private byte[] readAndBase64DecodeBody(InputStream in) throws IOException { byte[] body = IOUtils.toByteArray(in); body = DatatypeConverter.parseBase64Binary(new String(body, "UTF-8")); return body; }
public BinaryBody buildObject() { return new BinaryBody(DatatypeConverter.parseBase64Binary(value == null ? "" : value), getMediaType()); } }
private byte[] verifyAndExtractIv(InputStream in, Integer ivLen) throws IOException { int bytesRead; byte[] base64Iv = new byte[ivLen]; bytesRead = in.read(base64Iv); Assert.assertEquals(Integer.valueOf(bytesRead), Integer.valueOf(ivLen), "Expected to read IV"); return DatatypeConverter.parseBase64Binary(new String(base64Iv, "UTF-8")); }
@Override public void decode(FacesContext context, UIComponent component) { PhotoCam cam = (PhotoCam) component; String dataParam = cam.getClientId(context) + "_data"; Map<String, String> params = context.getExternalContext().getRequestParameterMap(); if (params.containsKey(dataParam)) { String image = params.get(dataParam); image = image.substring(22); CaptureEvent event = new CaptureEvent(cam, DatatypeConverter.parseBase64Binary(image), image); event.setPhaseId(PhaseId.INVOKE_APPLICATION); cam.queueEvent(event); } }
@Test public void encodeToStringWithJdk8VsJaxb() throws UnsupportedEncodingException { byte[] bytes = new byte[] {-0x4f, 0xa, -0x73, -0x4f, 0x64, -0x20, 0x75, 0x41, 0x5, -0x49, -0x57, -0x65, -0x19, 0x2e, 0x3f, -0x1b}; assertEquals(Base64Utils.encodeToString(bytes), DatatypeConverter.printBase64Binary(bytes)); assertArrayEquals(bytes, Base64Utils.decodeFromString(Base64Utils.encodeToString(bytes))); assertArrayEquals(bytes, DatatypeConverter.parseBase64Binary(DatatypeConverter.printBase64Binary(bytes))); bytes = "Hello World".getBytes("UTF-8"); assertEquals(Base64Utils.encodeToString(bytes), DatatypeConverter.printBase64Binary(bytes)); assertArrayEquals(bytes, Base64Utils.decodeFromString(Base64Utils.encodeToString(bytes))); assertArrayEquals(bytes, DatatypeConverter.parseBase64Binary(DatatypeConverter.printBase64Binary(bytes))); bytes = "Hello World\r\nSecond Line".getBytes("UTF-8"); assertEquals(Base64Utils.encodeToString(bytes), DatatypeConverter.printBase64Binary(bytes)); assertArrayEquals(bytes, Base64Utils.decodeFromString(Base64Utils.encodeToString(bytes))); assertArrayEquals(bytes, DatatypeConverter.parseBase64Binary(DatatypeConverter.printBase64Binary(bytes))); bytes = "Hello World\r\nSecond Line\r\n".getBytes("UTF-8"); assertEquals(Base64Utils.encodeToString(bytes), DatatypeConverter.printBase64Binary(bytes)); assertArrayEquals(bytes, Base64Utils.decodeFromString(Base64Utils.encodeToString(bytes))); assertArrayEquals(bytes, DatatypeConverter.parseBase64Binary(DatatypeConverter.printBase64Binary(bytes))); }