List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64URLSafe
public static byte[] encodeBase64URLSafe(final byte[] binaryData)
From source file:edu.utdallas.bigsecret.crypter.CrypterMode1.java
/** * {@inheritDoc}//from ww w . j a va2 s. c om */ public byte[] getIndexFamilyData(byte[] family) throws Exception { if (family == null || family.length == 0) throw new Exception("Family is null or has no data"); byte[] famBucketData = Base64.encodeBase64URLSafe(m_famBucketizer.getBucketValue(family)); return famBucketData; }
From source file:kr.debop4j.core.tools.StringTool.java
/** * Encode base 64./*from www. jav a 2s. c o m*/ * * @param input the input * @return the byte [ ] */ public static byte[] encodeBase64(final byte[] input) { return Base64.encodeBase64URLSafe(input); }
From source file:com.erudika.para.utils.Utils.java
/** * Encodes a byte array to Base64. URL safe. * @param str the byte array/*w w w. j a v a2s.co m*/ * @return an encoded string */ public static String base64encURL(byte[] str) { if (str == null) { return ""; } return new String(Base64.encodeBase64URLSafe(str)); }
From source file:net.ymate.platform.mvc.web.support.CookieHelper.java
public String encodeValue(String value) { String _value = value;/* ww w . ja v a2 s . co m*/ if (StringUtils.isNotBlank(value)) { if (this.__useAuthKey) { if (__cookieKey == null) { __cookieKey = __getEncodedAuthKeyStr(); } if (StringUtils.isNotBlank(__cookieKey)) { try { _value = new String(Base64.encodeBase64URLSafe( DESCodec.encrypt(value.getBytes(getCharsetEncoding()), __cookieKey.getBytes())), getCharsetEncoding()); } catch (Exception e) { _LOG.warn("", RuntimeUtils.unwrapThrow(e)); } } } else if (this.__useBase64) { try { _value = new String(Base64.encodeBase64URLSafe(_value.getBytes(getCharsetEncoding())), getCharsetEncoding()); } catch (UnsupportedEncodingException e) { _LOG.warn("", RuntimeUtils.unwrapThrow(e)); } } } else { _value = ""; } return _value; }
From source file:net.ymate.platform.webmvc.util.CookieHelper.java
public String encodeValue(String value) { String _value = value;// ww w . ja va 2 s . c om if (StringUtils.isNotBlank(value)) { if (this.__useAuthKey) { if (__cookieKey == null) { __cookieKey = __getEncodedAuthKeyStr(); } if (StringUtils.isNotBlank(__cookieKey)) { try { _value = new String(Base64.encodeBase64URLSafe( CodecUtils.DES.encrypt(value.getBytes(__charsetEncoding), __cookieKey.getBytes())), __charsetEncoding); } catch (Exception e) { __LOG.warn("", RuntimeUtils.unwrapThrow(e)); } } } else if (this.__useBase64) { try { _value = new String(Base64.encodeBase64URLSafe(_value.getBytes(__charsetEncoding)), __charsetEncoding); } catch (UnsupportedEncodingException e) { __LOG.warn("", RuntimeUtils.unwrapThrow(e)); } } } else { _value = ""; } return _value; }
From source file:nz.org.p2p.model.member.authentication.PasswordResetTokenFactory.java
@Override public String obfuscate(String token) { byte[] base64 = Base64.encodeBase64URLSafe(token.getBytes()); Charset charset = encoding == null ? Charset.defaultCharset() : Charset.forName(encoding); String string = new String(base64, charset); return string; }
From source file:openlr.binary.ByteArray.java
/** * Gets the base64 data.// w ww. ja v a 2 s. c o m * * @return the base64 data */ public final String getBase64DataUrlSafe() { return new String(Base64.encodeBase64URLSafe(bytes), Charset.forName("UTF-8")); }
From source file:org.apache.niolex.commons.codec.KVBase64Util.java
/** * KVbyte??64//from w w w .ja v a 2s .c om * Encode KV Byte Array into Base64 String * * @param key ?key?63 * @param value ?value?key+value512 * @return ??64 * @throws IllegalStateException ???ASCII? */ public static String kvToBase64(byte[] key, byte[] value) { if (key == null || value == null) throw new IllegalArgumentException("The parameter should not be null!"); int size = key.length + value.length; if (key.length > 63 || size > 512) { throw new IllegalArgumentException("The KV is too large!"); } byte data[] = new byte[(size + 3) / 3 * 3]; int start = data.length - size; int first = (key.length << 2) + start; data[0] = (byte) first; System.arraycopy(key, 0, data, start, key.length); System.arraycopy(value, 0, data, start + key.length, value.length); return StringUtil.asciiByteToStr(Base64.encodeBase64URLSafe(data)); }
From source file:org.apache.shindig.common.crypto.BasicBlobCrypter.java
public String wrap(Map<String, String> in) throws BlobCrypterException { Preconditions.checkArgument(!in.containsKey(TIMESTAMP_KEY), "No '%s' key allowed for BlobCrypter", TIMESTAMP_KEY);/*from w w w.j a v a 2s . c om*/ try { byte[] encoded = serializeAndTimestamp(in); byte[] cipherText = Crypto.aes128cbcEncrypt(cipherKey, encoded); byte[] hmac = Crypto.hmacSha1(hmacKey, cipherText); byte[] b64 = Base64.encodeBase64URLSafe(Crypto.concat(cipherText, hmac)); return new String(b64, UTF8); } catch (UnsupportedEncodingException e) { throw new BlobCrypterException(e); } catch (GeneralSecurityException e) { throw new BlobCrypterException(e); } }
From source file:org.artifactory.security.SecurityServiceImpl.java
/** * Generates a password recovery key for the specified user and send it by mail * * @param username User to rest his password * @param remoteAddress The IP of the client that sent the request * @param resetPageUrl The URL to the password reset page * @throws Exception// w w w . j a va 2 s .c o m */ @Override public void generatePasswordResetKey(String username, String remoteAddress, String resetPageUrl) throws Exception { UserInfo userInfo; try { userInfo = findUser(username); } catch (UsernameNotFoundException e) { //If can't find user throw new IllegalArgumentException("Could not find specified username.", e); } //If user has valid email if (!StringUtils.isEmpty(userInfo.getEmail())) { if (!userInfo.isUpdatableProfile()) { //If user is not allowed to update his profile throw new AuthorizationException("User is not permitted to reset his password."); } //Build key by UUID + current time millis + client ip -> encoded in B64 UUID uuid = UUID.randomUUID(); String passwordKey = uuid.toString() + ":" + System.currentTimeMillis() + ":" + remoteAddress; byte[] encodedKey = Base64.encodeBase64URLSafe(passwordKey.getBytes(Charsets.UTF_8)); String encodedKeyString = new String(encodedKey, Charsets.UTF_8); MutableUserInfo mutableUser = InfoFactoryHolder.get().copyUser(userInfo); mutableUser.setGenPasswordKey(encodedKeyString); updateUser(mutableUser, false); //Add encoded key to page url String resetPage = resetPageUrl + "?key=" + encodedKeyString; //If there are any admins with valid email addresses, add them to the list that the message will contain String adminList = getAdminListBlock(userInfo); InputStream stream = null; try { //Get message body from properties and substitute variables stream = getClass().getResourceAsStream("/org/artifactory/email/messages/resetPassword.properties"); ResourceBundle resourceBundle = new PropertyResourceBundle(stream); String body = resourceBundle.getString("body"); body = MessageFormat.format(body, username, remoteAddress, resetPage, adminList); mailService.sendMail(new String[] { userInfo.getEmail() }, "Reset password request", body); } catch (EmailException e) { log.error("Error while resetting password for user: '" + username + "'.", e); throw e; } finally { IOUtils.closeQuietly(stream); } log.info("The user: '{}' has been sent a password reset message by mail.", username); } }