List of usage examples for org.apache.commons.codec.binary Base64 decodeBase64
public static byte[] decodeBase64(final byte[] base64Data)
From source file:davmail.util.IOUtil.java
/** * Decode base64 input string, return byte array. * * @param encoded Base64 encoded string//ww w . j ava2 s. c o m * @return decoded content as byte arrey * @throws IOException on error */ public static byte[] decodeBase64(String encoded) throws IOException { return Base64.decodeBase64(encoded.getBytes("ASCII")); }
From source file:com.akshffeen.utils.Base64Image.java
/** * Decodes the base64 string into byte array * @param imageDataString - a {@link java.lang.String} * @return byte array//from w w w. j ava 2 s . co m */ public static byte[] decodeImage(String imageDataString) { return Base64.decodeBase64(imageDataString); }
From source file:com.apitrary.orm.codec.base64.Base64Codec.java
/** {@inheritDoc} */ @Override public byte[] decode(String value) { return Base64.decodeBase64(value); }
From source file:net.sf.jftp.config.Crypto.java
private static byte[] base64Decode(String str) throws IOException { return Base64.decodeBase64(str.getBytes()); }
From source file:com.ecyrd.jspwiki.util.Serializer.java
/** * Deserializes a Base64-encoded String into a HashMap. Both the keys and values * must implement {@link java.io.Serializable}. * @param rawString the String contents containing the map to be deserialized * @return the attributes, parsed into a Map * @throws IOException if the contents cannot be parsed for any reason *//*from ww w .j av a 2 s. com*/ @SuppressWarnings("unchecked") public static Map<String, ? extends Serializable> deserializeFromBase64(String rawString) throws IOException { // Decode from Base64-encoded String to byte array byte[] decodedBytes = Base64.decodeBase64(rawString.getBytes("UTF-8")); // Deserialize from the input stream to the Map InputStream bytesIn = new ByteArrayInputStream(decodedBytes); ObjectInputStream in = new ObjectInputStream(bytesIn); HashMap<String, Serializable> attributes; try { attributes = (HashMap<String, Serializable>) in.readObject(); } catch (ClassNotFoundException e) { throw new IOException("Could not deserialiaze user profile attributes. Reason: " + e.getMessage()); } finally { in.close(); } return attributes; }
From source file:com.vimukti.accounter.license.LicensePair.java
public LicensePair(String contactLicenseText) throws LicenseException { this.originalLicenseString = contactLicenseText; if (!new LicenseManager().canDecode(contactLicenseText)) { return;/* w w w . j a v a2 s. c om*/ } try { byte[] decodedBytes = Base64.decodeBase64(contactLicenseText.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(decodedBytes); DataInputStream dIn = new DataInputStream(in); int textLength = dIn.readInt(); this.licenseText = new byte[textLength]; dIn.read(licenseText); this.hash = new byte[dIn.available()]; dIn.read(hash); } catch (IOException e) { throw new LicenseException(e); } }
From source file:com.eviware.loadui.impl.statistics.db.util.TypeConverter.java
public static Object base64ToObject(String s) { byte[] data = Base64.decodeBase64(s); try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data))) { Object o = ois.readObject(); return o; } catch (IOException e) { return null; } catch (ClassNotFoundException e) { return null; }//w w w.j av a 2 s . c o m }
From source file:com.hp.application.automation.tools.EncryptionUtils.java
public static String Decrypt(String text, String key) throws Exception { Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); byte[] keyBytes = new byte[16]; byte[] b = key.getBytes("UTF-8"); int len = b.length; if (len > keyBytes.length) len = keyBytes.length;/*from ww w . j a v a 2s . co m*/ System.arraycopy(b, 0, keyBytes, 0, len); SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES"); IvParameterSpec ivSpec = new IvParameterSpec(keyBytes); cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec); byte[] results = cipher.doFinal(Base64.decodeBase64(text)); return new String(results, "UTF-8"); }
From source file:com.rr.familyPlanning.ui.security.decryptObject.java
/** * Decrypts the String and serializes the object * * @param base64Data//from w w w .ja v a 2 s . c o m * @param base64IV * @return * @throws Exception */ public Object decryptObject(String base64Data, String base64IV) throws Exception { // Decode the data byte[] encryptedData = Base64.decodeBase64(base64Data.getBytes()); // Decode the Init Vector byte[] rawIV = Base64.decodeBase64(base64IV.getBytes()); // Configure the Cipher Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); IvParameterSpec ivSpec = new IvParameterSpec(rawIV); MessageDigest digest = MessageDigest.getInstance("SHA-256"); digest.update(keyString.getBytes()); byte[] key = new byte[16]; System.arraycopy(digest.digest(), 0, key, 0, key.length); SecretKeySpec keySpec = new SecretKeySpec(key, "AES"); cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec); // Decrypt the data.. byte[] decrypted = cipher.doFinal(encryptedData); // Deserialize the object ByteArrayInputStream stream = new ByteArrayInputStream(decrypted); ObjectInput in = new ObjectInputStream(stream); Object obj = null; try { obj = in.readObject(); } finally { stream.close(); in.close(); } return obj; }
From source file:edu.mit.ll.graphulo.util.SerializationUtil.java
public static void deserializeWritableBase64(Writable writable, String str) { byte[] b = Base64.decodeBase64(str); deserializeWritable(writable, b); }