List of usage examples for org.apache.commons.codec.binary Base64 decodeBase64
public static byte[] decodeBase64(final byte[] base64Data)
From source file:net.sf.hajdbc.codec.base64.Base64CodecFactory.java
/** * {@inheritDoc}/* w w w .j a v a2s . c o m*/ * @see net.sf.hajdbc.codec.Codec#decode(java.lang.String) */ @Override public String decode(String value) throws SQLException { return new String(Base64.decodeBase64(value.getBytes())); }
From source file:com.spotify.sshagentproxy.RSA.java
/** * Create an {@link RSAPublicKey} from bytes. * @param key Array of bytes representing RSA public key. * @return {@link RSAPublicKey}//from w w w . j a v a2 s .c o m * @throws InvalidKeyException * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException */ static RSAPublicKey from(final byte[] key) throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException { final String s = new String(key); final byte[] encoded; final String decoded; if (s.startsWith(RSA_LABEL)) { decoded = s.split(" ")[1]; encoded = Base64.decodeBase64(decoded); } else { encoded = key; decoded = Base64.encodeBase64String(key); } final Iterator<byte[]> fields = new ByteIterator(encoded); final String sigType = new String(fields.next()); if (!sigType.equals(RSA_LABEL)) { throw new RuntimeException(String.format("Unknown key type %s. This code currently only supports %s.", sigType, RSA_LABEL)); } final RSAPublicKeySpec keySpec = TraditionalKeyParser.parsePemPublicKey(RSA_LABEL + " " + decoded + " "); final KeyFactory keyFactory = KeyFactory.getInstance("RSA"); return (RSAPublicKey) keyFactory.generatePublic(keySpec); }
From source file:cd.go.authentication.ldap.executor.GetPluginIconExecutorTest.java
@Test public void rendersIconInBase64() throws Exception { GoPluginApiResponse response = new GetPluginIconExecutor().execute(); HashMap<String, String> hashMap = new Gson().fromJson(response.responseBody(), HashMap.class); assertThat(hashMap.size(), is(2));//from w ww. j a v a2 s. c om assertThat(hashMap.get("content_type"), is("image/png")); assertThat(Util.readResourceBytes("/gocd_72_72_icon.png"), is(Base64.decodeBase64(hashMap.get("data")))); }
From source file:com.comcast.video.dawg.show.video.BufferedImageCerealizer.java
/** * {@inheritDoc}//from w ww. j av a 2 s . com */ @Override public BufferedImage deCerealize(String cereal, ObjectCache objectCache) throws CerealException { byte[] data = Base64.decodeBase64(cereal); ByteArrayInputStream bais = new ByteArrayInputStream(data); try { try { return ImageIO.read(bais); } catch (IOException e) { throw new CerealException("Failed to deCerealize BufferedImage", e); } } finally { IOUtils.closeQuietly(bais); } }
From source file:com.github.aynu.mosir.core.standard.util.CodecHelper.java
/** * Base64// w w w . j ava2s . com * <dl> * <dt>? * <dd>Base64???? * </dl> * @param data * @return Base64 */ public static byte[] decodeBase64(final byte[] data) { return Base64.decodeBase64(data); }
From source file:com.mirth.connect.plugins.textviewer.TextViewer.java
@Override public void viewAttachments(String channelId, Long messageId, String attachmentId) { // do viewing code Frame frame = new Frame("Text Viewer"); frame.setLayout(new BorderLayout()); try {// w ww .ja va 2s. com Attachment attachment = parent.mirthClient.getAttachment(channelId, messageId, attachmentId); byte[] content = Base64.decodeBase64(attachment.getContent()); boolean isRTF = attachment.getType().toLowerCase().contains("rtf"); //TODO set character encoding JEditorPane jEditorPane = new JEditorPane(isRTF ? "text/rtf" : "text/plain", new String(content)); if (jEditorPane.getDocument().getLength() == 0) { // decoded when it should not have been. i.e.) the attachment data was not encoded. jEditorPane.setText(new String(attachment.getContent())); } jEditorPane.setEditable(false); JScrollPane scrollPane = new javax.swing.JScrollPane(); scrollPane.setViewportView(jEditorPane); frame.add(scrollPane); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { e.getWindow().dispose(); } }); frame.setSize(600, 800); Dimension dlgSize = frame.getSize(); Dimension frmSize = parent.getSize(); Point loc = parent.getLocation(); if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) { frame.setLocationRelativeTo(null); } else { frame.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); } frame.setVisible(true); } catch (Exception e) { parent.alertThrowable(parent, e); } }
From source file:com.vss.ogc.types.WkbSerializer.java
@Override public Geometry toGeometry(String value) throws InvalidGeometryException { return value.isEmpty() ? GeoConvert.getEmptyGeometry() : AbstractGeo.binaryToGeometry(Base64.decodeBase64(value.getBytes())); }
From source file:com.abiquo.abiserver.business.authentication.TokenUtils.java
/** * Returns an array containing each token field * <ul>/* ww w .j a v a 2 s . com*/ * <li>[0] => The token signature.</li> * <li>[1] => The token user name.</li> * <li>[2] => The token expiration time.</li> * </ul> * * @param token The token. * @return The token fields. * @throws Exception */ public static String[] getTokenFields(final String token) throws Exception { String base64Token = token; for (int j = 0; j < base64Token.length() % 4; j++) { base64Token = base64Token + "="; } if (!Base64.isArrayByteBase64(base64Token.getBytes())) { throw new Exception("Token is not Base64 encoded"); } String decodedToken = new String(Base64.decodeBase64(base64Token.getBytes())); return decodedToken.split(":"); }
From source file:com.navercorp.pinpoint.web.filter.URLPatternFilter.java
public URLPatternFilter(Filter fromToFilter, String urlPattern) { if (fromToFilter == null) { throw new NullPointerException("fromToFilter must not be null"); }/*from w w w . j a v a 2 s.c o m*/ this.fromToFilter = fromToFilter; this.urlPattern = new String(Base64.decodeBase64(urlPattern), Charset.forName("UTF-8")); }
From source file:love.sola.netsupport.util.RSAUtil.java
public static String decrypt(String encrypted) { try {/*ww w . jav a 2 s .c o m*/ Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.DECRYPT_MODE, privateKey); byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted)); return new String(original, StandardCharsets.UTF_8); } catch (Exception ex) { ex.printStackTrace(); } return null; }