List of usage examples for org.apache.commons.codec.binary Base64 Base64
public Base64()
From source file:com.ddling.utils.MyBase64.java
public static String encodeStr(String str) { Base64 base64 = new Base64(); byte[] enbytes = base64.encodeBase64Chunked(str.getBytes()); return new String(enbytes); }
From source file:net.cheesecan.cheeselobby.session.MD5Base64Hash.java
public static String encrypt(String str) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(str.getBytes());/*from w w w.j a va2s . c o m*/ byte[] enc = md.digest(); return new String(new Base64().encode(enc)); }
From source file:br.com.zeros.tipsandtricks.cryto.EncryptionStrings.java
public static String encrypt(String valueToEnc) throws Exception { Key key = generateKey();/*www .j a v a 2 s . c o m*/ Cipher c = Cipher.getInstance(ALGORITHM); c.init(Cipher.ENCRYPT_MODE, key); byte[] encValue = c.doFinal(valueToEnc.getBytes()); String encryptedValue = new Base64().encodeToString(encValue); return encryptedValue; }
From source file:com.kscs.server.web.source.JavaSourceCode.java
public static void main(String[] args) { JavaSourceCode sourceCode = new JavaSourceCode(); System.out.println("Hello"); // System.out.println(sourceCode.readfile("bean.txt")); Base64 base64 = new Base64(); System.out.println(new String(base64.encode(sourceCode.readfile("bean.txt").getBytes()))); System.out.println(new String(base64.decode(base64.encode(sourceCode.readfile("bean.txt").getBytes())))); }
From source file:com.ucpaas.utils.EncryptUtil.java
/** * BASE64?/*w w w .jav a 2s. c om*/ * @param src * @return * @throws Exception */ public static String base64Encoder(String src) throws Exception { Base64 encoder = new Base64(); return encoder.encodeToString(src.getBytes(UTF8)); }
From source file:com.ddling.client.utils.MyBase64.java
/** * Base64?/*from w w w .j av a 2s.c o m*/ * @param str ?? * @return ?? */ public static String encodeStr(String str) { Base64 base64 = new Base64(); byte[] enbytes = base64.encodeBase64Chunked(str.getBytes()); return new String(enbytes); }
From source file:br.com.zeros.tipsandtricks.cryto.EncryptionStrings.java
public static String decrypt(String encryptedValue) throws Exception { Key key = generateKey();//from www .jav a2 s . c o m Cipher c = Cipher.getInstance(ALGORITHM); c.init(Cipher.DECRYPT_MODE, key); byte[] decordedValue = new Base64().decode(encryptedValue); byte[] decValue = c.doFinal(decordedValue);//////////LINE 50 String decryptedValue = new String(decValue); return decryptedValue; }
From source file:de.hybris.platform.b2b.punchout.services.impl.SymmetricManager.java
public static String encrypt(final String unsecureText, final String key) throws PunchOutCipherException { String encrypted = null;//from www . jav a 2s . c om try { final Key skeySpec = new SecretKeySpec(new Base64().decode(key), ALGORITHM); final Cipher cipher = Cipher.getInstance(ALGORITHM); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); final byte[] encryptedValue = cipher.doFinal(unsecureText.getBytes()); encrypted = new Base64().encodeAsString(encryptedValue); } catch (final NoSuchAlgorithmException | NoSuchPaddingException e) { // should never happen LOG.error("System was unable instantiate Cipher.", e); } catch (InvalidKeyException | BadPaddingException | IllegalBlockSizeException e) { final String msg = "Error occured during encryption." + e.getMessage(); LOG.error(msg); throw new PunchOutCipherException(msg, e); } return encrypted; }
From source file:com.ucpaas.utils.EncryptUtil.java
/** * BASE64?//from w w w. j a v a 2 s . co m * @param dest * @return * @throws Exception */ public static String base64Decoder(String dest) throws Exception { Base64 decoder = new Base64(); return new String(decoder.decode(dest), UTF8); }
From source file:cmusv.mr.carbon.utils.QRCodeGenerator.java
public static Bitmap encodeAsBitmap(String contentsToEncode, int dimension, boolean isEncoded) throws WriterException { if (contentsToEncode == null) { return null; }// w w w .ja va 2 s . co m if (isEncoded) { Base64 base64 = new Base64(); contentsToEncode = new String(base64.encode(contentsToEncode.getBytes())); } Map<EncodeHintType, Object> hints = null; String encoding = guessAppropriateEncoding(contentsToEncode); if (encoding != null) { hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class); hints.put(EncodeHintType.CHARACTER_SET, encoding); } MultiFormatWriter writer = new MultiFormatWriter(); BitMatrix result = writer.encode(contentsToEncode, format, dimension, dimension, hints); int width = result.getWidth(); int height = result.getHeight(); int[] pixels = new int[width * height]; for (int y = 0; y < height; y++) { int offset = y * width; for (int x = 0; x < width; x++) { pixels[offset + x] = result.get(x, y) ? BLACK : WHITE; } } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap.setPixels(pixels, 0, width, 0, 0, width, height); return bitmap; }