List of usage examples for org.apache.commons.codec.binary Base64 Base64
public Base64()
From source file:android.provider.CredentialInputAdapter.java
@Override public URLConnection getConnection() throws IOException { if (getURL().getProtocol().equals("ftp")) { URL u = new URL("ftp://" + credentials.getUsername() + ":" + credentials.getPassword() + "@" + getURL().toExternalForm().substring(6)); return u.openConnection(); } else if (getURL().getProtocol().equals("http")) { Base64 enc = new Base64(); byte[] encoded = enc.encode((credentials.getUsername() + ":" + credentials.getPassword()).getBytes()); URLConnection connection = getURL().openConnection(); connection.setRequestProperty("Authorization", "Basic " + new String(encoded)); return connection; }/*w ww . j ava 2 s.c o m*/ return super.getConnection(); }
From source file:com.vab.iflex.gateway.paybillservice.Stub.java
private static String calculateRFC2104HMAC(String data, String key) throws Exception { String result;//from w ww.jav a 2 s .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 = new BASE64Encoder().encode(rawHmac); result = new Base64().encodeAsString(rawHmac); } catch (Exception e) { throw new SignatureException("Failed to generate HMAC : " + e.getMessage()); } return result; }
From source file:com.aurel.track.beans.TBLOBBean.java
@Override public Map<String, String> serializeBean() { Map<String, String> attributesMap = new HashMap<String, String>(); attributesMap.put("objectID", getObjectID().toString()); byte[] imageContent = getBLOBValue(); if (imageContent != null) { String imageData = new Base64().encodeAsString(imageContent); attributesMap.put("imageData", imageData); }//w ww . ja v a2s . c om attributesMap.put("uuid", getUuid()); return attributesMap; }
From source file:be.wolkmaan.klimtoren.security.encryption.pbe.StandardPBEStringEncryptor.java
public StandardPBEStringEncryptor() { super();//from w w w .j ava 2 s . co m this.byteEncryptor = new StandardPBEByteEncryptor(); this.base64 = new Base64(); }
From source file:course.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);// www .j ava 2s. c o m // result = new Base64().encodeToString(rawHmac); // BASE64Encoder encoder = new BASE64Encoder(); // String sessionID = encoder.encode(randomBytes); String sessionID = new Base64().encodeToString(randomBytes); // build the BSON object BasicDBObject session = new BasicDBObject("username", username); session.append("_id", sessionID); sessionsCollection.insert(session); return session.getString("_id"); }
From source file:de.alpharogroup.crypto.sha.Hasher.java
public static String hashAndBase64(final String hashIt, final String salt, final HashAlgorithm hashAlgorithm, final Charset charset) throws NoSuchAlgorithmException { final String hashedAndBase64 = new Base64() .encodeToString(hash(hashIt, salt, hashAlgorithm, charset).getBytes(charset)); return hashedAndBase64; }
From source file:adminpassword.AESDemo.java
public String encrypt(String plainText) throws Exception { //get salt//from w w w.j av a 2 s . c om salt = generateSalt(); byte[] saltBytes = salt.getBytes("UTF-8"); // Derive the key SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), saltBytes, pswdIterations, keySize); SecretKey secretKey = factory.generateSecret(spec); SecretKeySpec secret = new SecretKeySpec(secretKey.getEncoded(), "AES"); //encrypt the message Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, secret); AlgorithmParameters params = cipher.getParameters(); ivBytes = params.getParameterSpec(IvParameterSpec.class).getIV(); byte[] encryptedTextBytes = cipher.doFinal(plainText.getBytes("UTF-8")); return new Base64().encodeAsString(encryptedTextBytes); }
From source file:fr.gael.drb.impl.http.HttpNode.java
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override/*from w w w .j a v a2 s .c o m*/ public Object getImpl(Class api) { if (api.isAssignableFrom(InputStream.class)) { try { URLConnection urlConnect = this.url.openConnection(); if (this.url.getUserInfo() != null) { // HTTP Basic Authentication. String userpass = this.url.getUserInfo(); String basicAuth = "Basic " + new String(new Base64().encode(userpass.getBytes())); urlConnect.setRequestProperty("Authorization", basicAuth); } urlConnect.setDoInput(true); urlConnect.setUseCaches(false); return urlConnect.getInputStream(); } catch (IOException e) { return null; } } return null; }
From source file:com.devbury.mkremote.server.QuickLaunchServiceImpl.java
public ArrayList<LaunchItem> list(String dir) { Base64 base64 = new Base64(); JFileChooser chooser = new JFileChooser(); File new_dir = newFileDir(dir); logger.debug("Looking for files in {}", new_dir.getAbsolutePath()); ArrayList<LaunchItem> items = new ArrayList<LaunchItem>(); if (isSupported()) { if (new_dir.isDirectory()) { FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return !name.startsWith("."); }// w w w . ja v a 2 s .c o m }; for (File f : new_dir.listFiles(filter)) { if (!f.isHidden()) { LaunchItem item = new LaunchItem(); item.setName(f.getName()); item.setPath(dir); if (f.isDirectory()) { if (isMac() && f.getName().endsWith(".app")) { item.setType(LaunchItem.FILE_TYPE); item.setName(f.getName().substring(0, f.getName().length() - 4)); } else { item.setType(LaunchItem.DIR_TYPE); } } else { item.setType(LaunchItem.FILE_TYPE); } Icon icon = chooser.getIcon(f); BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB); icon.paintIcon(null, bi.createGraphics(), 0, 0); ByteArrayOutputStream os = new ByteArrayOutputStream(); try { ImageIO.write(bi, "png", os); item.setIcon(base64.encodeToString(os.toByteArray())); } catch (IOException e) { logger.debug("could not write image {}", e); item.setIcon(null); } logger.debug("Adding LaunchItem : {}", item); items.add(item); } else { logger.debug("Skipping hidden file {}", f.getName()); } } } } else { new Thread() { @Override public void run() { JOptionPane.showMessageDialog(null, "We are sorry but quick launch is not supported on your platform", "Quick Launch Not Supported", JOptionPane.ERROR_MESSAGE); } }.start(); } return items; }
From source file:ca.ualberta.physics.cssdp.util.HashUtils.java
/** * From a byte[] returns a base 64 representation * //from w w w .j av a 2 s .com * @param data * byte[] * @return String * @throws IOException */ public static String byteToBase64(byte[] data) { Base64 encoder = new Base64(); return encoder.encodeAsString(data); }