List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64URLSafeString
public static String encodeBase64URLSafeString(final byte[] binaryData)
From source file:teste.transformarImage.java
public static String encodeImage(byte[] imageByteArray) { return Base64.encodeBase64URLSafeString(imageByteArray); }
From source file:uk.ac.bbsrc.tgac.miso.integration.util.SignatureHelper.java
private static String calculateHMAC(String data, String key) throws java.security.SignatureException { String result;/*from w ww. j av a2s .c o m*/ try { // get an hmac_sha1 key from the raw key bytes SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM); // get an hmac_sha1 Mac instance and initialize with the signing key Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM); mac.init(signingKey); // compute the hmac on input data bytes byte[] rawHmac = mac.doFinal(data.getBytes()); // base64-encode the hmac result = Base64.encodeBase64URLSafeString(rawHmac); } catch (Exception e) { log.error("failed to generate HMAC", e); throw new SignatureException("Failed to generate HMAC : " + e.getMessage()); } return result; }
From source file:uk.ac.bbsrc.tgac.miso.integration.util.SignatureHelper.java
public static String generatePrivateUserKey(byte[] data) throws NoSuchAlgorithmException { SecretKeySpec signingKey = new SecretKeySpec(data, DSA_ALGORITHM); return Base64.encodeBase64URLSafeString(signingKey.getEncoded()); }
From source file:uk.ac.tgac.bbsrc.miso.external.ajax.ExternalSectionControllerHelperService.java
public static String generatePrivateUserKey(byte[] data) throws NoSuchAlgorithmException { SecretKeySpec signingKey = new SecretKeySpec(data, "DSA"); return Base64.encodeBase64URLSafeString(signingKey.getEncoded()); }
From source file:uk.ac.tgac.bbsrc.miso.external.ajax.ExternalSectionControllerHelperService.java
public static String calculateHMAC(String data, String key) throws java.security.SignatureException { String result;/*from ww w .j a va 2 s. c o m*/ try { // get an hmac_sha1 key from the raw key bytes SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), "HmacSHA1"); // get an hmac_sha1 Mac instance and initialize with the signing key Mac mac = Mac.getInstance("HmacSHA1"); mac.init(signingKey); // compute the hmac on input data bytes byte[] rawHmac = mac.doFinal(data.getBytes()); // base64-encode the hmac result = Base64.encodeBase64URLSafeString(rawHmac); } catch (Exception e) { log.error("failed to generate HMAC", e); throw new SignatureException("Failed to generate HMAC : " + e.getMessage()); } return result; }
From source file:uk.co.tfd.symplectic.harvester.XmlAide.java
public static String hash(String userUrl) throws UnsupportedEncodingException, NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("SHA1"); return Base64.encodeBase64URLSafeString(md.digest(userUrl.getBytes("UTF-8"))); }
From source file:watne.seis720.project.AES_Utilities.java
/** * Get the Base64 text representation of the given byte sequence. * @param bytes the byte sequence for which the Base64 text representation * is to be given./*from w w w.ja va 2 s. c o m*/ * @return the Base64 text representation of the given byte sequence. */ public static String getBase64Text(byte[] bytes) { return Base64.encodeBase64URLSafeString(bytes); }
From source file:yoyo.framework.standard.shared.SecurityUtils.java
/** * ???//from ww w . jav a 2s . c om * <ul> * <li>AES256bit?????</li> * <li>SHA1PRNG???????URL?BASE64?????</li> * </ul> * @return ?(URL?BASE64) */ public static String createKey() { try { final KeyGenerator generator = KeyGenerator.getInstance(ALGO_NAME); generator.init(KEY_LENGTH, SecureRandom.getInstance(RAND_NAME)); return Base64.encodeBase64URLSafeString(generator.generateKey().getEncoded()); } catch (final NoSuchAlgorithmException e) { throw new IllegalArgumentException(e); } }