List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64String
public static String encodeBase64String(final byte[] binaryData)
From source file:com.sap.core.odata.core.debug.DebugInfoBody.java
@Override public void appendJson(final JsonStreamWriter jsonStreamWriter) throws IOException { final String contentType = response.getContentHeader(); if (contentType.startsWith("image/")) { if (response.getEntity() instanceof InputStream) { jsonStreamWriter.stringValueRaw( Base64.encodeBase64String(getBinaryFromInputStream((InputStream) response.getEntity()))); } else if (response.getEntity() instanceof String) { jsonStreamWriter.stringValueRaw(getContentString()); } else {//w w w .ja v a 2 s. c o m throw new ClassCastException( "Unsupported content entity class: " + response.getEntity().getClass().getName()); } } else if (contentType.startsWith(HttpContentType.APPLICATION_JSON)) { jsonStreamWriter.unquotedValue(getContentString()); } else { jsonStreamWriter.stringValue(getContentString()); } }
From source file:com.r573.enfili.common.resource.external.appstore.AppStoreManager.java
public VerifyReceiptResponse verifyReceipt(String receiptId) throws AppStoreException { try {/*from ww w . j av a 2 s . c o m*/ String receiptEncoded = Base64.encodeBase64String(receiptId.getBytes("UTF-8")); String urlToUse = ITUNES_API_BASEURL; if (useSandbox) { urlToUse = ITUNES_API_SANDBOX_BASEURL; } RestClient restClient = new RestClient(urlToUse); VerifyReceiptRequest request = new VerifyReceiptRequest(); request.setReceiptData(receiptEncoded); ResponseWrapper<VerifyReceiptResponse> result = restClient.post("/verifyReceipt", request, VerifyReceiptResponse.class); return result.getResponse(); } catch (Exception e) { throw new AppStoreException("Unable to verify receipt with AppStore", e); } }
From source file:com.surevine.gateway.scm.util.SCMSystemProperties.java
SCMSystemProperties(final String type, final String username, final String password, final String host) { this.type = SCMType.getType(type); this.username = username; this.password = password; this.host = host.replaceAll("/$", ""); this.encodedAuth = "Basic " + Base64.encodeBase64String((username + ":" + password).getBytes()); }
From source file:br.com.intelidev.dao.DadosDao.java
public List<Dados> get_stream_data(String stream_api, String user, String pass) { HttpsURLConnection conn = null; List<Dados> list_return = new ArrayList<>(); int i;/*from ww w. j a v a 2 s .c o m*/ try { // Create url to the Device Cloud server for a given web service request //00000000-00000000-00409DFF-FF6064F8/xbee.analog/[00:13:A2:00:40:E6:5A:88]!/AD1 ObjectMapper mapper = new ObjectMapper(); URL url = new URL("https://devicecloud.digi.com/ws/v1/streams/history/" + stream_api); //URL url = new URL("https://devicecloud.digi.com/ws/v1/streams/history/00000000-00000000-00409DFF-FF6064F8/xbee.analog/[00:13:A2:00:40:E6:5A:88]!/AD1"); conn = (HttpsURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestMethod("GET"); // Build authentication string String userpassword = user + ":" + pass; System.out.println(userpassword); // can change this to use a different base64 encoder String encodedAuthorization = Base64.encodeBase64String(userpassword.getBytes()).trim(); // set request headers conn.setRequestProperty("Authorization", "Basic " + encodedAuthorization); // Get input stream from response and convert to String InputStream is = conn.getInputStream(); Scanner isScanner = new Scanner(is); StringBuffer buf = new StringBuffer(); while (isScanner.hasNextLine()) { buf.append(isScanner.nextLine() + "\n"); } String responseContent = buf.toString(); // add line returns between tags to make it a bit more readable responseContent = responseContent.replaceAll("><", ">\n<"); // Output response to standard out System.out.println(responseContent); // Convert JSON string to Object StreamDados stream = mapper.readValue(responseContent, StreamDados.class); //System.out.println(stream.getList()); System.out.println(stream.getList().size()); for (i = 0; i < stream.getList().size(); i++) { list_return.add(stream.getList().get(i)); //System.out.println("ts: "+ stream.getList().get(i).getTimestamp() + "Value: " + stream.getList().get(i).getValue()); } } catch (Exception e) { // Print any exceptions that occur System.out.println("br.com.intelidev.dao.DadosDao.get_stream_data() e" + e); } finally { if (conn != null) conn.disconnect(); } return list_return; }
From source file:com.rdonasco.security.utils.EncryptionUtil.java
public static String encryptWithPassword(String stringToEncrypt, String password) throws Exception { PBEKeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray(), SALT, COUNT); SecretKey pbeKey = getKeyFactory().generateSecret(pbeKeySpec); Cipher pbeCipher = Cipher.getInstance(CIPHER_KEY_SPEC); pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, PBE_PARAM_SPEC); byte[] encryptedBytes = pbeCipher.doFinal(stringToEncrypt.getBytes()); return Base64.encodeBase64String(encryptedBytes); }
From source file:com.qperior.gsa.oneboxprovider.implementations.jive.QPJiveSecurityProvider.java
private String base64Encode(String stringToEncode) { byte[] stringToEncodeBytes = stringToEncode.getBytes(); return Base64.encodeBase64String(stringToEncodeBytes); }
From source file:io.apicurio.hub.api.bitbucket.BitbucketSourceConnectorTest.java
@BeforeClass public static void globalSetUp() { File credsFile = new File(".bitbucket"); if (!credsFile.isFile()) { return;// w ww. j a v a 2 s .co m } System.out.println("Loading Bitbucket credentials from: " + credsFile.getAbsolutePath()); try (Reader reader = new FileReader(credsFile)) { Properties props = new Properties(); props.load(reader); String userPass = props.getProperty("username") + ":" + props.getProperty("password"); basicAuth = Base64.encodeBase64String(userPass.getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } }
From source file:com.tmobile.TMobileParsing.java
protected static String getToken(String username, String password) throws IOException { byte[] auth = String.valueOf(username + ":" + password).getBytes(); String basicAuthToken = Base64.encodeBase64String(auth); String authenticationData = getDataFromUrl(TMobile.URL_AUTHENTICATE, basicAuthToken); Gson gson = new Gson(); AuthToken authToken = gson.fromJson(authenticationData, AuthToken.class); return authToken.response.authToken; }
From source file:de.learnlib.alex.data.entities.actions.Credentials.java
/** * Return the name and password encoded in Base64 to be used in the HTTP Basic Authentication. * * @return "name:password" encoded in Base64. *//*from w w w . j av a 2 s. c om*/ public String toBase64() { String credentialsAsString = name + ":" + password; return Base64.encodeBase64String(credentialsAsString.getBytes()); }
From source file:com.sap.core.odata.core.uri.expression.TestTokenizer.java
public static String HexToBase64(final String hex) { String base64 = ""; byte bArr[];/*from w w w .j a v a2 s . c o m*/ try { bArr = Hex.decodeHex(hex.toCharArray()); base64 = Base64.encodeBase64String(bArr); } catch (DecoderException e) { fail("Error in Unittest preparation ( HEX->base64"); } return base64; }