URL myURL = new URL(serviceURL); HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection(); String userCredentials = "username:password"; String basicAuth = "Basic " + new String(new Base64().encode(userCredentials.getBytes())); myURLConnection.setRequestProperty ("Authorization", basicAuth); myURLConnection.setRequestMethod("POST"); myURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); myURLConnection.setRequestProperty("Content-Length", "" + postData.getBytes().length); myURLConnection.setRequestProperty("Content-Language", "en-US"); myURLConnection.setUseCaches(false); myURLConnection.setDoInput(true); myURLConnection.setDoOutput(true);
c.init(Cipher.DECRYPT_MODE, key) val decodedValue = new Base64().decode(encryptedValue.getBytes()) val decryptedVal = c.doFinal(decodedValue) return new String(decryptedVal)
URL url = new URL(“location address”); URLConnection uc = url.openConnection(); String userpass = username + ":" + password; String basicAuth = "Basic " + new String(new Base64().encode(userpass.getBytes())); uc.setRequestProperty ("Authorization", basicAuth); InputStream in = uc.getInputStream();
URL url = new URL("http://user:pass@domain.com/url"); URLConnection urlConnection = url.openConnection(); if (url.getUserInfo() != null) { String basicAuth = "Basic " + new String(new Base64().encode(url.getUserInfo().getBytes())); urlConnection.setRequestProperty("Authorization", basicAuth); } InputStream inputStream = urlConnection.getInputStream();
import org.apache.commons.codec.binary.Base64; private static String uuidToBase64(String str) { Base64 base64 = new Base64(); UUID uuid = UUID.fromString(str); ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return base64.encodeBase64URLSafeString(bb.array()); } private static String uuidFromBase64(String str) { Base64 base64 = new Base64(); byte[] bytes = base64.decodeBase64(str); ByteBuffer bb = ByteBuffer.wrap(bytes); UUID uuid = new UUID(bb.getLong(), bb.getLong()); return uuid.toString(); }
protected static String convertToPem(X509Certificate cert) throws CertificateEncodingException { Base64 encoder = new Base64(64); String cert_begin = "-----BEGIN CERTIFICATE-----\n"; String end_cert = "-----END CERTIFICATE-----"; byte[] derCert = x509cert.getEncoded(); String pemCertPre = new String(encoder.encode(derCert)); String pemCert = cert_begin + pemCertPre + end_cert; return pemCert; }
import org.apache.commons.codec.binary.Base64; public static String base64UrlDecode(String input) { String result = null; Base64 decoder = new Base64(true); byte[] decodedBytes = decoder.decode(input); result = new String(decodedBytes); return result; }
String keySource = username + creationDate + random; byte [] tokenByte = new Base64(true).encodeBase64(keySource.getBytes()); String token = new String(tokenByte);
// Base64 decode Base64 base64Decoder = new Base64(); byte[] xmlBytes = encodedXmlString.getBytes("UTF-8"); byte[] base64DecodedByteArray = base64Decoder.decode(xmlBytes); // Inflate (uncompress) the AuthnRequest data // First attempt to unzip the byte array according to DEFLATE (rfc 1951) Inflater inflater = new Inflater(true); inflater.setInput(base64DecodedByteArray); // since we are decompressing, it's impossible to know how much space we // might need; hopefully this number is suitably big byte[] xmlMessageBytes = new byte[5000]; int resultLength = inflater.inflate(xmlMessageBytes); if (!inflater.finished()) { throw new RuntimeException("didn't allocate enough space to hold " + "decompressed data"); } inflater.end(); String decodedResponse = new String(xmlMessageBytes, 0, resultLength, "UTF-8"); return decodedResponse;
static final Base64 base64 = new Base64();
private static Base64 base64 = new Base64();
import org.apache.commons.codec.binary.Base64; ... byte[] abValue = {...}; // Your data to encode Base64 base64 = new Base64(); String strEncodedData = base64.encodeToString(abValue).trim();
import org.apache.commons.codec.binary.Base64; public class GiveMeANameHere { public static void main(String[] args) { Base64 decoder = new Base64(); byte[] license = decoder.decode(args[0]); // Do whatever you need to with the license. // Other strings passed in will appear as elements in args array } }
import org.apache.commons.codec.binary.Base64; @RequestMapping(value = "/info/{id}", method = RequestMethod.GET) public String get(@PathVariable String id) { final String realId = new String(new Base64(true).encodeBase64URLSafe(id)); [...] }
import org.apache.commons.codec.binary.Base64; void example() { String srr = FileUtils.readFileToString(new File("c:\\test.txt")); byte b[]; Base64 base64 = new Base64(); b=base64.decode(srr); }
URLConnection conn = url.openConnection(); String creds = user + ":" + pass; String encodedCreds = "Basic " + new String(new Base64().encode(creds.getBytes())); conn.setRequestProperty ("Authorization", encodedCreds); InputStream in = conn.getInputStream();
BufferedImage img = ImageIO.read(new File("temp.jpg")); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(img, "jpg", baos); baos.flush(); Base64 base = new Base64(false); String encodedImage = base.encodeToString(baos.toByteArray()); baos.close(); encodedImage = java.net.URLEncoder.encode(encodedImage, "ISO-8859-1"); request.setRequestBody(encodedImage);
URL url = new URL("http://user:pass@127.0.0.1:18332/"); URLConnection conn = url.openConnection(); String userpass = rpcuser + ":" + rpcpassword; String basicAuth = "Basic " + new String(new Base64().encode(userpass.getBytes())); conn.setRequestProperty ("Authorization", basicAuth); conn.setRequestProperty ("Content-Type", "application/json"); conn.setDoOutput(true);
String s1 = "test"; System.out.println(s1); Base64 base64 = new Base64(); String s2 = base64.encodeAsString(s1.getBytes()); System.out.println(s2); URLCodec url = new URLCodec(); String s3 = url.encode(s2); System.out.println(s3); s2 = url.decode(s3); System.out.println(s2); s1 = new String(base64.decode(s2)); System.out.println(s1);
Attachments attachments3 = new Attachments(); Base64 x = new Base64(); String imageDataString = x.encodeAsString(fileData); attachments3.setContent(imageDataString); attachments3.setType("image/png");//"application/pdf" attachments3.setFilename("x.png"); attachments3.setDisposition("attachment"); attachments3.setContentId("Banner"); mail.addAttachments(attachments3);