List of usage examples for org.apache.commons.codec.binary Base64 Base64
public Base64()
From source file:zipB64.java
protected static String decodeMessage(String encodedMessage) { try {// w w w .j ava 2 s. com Base64 b = new Base64(); byte[] decodedBase64 = b.decode(encodedMessage.getBytes()); // Decompress the bytes ByteArrayInputStream bytesIn = new ByteArrayInputStream(decodedBase64); InflaterInputStream inflater = new InflaterInputStream(bytesIn); int nbRead = 0; StringBuilder sb = new StringBuilder(); while (nbRead >= 0) { byte[] result = new byte[500]; nbRead = inflater.read(result, 0, result.length); if (nbRead > 0) { sb.append(new String(result, 0, nbRead, "UTF-8")); } } return sb.toString(); } catch (Exception e) { return "zut"; } }
From source file:com._64bitlabs.util.Encryptors.java
/** * Encrypts string value with the specified AES algorithm * @param Data string to be encrypted// w w w . j a v a2s . c o m * @return encrypted string */ public static String encrypt(String Data) { try { Key key = generateKey(); Cipher c = Cipher.getInstance(ALGORITHM); c.init(Cipher.ENCRYPT_MODE, key); byte[] encVal = c.doFinal(Data.getBytes()); Base64 encoder = new Base64(); String encryptedValue = new String(encoder.encode(encVal)).trim(); return encryptedValue; } catch (Exception e) { return null; } }
From source file:com.aurel.track.attachment.BrowseFileBL.java
public static Integer storeImage(Integer workItemID, TPersonBean person, Locale locale, String imageData, boolean addToHistory) { String description = ""; String fileName = "image.jpg"; Integer attachKey = null;//from w w w .j a v a 2 s.co m if (imageData != null) { byte[] bytearray = new Base64().decode(imageData); InputStream is = new ByteArrayInputStream(bytearray); try { TAttachmentBean attachmentBean = AttachBL.save(workItemID, description, fileName, is, person.getObjectID()); attachKey = attachmentBean.getObjectID(); if (addToHistory) { //add to history HistorySaverBL.addAttachment(workItemID, person.getObjectID(), locale, fileName, description, Long.valueOf(bytearray.length), false); } } catch (AttachBLException e) { LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } return attachKey; }
From source file:com.vaadin.testbench.screenshot.ImageUtil.java
/** * Encodes target image to a Base64 string * /*from ww w .j a v a 2s . com*/ * @param image * BufferedImage to encode to String * @return Base64 encoded String of image */ public static String encodeImageToBase64(BufferedImage image) { String encodedImage = ""; Base64 encoder = new Base64(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "png", baos); baos.flush(); byte[] encodedBytes = encoder.encode(baos.toByteArray()); encodedImage = new String(encodedBytes); baos.close(); } catch (IOException e) { e.printStackTrace(); } return encodedImage; }
From source file:de.openflorian.crypt.CipherKeyGenerator.java
/** * Generate Cipher Secret<br/>/*from w w w.j ava2s. c o m*/ * <br/> * Secret is generated by Blowfish {@link KeyGenerator} and a system default * {@link SecureRandom} provider and Base64 encoded afterwards. * * @return Base64 encoded {@link SecureRandom} generated encryption key * @throws GeneralSecurityException */ public static String generateKey() throws GeneralSecurityException { try { KeyGenerator gen = KeyGenerator.getInstance("Blowfish"); gen.init(192, new SecureRandom()); SecretKey key = gen.generateKey(); return new String(new Base64().encode(key.getEncoded())).trim(); } catch (Exception e) { log.error(e.getMessage(), e); throw new GeneralSecurityException(e.getMessage(), e); } }
From source file:adminpassword.Decryption.java
@SuppressWarnings("static-access") public String decrypt(String encryptedText, String idKey) throws Exception { String password = idKey;// www . j a v a2 s .c om Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); //strip off the salt and iv ByteBuffer buffer = ByteBuffer.wrap(new Base64().decode(encryptedText)); byte[] saltBytes = new byte[20]; buffer.get(saltBytes, 0, saltBytes.length); byte[] ivBytes1 = new byte[cipher.getBlockSize()]; buffer.get(ivBytes1, 0, ivBytes1.length); byte[] encryptedTextBytes = new byte[buffer.capacity() - saltBytes.length - ivBytes1.length]; buffer.get(encryptedTextBytes); // Deriving the key SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), saltBytes, 65556, 256); SecretKey secretKey = factory.generateSecret(spec); SecretKeySpec secret = new SecretKeySpec(secretKey.getEncoded(), "AES"); cipher.init(Cipher.DECRYPT_MODE, secret, new IvParameterSpec(ivBytes1)); byte[] decryptedTextBytes = null; try { decryptedTextBytes = cipher.doFinal(encryptedTextBytes); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } return new String(decryptedTextBytes); }
From source file:cn.crawin.msg.gateway.http.MessageDigestUtil.java
/** * MD5??Base64???//from w w w. j av a 2 s . c o m * * @return */ public static String base64AndMD5(byte[] bytes) { if (bytes == null) { throw new IllegalArgumentException("bytes can not be null"); } try { final MessageDigest md = MessageDigest.getInstance("MD5"); md.reset(); md.update(bytes); final Base64 base64 = new Base64(); final byte[] enbytes = base64.encode(md.digest()); return new String(enbytes); } catch (final NoSuchAlgorithmException e) { throw new IllegalArgumentException("unknown algorithm MD5"); } }
From source file:com.amalto.workbench.utils.PasswordUtil.java
public static String decryptPasswordBase64(String encodedPassword) { Base64 base64 = new Base64(); byte[] debytes = null; String decodeStr = null;//from w w w . j a va2s .co m debytes = base64.decode(encodedPassword.getBytes()); decodeStr = new String(debytes); return decodeStr; }
From source file:cross.io.misc.Base64Util.java
/** * * @param base64String/*from w ww . ja v a2 s.co m*/ * @param bigEndian * @return * @throws DecoderException */ public static List<Float> base64StringToFloatList(final String base64String, final boolean bigEndian) throws DecoderException { final Base64 base64 = new Base64(); final byte[] encoded = base64String.getBytes(); final byte[] raw = base64.decode(encoded); final List<Float> floatList = Base64Util.byteArrayToFloatList(raw, bigEndian); return floatList; }
From source file:com.sun.syndication.propono.atom.client.BasicAuthStrategy.java
public BasicAuthStrategy(String username, String password) { this.credentials = new String(new Base64().encode((username + ":" + password).getBytes())); }