List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64String
public static String encodeBase64String(final byte[] binaryData)
From source file:com.pamarin.income.util.StringRandom.java
public static String random2048bit() { byte[] r = new byte[256]; //Means 2048 bit Random random = new Random(); random.nextBytes(r);/* w w w .ja va 2 s .c om*/ return Base64.encodeBase64String(r).replace("+", "_"); }
From source file:ju.ehealthservice.utils.ImageHandler.java
public static String formatString(byte[] bin) { StringBuffer data = new StringBuffer(Base64.encodeBase64String(bin)); data.insert(0, Constants.IMAGE_HEADER); return data.toString(); }
From source file:com.jeet.s3.util.HashUtil.java
public static String generateFileHash(File file) { String hash = ""; try {/* w ww. j a v a 2s . c o m*/ Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); SecretKeySpec secret_key = new SecretKeySpec(Constants.HASH_SECRET.getBytes(), "HmacSHA256"); sha256_HMAC.init(secret_key); hash = Base64.encodeBase64String(sha256_HMAC.doFinal(IOUtils.toByteArray(new FileInputStream(file)))); } catch (Exception ex) { System.out.println("Error in generating hash."); } return hash; }
From source file:FainClasses.HttpBasicAuth.java
public static void auth() { String sHTML = "Can not load page"; URL url;/* w ww. ja v a2s . com*/ InputStream is; BufferedReader buff = null; try { url = new URL("http://vrgaz.ru/lk/index.php?page=ls&lss=1600013620"); url.getAuthority(); String encoding = Base64.encodeBase64String("md_dimka@mail.ru:ufpyflt;ls".getBytes()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.setRequestProperty("Cookie", "PHPSESSID=343266771f5de3a489ba82fe79809854"); // connection. //connection.setRequestProperty("Authorization", "Basic " + encoding); /*connection.setRequestProperty("avl","md_dimka@mail.ru"); connection.setRequestProperty("avp","ufpyflt;ls"); */ //connection.setRequestProperty("page", "ls"); //connection.setRequestProperty("lss", "1600013620"); //URL url = new URL("http://vrgaz.ru/lk/"); // url = new URL(sUrl); //is = url.openStream(); is = connection.getInputStream(); buff = new BufferedReader(new InputStreamReader(is, "windows-1251")); StringBuilder page = new StringBuilder(); String tmp; while ((tmp = buff.readLine()) != null) { page.append(tmp).append("\n"); } sHTML = page.toString(); System.out.println(sHTML); // InputStream content = (InputStream) connection.getInputStream(); // BufferedReader in // = new BufferedReader(new InputStreamReader(content)); // String line; // while ((line = in.readLine()) != null) { // System.out.println(line); // } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.shadows.liquiblq.common.utils.HashManager.java
public static String GenerateStringSalt() { SecureRandom RANDOM = new SecureRandom(); byte[] salt = new byte[16]; RANDOM.nextBytes(salt);/*from w w w. j a va 2s . com*/ return Base64.encodeBase64String(salt); }
From source file:com.sysfore.pos.licensemanagement.LicenceManagementUtil.java
public static String encrypt(String strToEncrypt) { try {//from w ww. j av a2s . c o m Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); final SecretKeySpec secretKey = new SecretKeySpec(key, "AES"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); final String encryptedString = Base64.encodeBase64String(cipher.doFinal(strToEncrypt.getBytes())); return encryptedString; } catch (Exception e) { log.error("Error while encrypting", e); } return null; }
From source file:com.trouch.webiopi.client.PiClient.java
public static String encodeCredentials(String login, String password) { return Base64.encodeBase64String((login + ":" + password).getBytes()); }
From source file:Logic.security.java
public static String symmetricEncrypt(String text, String secretKey) { byte[] raw;/*from w ww .jav a2 s . co m*/ String encryptedString; SecretKeySpec skeySpec; byte[] encryptText = text.getBytes(); Cipher cipher; try { raw = Base64.decodeBase64(secretKey); skeySpec = new SecretKeySpec(raw, "AES"); cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); encryptedString = Base64.encodeBase64String(cipher.doFinal(encryptText)); } catch (Exception e) { e.printStackTrace(); return "Error"; } return encryptedString; }
From source file:cn.zhuqi.mavenssh.ext.util.Coder.java
/** * BASE64/*from www .j ava 2 s . c om*/ * * @param sign * @return * @throws Exception */ public static String encryptBASE64(byte[] sign) throws Exception { return Base64.encodeBase64String(sign); }
From source file:licenceexecuter.Encryptor.java
public static String encrypt(String key, String initVector, String value) { try {//from w w w . j av a 2 s .c o m IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8")); SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); byte[] encrypted = cipher.doFinal(value.getBytes()); return Base64.encodeBase64String(encrypted); } catch (Exception ex) { ex.printStackTrace(); } return null; }