List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64String
public static String encodeBase64String(final byte[] binaryData)
From source file:integration.util.graylog.ServerHelper.java
public String getNodeId() throws MalformedURLException, URISyntaxException { final URI uri = IntegrationTestsConfig.getGlServerURL(); ObjectMapper mapper = new ObjectMapper(); try {//from ww w. j ava2 s .co m HttpURLConnection connection = (HttpURLConnection) new URL(uri.toURL(), "/system").openConnection(); connection.setConnectTimeout(HTTP_TIMEOUT); connection.setReadTimeout(HTTP_TIMEOUT); connection.setRequestMethod("GET"); if (uri.getUserInfo() != null) { String encodedUserInfo = Base64 .encodeBase64String(uri.getUserInfo().getBytes(StandardCharsets.UTF_8)); connection.setRequestProperty("Authorization", "Basic " + encodedUserInfo); } InputStream inputStream = connection.getInputStream(); JsonNode json = mapper.readTree(inputStream); return json.get("node_id").toString(); } catch (IOException e) { e.printStackTrace(); } return "00000000-0000-0000-0000-000000000000"; }
From source file:edu.wpi.cs.wpisuitetng.authentication.BasicAuthTest.java
@Test(expected = AuthenticationException.class) /**/* ww w . j a v a 2 s . c om*/ * Generates a valid BasicAuth token with invalidly formatted * credentials. Decoding should work properly. An exception should * raise because the credential string is not in the "String:String" format. */ public void testInvalidCredentialFormat() throws AuthenticationException { String authToken = "Basic "; String credentials = "abcdefg123456"; authToken += Base64.encodeBase64String(credentials.getBytes()); this.basic.parsePost(authToken); }
From source file:com.threatconnect.sdk.conn.ConnectionUtil.java
public static String getHmacSha256Signature(String signature, String apiSecretKey) { try {/*www . j a v a 2s . com*/ String calculatedSignature; SecretKeySpec spec = new SecretKeySpec(apiSecretKey.getBytes(), "HmacSHA256"); Mac mac = Mac.getInstance("HmacSHA256"); mac.init(spec); byte[] rawSignature = mac.doFinal(signature.getBytes()); calculatedSignature = Base64.encodeBase64String(rawSignature); return calculatedSignature; } catch (NoSuchAlgorithmException | InvalidKeyException | IllegalStateException ex) { logger.error("Error creating HMAC SHA256 signature", ex); return null; } }
From source file:com.vmware.o11n.plugin.crypto.service.CryptoDigestService.java
public String sha512(String data) { return Base64.encodeBase64String(DigestUtils.sha512(data)); }
From source file:br.com.intelidev.dao.userDao.java
/** * Run the web service request/*www . ja v a2s. c om*/ * @param username * @param password * @return */ public boolean login_acess(String username, String password) { HttpsURLConnection conn = null; boolean bo_return = false; try { // Create url to the Device Cloud server for a given web service request URL url = new URL("https://devicecloud.digi.com/ws/sci"); conn = (HttpsURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestMethod("GET"); // Build authentication string String userpassword = username + ":" + password; // 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); bo_return = true; } catch (Exception e) { // Print any exceptions that occur System.out.println("br.com.intelidev.dao.userDao.login_acess() Error: " + e); bo_return = false; //e.printStackTrace(); } finally { if (conn != null) conn.disconnect(); if (bo_return) { System.out.println("Conectou "); } else { System.out.println("No conectou "); } } return bo_return; }
From source file:com.buddycloud.friendfinder.HashUtils.java
public static String encodeSHA256(String str) throws NoSuchAlgorithmException, UnsupportedEncodingException { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(str.getBytes("UTF-8")); byte[] digest = md.digest(); return Base64.encodeBase64String(digest); }
From source file:me.schiz.functions.Base64EncodeFunction.java
public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException { String str = ((CompoundVariable) values[0]).execute(); return Base64.encodeBase64String(str.getBytes()); }
From source file:com.k42b3.aletheia.oauth.HMACSHA1.java
public String build(String baseString, String consumerSecret, String tokenSecret) { try {/*from w w w.j a v a 2 s.c o m*/ String key = Oauth.urlEncode(consumerSecret) + "&" + Oauth.urlEncode(tokenSecret); Mac mac = Mac.getInstance("HmacSHA1"); SecretKeySpec secret = new SecretKeySpec(key.getBytes(), "HmacSHA1"); mac.init(secret); byte[] result = mac.doFinal(baseString.getBytes()); return Base64.encodeBase64String(result); } catch (Exception e) { Aletheia.handleException(e); return null; } }
From source file:com.willetinc.hadoop.mapreduce.dynamodb.AttributeValueIOUtilsTest.java
@Test public void testToStringB() { final byte[] BYTES = new byte[] { 0xD, 0xE, 0xA, 0xD, 0xB, 0xE, 0xE, 0xF }; final String ENCODED_VALUE = Base64.encodeBase64String(BYTES); ByteBuffer buf = ByteBuffer.wrap(BYTES); AttributeValue attr = new AttributeValue().withB(buf); String result = AttributeValueIOUtils.toString(Types.BINARY, attr); assertEquals(ENCODED_VALUE, result); }
From source file:com.glaf.core.util.BinaryUtils.java
/** * Converts byte data to a Base64-encoded string. * * @param data//from www . j av a2 s . c o m * data to Base64 encode. * @return encoded Base64 string. */ public static String toBase64(byte[] data) { return Base64.encodeBase64String(data); }