List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64
public static byte[] encodeBase64(final byte[] binaryData)
From source file:com.atlassian.jira.rest.client.auth.BasicHttpAuthenticationHandler.java
private String encodeCredentials() { byte[] credentials = (username + ':' + password).getBytes(); return new String(Base64.encodeBase64(credentials)); }
From source file:net.sf.hajdbc.codec.base64.Base64CodecFactory.java
/** * {@inheritDoc}// ww w .ja va2 s .c o m * @see net.sf.hajdbc.codec.Codec#encode(java.lang.String) */ @Override public String encode(String value) throws SQLException { return new String(Base64.encodeBase64(value.getBytes())); }
From source file:com.nextdoor.bender.ipc.http.HttpTransportFactory.java
@Override public void setConf(AbstractConfig config) { HttpTransportConfig httpConfig = (HttpTransportConfig) config; BasicHttpAuthConfig auth = (BasicHttpAuthConfig) httpConfig.getBasicHttpAuth(); if (auth != null) { byte[] encodedAuth = Base64.encodeBase64((auth.getUsername() + ":" + auth.getPassword()).getBytes()); httpConfig.addHttpHeader(HttpHeaders.AUTHORIZATION, "Basic " + new String(encodedAuth)); }/*from ww w . j a v a 2 s. c o m*/ super.setConf(config); }
From source file:com.andiandy.m101j.week2.hw3.SessionDAO.java
public String startSession(String username) { // get 32 byte random number. that's a lot of bits. SecureRandom generator = new SecureRandom(); byte randomBytes[] = new byte[32]; generator.nextBytes(randomBytes);//from w ww . j a v a 2 s .c o m String sessionID = Base64.encodeBase64(randomBytes).toString(); // build the BSON object BasicDBObject session = new BasicDBObject("username", username); session.append("_id", sessionID); sessionsCollection.insert(session); return session.getString("_id"); }
From source file:net.mindengine.oculus.frontend.web.Auth.java
public static String encodeUser(User user) throws Exception { if (user == null) { throw new IllegalArgumentException("User should not be null"); }//from ww w.j ava 2 s . co m if (secrectAuthKey == null) { throw new IllegalArgumentException("Couldn't generate secret key"); } Cipher cipher = Cipher.getInstance("DES"); cipher.init(Cipher.ENCRYPT_MODE, secrectAuthKey); SealedObject sealedUser = new SealedObject(user, cipher); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(sealedUser); oos.close(); return new String(Base64.encodeBase64(baos.toByteArray())); }
From source file:com.imaginary.home.cloud.Configuration.java
static public @Nonnull String encrypt(@Nonnull String keySalt, @Nonnull String value) { try {//w w w. jav a 2 s.com SecretKeySpec spec = new SecretKeySpec(getConfiguration().getCustomSalt(keySalt), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, spec); byte[] raw = value.getBytes("utf-8"); byte[] encrypted = cipher.doFinal(raw); byte[] b64 = Base64.encodeBase64(encrypted); return new String(b64, "utf-8"); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.cisco.oss.foundation.directory.utils.ObfuscatUtil.java
/** * base64 encode./*from ww w . ja va 2 s . co m*/ * * @param buffer * the byte array. * @return * the encoded byte array. */ public static byte[] base64Encode(byte[] buffer) { return Base64.encodeBase64(buffer); }
From source file:com.hadoopvietnam.commons.crypt.J2MECrypto.java
public byte[] encrypt(byte[] clear) { int paddedSize = (clear.length / 8 + (clear.length % 8 == 0 ? 0 : 1)) * 2; int[] buffer = new int[paddedSize + 1]; buffer[0] = clear.length;//from w w w . ja v a2 s. c om pack(clear, buffer, 1); brew(buffer); return Base64.encodeBase64(unpack(buffer, 0, buffer.length * 4)); }
From source file:com.cyclopsgroup.tornado.security.entity.User.java
/** * @param privatePassword//from ww w.ja v a 2s. c o m */ public void setPrivatePassword(String privatePassword) { String pwd = new String(Base64.encodeBase64(privatePassword.getBytes())); setPassword(pwd); }
From source file:info.track_mate.util.EncryptionUtils.java
/** * Encrypt the specified String./*from w w w . j a va2s .co m*/ * @param toEncrypt The String to encrypt. * @param algorithm The algorithm to use for the encryption. See Appendix A in the * <a href="../../../technotes/guides/security/crypto/CryptoSpec.html#AppA">Java Cryptography Architecture API Specification & Reference </a> * for information about standard algorithm names. * @param encodeAsBase64 If true then encode the output of the encryption algorithm as Base64. * @return The encrypted String. * @throws NoSuchAlgorithmException If the specified algorithm doesn't exist or is unavailable. */ public static String encryptString(String toEncrypt, String algorithm, boolean encodeAsBase64) throws NoSuchAlgorithmException { MessageDigest md5Digest = MessageDigest.getInstance(algorithm); byte[] encryptedBytes = md5Digest.digest(toEncrypt.getBytes()); if (encodeAsBase64) { encryptedBytes = Base64.encodeBase64(encryptedBytes); } String encryptedString = new String(encryptedBytes); return encryptedString; }