List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64URLSafeString
public static String encodeBase64URLSafeString(final byte[] binaryData)
From source file:com.oneops.ecv.auth.AuthUtilTest.java
@Test public void testAuthenticate() throws Exception { AuthUtil authUtil = new AuthUtil(); authUtil.setSecret(SECRET);//from ww w .ja va 2s . co m authUtil.setUser(USER); String authHeader = "Basic "; String userSecret = USER + ":" + SECRET; String authString = String.valueOf(Base64.encodeBase64URLSafeString(userSecret.getBytes())); Assert.assertTrue(authUtil.authenticate(authHeader + authString)); }
From source file:customerproject.customerutilities.Utilities.java
public static String SHA256(String email, String password) throws NoSuchAlgorithmException, UnsupportedEncodingException { String text = email + "." + password; MessageDigest md = DigestUtils.getSha256Digest(); byte[] sha256hash = new byte[32]; md.update(text.getBytes("iso-8859-1"), 0, text.length()); sha256hash = md.digest();// w w w . j a va2s. c om //return Base64.encodeBase64String(sha256hash); return Base64.encodeBase64URLSafeString(sha256hash); //String hex = convertToHex(sha256hash); }
From source file:it.smartcommunitylab.aac.oauth.AACOAuth2Utils.java
private static String getS256CodeChallenge(String codeVerifier) { MessageDigest md;/*from w w w . j a v a 2s. c o m*/ try { md = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException("No such algorithm [SHA-256]"); } byte[] sha256 = md.digest(Utf8.encode(codeVerifier)); String codeChallenge = Base64.encodeBase64URLSafeString(sha256); return codeChallenge; }
From source file:com.webarch.common.lang.Digest.java
/** * base64/*from w w w .j av a 2s . co m*/ * * @param charset UTF-8 * @param soureces ? * @return <code>sources</code>?? */ public static String[] base64Code(String charset, final String... soureces) { try { if (charset == null || "".equals(charset)) charset = "UTF-8"; String[] results = new String[soureces.length]; for (int i = 0; i < soureces.length; i++) { results[i] = Base64.encodeBase64URLSafeString(soureces[i].getBytes(charset)); } return results; } catch (UnsupportedEncodingException E) { return null; } }
From source file:com.github.ambry.frontend.AmbryIdSigningService.java
@Override public String getSignedId(String blobId, Map<String, String> metadata) throws RestServiceException { try {// w ww . jav a2s .c om String jsonString = SignedIdSerDe.toJson(blobId, metadata); return RestUtils.SIGNED_ID_PREFIX + Base64.encodeBase64URLSafeString(jsonString.getBytes(StandardCharsets.UTF_8)); } catch (Exception e) { throw new RestServiceException("Error serializing signed ID", e, RestServiceErrorCode.InternalServerError); } }
From source file:me.vertretungsplan.objects.credential.BaseCredential.java
protected String hash(String data) { try {//from www .j a va2s . c o m MessageDigest digest = MessageDigest.getInstance("SHA-256"); byte[] hashBytes = digest.digest(data.getBytes()); return Base64.encodeBase64URLSafeString(hashBytes); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; }
From source file:com.pinterest.deployservice.common.CommonUtils.java
public static Map<String, String> encodeScript(Map<String, String> data) throws Exception { Map<String, String> encoded = new HashMap<String, String>(data.size()); for (Map.Entry<String, String> entry : data.entrySet()) { encoded.put(entry.getKey(), Base64.encodeBase64URLSafeString(entry.getValue().getBytes("UTF8"))); }/*from w ww. j a va 2 s. co m*/ return encoded; }
From source file:baggage.hypertoolkit.security.CipherText.java
public String base64() { return Base64.encodeBase64URLSafeString(bytes).trim(); }
From source file:com.oneops.ecv.auth.AuthUtilTest.java
@Test public void testAuthenticateInvalidCred() throws Exception { AuthUtil authUtil = new AuthUtil(); authUtil.setSecret(SECRET);//from w w w .j a va 2 s . c o m authUtil.setUser(USER); String authHeader = "Basic "; String userSecret = USER + ":" + SECRET + "1"; String authString = String.valueOf(Base64.encodeBase64URLSafeString(userSecret.getBytes())); Assert.assertFalse(authUtil.authenticate(authHeader + authString)); }
From source file:com.vmware.vchs.api.samples.services.IAM.java
/** * This method will attempt to create a user session, effectively logging in if the username * and password are valid account credentials and the account TOS has been accepted (via * the UI currently).//from www. j a v a 2 s. c o m * * @param hostname * the url of the API to make requests to * @param username * the username of the account to log in with * @param password * the password of the account to log in with * @param version * the version of the API to call * @return the value of the response header vchs-authorization if login is successful, null * otherwise */ public static final String login(String hostname, String username, String password, String version) { HttpPost post = new HttpPost(hostname + LOGIN_URL_RESOURCE); post.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + Base64.encodeBase64URLSafeString(new String(username + ":" + password).getBytes())); post.setHeader(HttpHeaders.ACCEPT, SampleConstants.APPLICATION_JSON_VERSION + version); HttpResponse response = HttpUtils.httpInvoke(post); if (null != response) { // If the response status is 400 - 599 if (response.getStatusLine().getStatusCode() >= HttpStatus.SC_BAD_REQUEST) { // This is here to show when an error occurs, the response should always be // an Error instance Error error = HttpUtils.unmarshal(response.getEntity(), Error.class); // Do something with Error, possibly using Error.getCode() value to // determine the specific reason for the error. } else { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED) { return response.getFirstHeader(SampleConstants.VCHS_AUTHORIZATION_HEADER).getValue(); } } } return null; }