List of usage examples for org.apache.commons.codec.binary Base64 decodeBase64
public static byte[] decodeBase64(final byte[] base64Data)
From source file:com.blackcrowsys.sinscrypto.AesEncryptor.java
@Override public String decrypt(String secretkey, String iv, String toDecrypt) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, DecoderException { Cipher cipher = Cipher.getInstance(AESMODE); SecretKeySpec secretKeySpec = new SecretKeySpec(secretkey.getBytes(), AES); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, new IvParameterSpec(Hex.decodeHex(iv.toCharArray()))); return new String(cipher.doFinal(Base64.decodeBase64(toDecrypt))); }
From source file:com.monitor.baseservice.utils.XCodeUtil.java
public static String base64ToBase16(String str) { byte[] data = Base64.decodeBase64(str); int length = data.length; StringBuffer sb = new StringBuffer(); for (int i = 0; i < length; i++) { byte d = data[i]; int dd = 0x000000ff & d; String s = Integer.toHexString(dd); if (s.length() == 1) { sb.append("0"); }/*from w w w. j a v a2 s .c o m*/ sb.append(s); } return sb.toString(); }
From source file:net.mooncloud.hadoop.hive.ql.udf.UDFRSAVerify.java
public BooleanWritable evaluate(Text n, Text sign, Text publicKey) { if (n == null || sign == null || publicKey == null) { return null; }/* ww w . j av a 2 s . c o m*/ try { byte[] publicKeybytes = new byte[publicKey.getLength()]; System.arraycopy(publicKey.getBytes(), 0, publicKeybytes, 0, publicKey.getLength()); byte[] publicKeydecoded = Base64.decodeBase64(publicKeybytes); byte[] signbytes = new byte[sign.getLength()]; System.arraycopy(sign.getBytes(), 0, signbytes, 0, sign.getLength()); byte[] signdecoded = Base64.decodeBase64(signbytes); result = new BooleanWritable(RSAUtils.verify(n.getBytes(), publicKeydecoded, signdecoded)); } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:com.zotoh.crypto.BCOfuscator.java
private String decrypt(String encrypted) throws Exception { if (isEmpty(encrypted)) { return encrypted; }//from ww w. j av a2 s.co m PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new DESedeEngine())); byte[] p = Base64.decodeBase64(encrypted), out = new byte[1024]; ByteOStream baos = new ByteOStream(); int c; // initialise the cipher with the key bytes, for encryption cipher.init(false, new KeyParameter(getKey())); c = cipher.processBytes(p, 0, p.length, out, 0); if (c > 0) { baos.write(out, 0, c); } c = cipher.doFinal(out, 0); if (c > 0) { baos.write(out, 0, c); } return asString(baos.asBytes()); }
From source file:com.alfaariss.oa.util.ModifiedBase64.java
/** * Decodes the supplied data String.// www .j a v a 2s.c o m * * @param data string containing the data * @param charset Charset used for encoding the byte array to a <tt>String</tt> * @return String decoded byte array representation * @throws UnsupportedEncodingException if supplied charset isn't supported */ public static byte[] decode(String data, String charset) throws UnsupportedEncodingException { String sEncoded = data.replaceAll("-", "+"); sEncoded = sEncoded.replaceAll("_", "/"); while (sEncoded.length() % 4 != 0) { sEncoded = sEncoded + "="; } byte[] baDecoded = Base64.decodeBase64(sEncoded.getBytes(charset)); return baDecoded; }
From source file:io.smartspaces.scheduling.quartz.orientdb.internal.util.SerialUtils.java
public static Map<String, ?> deserialize(JobDataMap jobDataMap, String clob) throws IOException { try {//from w w w . j a v a2s.c o m byte[] bytes = Base64.decodeBase64(clob); return stringMapFromBytes(bytes); } catch (NotSerializableException e) { rethrowEnhanced(jobDataMap, e); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return Collections.emptyMap(); }
From source file:com.shenit.commons.codec.Base64Utils.java
/** * Base64?/*from ww w . jav a 2 s . c o m*/ * * @param str * @param enc * @return */ public static String base64DecodeHex(String str, String enc) { if (StringUtils.isEmpty(str)) return null; enc = enc == null ? HttpUtils.ENC_UTF8 : enc; try { return new String(Base64.decodeBase64(str.getBytes(enc)), enc); } catch (UnsupportedEncodingException e) { LOG.warn("[base64Decode] not supported encoding", e); } return null; }
From source file:com.amazon.s3.util.BinaryUtils.java
/** * Converts a Base64-encoded string to the original byte data. * /*www . j a va 2s .c om*/ * @param b64Data * a Base64-encoded string to decode. * * @return bytes decoded from a Base64 string. */ public static byte[] fromBase64(String b64Data) { byte[] decoded; try { decoded = Base64.decodeBase64(b64Data.getBytes(DEFAULT_ENCODING)); } catch (UnsupportedEncodingException uee) { // Shouldn't happen if the string is truly Base64 encoded. Log.w(TAG, "Tried to Base64-decode a String with the wrong encoding: ", uee); decoded = Base64.decodeBase64(b64Data.getBytes()); } return decoded; }
From source file:cl.cla.web.firma.servlet.ServletDetalleDocumentoPdf.java
private void generarPdf(HttpServletRequest request, HttpServletResponse response) throws IOException { String p = request.getParameter("p") != null ? request.getParameter("p") : ""; System.out.println("p " + p); String nombreArchivo = ""; switch (p) {//from w w w. ja v a 2 s . co m case "1-1BSUGWN": nombreArchivo = "C:\\pdf\\a.txt"; break; case "1-1BSUGWR": nombreArchivo = "C:\\pdf\\b.txt"; break; case "1-1BSUGWP": nombreArchivo = "C:\\pdf\\c.txt"; break; default: } System.out.println("nombreArchivo " + nombreArchivo); FileReader fr = null; String base64File = generarBase64(nombreArchivo); System.out.println(base64File); System.out.println("detalleRepController " + detalleRepController); byte[] encoded = Base64.decodeBase64(base64File); // try { // DetalleDocumentoVO detalleDocumentoVO = detalleRepController.detalleRepINOperation(p); // encoded=detalleDocumentoVO.getArchivo(); // } catch (Exception ex) { // encoded =Base64.decodeBase64(generarBase64Vacio()); // } File pdfFile = new File("c.pdf"); FileUtils.writeByteArrayToFile(pdfFile, encoded); response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "inline; filename=a.pdf"); response.setContentLength((int) pdfFile.length()); FileInputStream fileInputStream = new FileInputStream(pdfFile); OutputStream responseOutputStream = response.getOutputStream(); int bytes; while ((bytes = fileInputStream.read()) != -1) { responseOutputStream.write(bytes); } fileInputStream.close(); responseOutputStream.close(); }