List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64
public static byte[] encodeBase64(final byte[] binaryData)
From source file:birch.util.EncryptionKeyFileUtil.java
public static String createKey(String cipher, int keysize) throws InvalidKeyException, IllegalBlockSizeException, NoSuchAlgorithmException, NoSuchPaddingException { KeyGenerator keyGenerator;/*from ww w . j a v a 2 s . co m*/ Key key; keyGenerator = KeyGenerator.getInstance(cipher); keyGenerator.init(keysize); key = keyGenerator.generateKey(); return new String(Base64.encodeBase64(key.getEncoded())); }
From source file:de.scrubstudios.srvmon.notificator.classes.Crypt.java
public static String encrypt(String key, String data) { byte[] encryptedData = null; SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES"); try {/*from www . ja v a2s .c o m*/ Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, keySpec); encryptedData = cipher.doFinal(data.getBytes()); byte[] encr64 = Base64.encodeBase64(encryptedData); //System.out.println(new String(encr64)); return new String(encr64); } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException ex) { Logger.getLogger(Crypt.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:cn.newtouch.util.utils.encode.EncodeUtils.java
/** * Base64?./*from w w w . j a va 2 s . c om*/ */ public static String base64Encode(byte[] input) { return new String(Base64.encodeBase64(input)); }
From source file:com.openbravo.pos.util.Base64Encoder.java
public static String encode(byte[] raw) { try {//from www .j a va2 s .c o m return new String(Base64.encodeBase64(raw), "ASCII"); } catch (UnsupportedEncodingException e) { return null; } }
From source file:dtu.ds.warnme.app.utils.SecurityUtils.java
public static String hashMD5Base64(String stringToHash) { if (StringUtils.isEmpty(stringToHash)) { return StringUtils.EMPTY; }/*from ww w . j ava 2 s. c o m*/ try { byte[] bytes = stringToHash.getBytes(CHARSET_UTF8); byte[] sha512bytes = DigestUtils.md5(bytes); byte[] base64bytes = Base64.encodeBase64(sha512bytes); return new String(base64bytes, CHARSET_UTF8); } catch (UnsupportedEncodingException e) { Log.e(TAG, "This system does not support required hashing algorithms.", e); throw new IllegalStateException("This system does not support required hashing algorithms.", e); } }
From source file:hudson.util.Protector.java
public static String protect(String secret) { try {/*from w w w . ja va 2s. c o m*/ Cipher cipher = Secret.getCipher(ALGORITHM); cipher.init(Cipher.ENCRYPT_MODE, DES_KEY); return new String(Base64.encodeBase64(cipher.doFinal((secret + MAGIC).getBytes("UTF-8")))); } catch (GeneralSecurityException e) { throw new Error(e); // impossible } catch (UnsupportedEncodingException e) { throw new Error(e); // impossible } }
From source file:com.amazonaws.tvm.AESEncryption.java
public static String wrap(String clearText, String key) throws Exception { byte[] iv = getIv(); byte[] cipherText = encrypt(clearText, key, iv); byte[] wrapped = new byte[iv.length + cipherText.length]; System.arraycopy(iv, 0, wrapped, 0, iv.length); System.arraycopy(cipherText, 0, wrapped, 16, cipherText.length); return new String(Base64.encodeBase64(wrapped)); }
From source file:jshm.util.Crypto.java
public static String encrypt(String clearText) { LOG.finest("entered Crypto.encrypt()"); LOG.finer("Base64 encoding clearText"); clearText = new String(Base64.encodeBase64(clearText.getBytes())); LOG.finest("exiting Crypto.encrypt()"); return clearText; }
From source file:com.apabi.qrcode.utils.EncodeUtils.java
/** * Base64?.//from w w w . ja v a 2s . c om */ public static String base64Encode(final byte[] input) { return new String(Base64.encodeBase64(input)); }
From source file:com.aliyun.oss.urlsign.common.utils.BinaryUtil.java
public static String toBase64String(byte[] binaryData) { // return Base64.encodeToString(binaryData,Base64.DEFAULT); return new String(Base64.encodeBase64(binaryData)); }