List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64String
public static String encodeBase64String(final byte[] binaryData)
From source file:cn.vlabs.duckling.aone.client.impl.EmailNameEncoding.java
private String encodeByte(byte[] data) { return Base64.encodeBase64String(data); }
From source file:com.hurence.logisland.processor.hbase.io.TestJsonQualifierAndValueRowSerializer.java
@Test public void testSerializeWithBase64() throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final RowSerializer rowSerializer = new JsonQualifierAndValueRowSerializer(StandardCharsets.UTF_8, StandardCharsets.UTF_8, true); rowSerializer.serialize(rowKey, cells, out); final String qual1Base64 = Base64.encodeBase64String(QUAL1.getBytes(StandardCharsets.UTF_8)); final String val1Base64 = Base64.encodeBase64String(VAL1.getBytes(StandardCharsets.UTF_8)); final String qual2Base64 = Base64.encodeBase64String(QUAL2.getBytes(StandardCharsets.UTF_8)); final String val2Base64 = Base64.encodeBase64String(VAL2.getBytes(StandardCharsets.UTF_8)); final String json = out.toString(StandardCharsets.UTF_8.name()); Assert.assertEquals(// w ww. j a v a 2 s . c o m "{\"" + qual1Base64 + "\":\"" + val1Base64 + "\", \"" + qual2Base64 + "\":\"" + val2Base64 + "\"}", json); }
From source file:de.roderick.weberknecht.WebSocketHandshake.java
private String createNonce() { byte[] nonce = new byte[16]; for (int i = 0; i < 16; i++) { nonce[i] = (byte) rand(0, 255); }//from www . j a v a2 s. co m return Base64.encodeBase64String(nonce); }
From source file:ioc.wiki.processingmanager.http.HttpFileSender.java
/** * Prepara la comanda a enviar al servidor, l'envia i rep la resposta en un string. * Cont informaci sobre el xit de guardar el fitxer al servidor. * @return Retorna un string amb la resposta del servidor. *///from w ww . j a v a 2s.co m @Override public String sendCommand() { super.prepareCommand(); try { ((HttpURLConnection) urlConnection).setRequestMethod(REQUEST_METHOD); urlConnection.setRequestProperty(PROPERTY_CONTENT_TYPE, content_type + boundary); DataOutputStream request = new DataOutputStream(urlConnection.getOutputStream()); //Capalera fitxer request.writeBytes(twoHyphens + boundary + crlf); request.writeBytes(contentDispositionFile + quote + this.destFilename + quote + crlf); request.writeBytes(contentTypeFile + crlf); request.writeBytes(contentTransferEncodingFile + crlf); request.writeBytes(crlf); //IMAGE String base64Image = Base64.encodeBase64String(this.image); request.writeBytes(base64Image); //Tancament fitxer request.writeBytes(crlf); request.writeBytes(twoHyphens + boundary + twoHyphens + crlf); request.flush(); request.close(); } catch (IOException ex) { throw new ProcessingRtURLException(ex); } return super.receiveResponse(); }
From source file:com.cloud.upgrade.dao.Upgrade41000to41100.java
private void validateUserDataInBase64(Connection conn) { try (final PreparedStatement selectStatement = conn .prepareStatement("SELECT `id`, `user_data` FROM `cloud`.`user_vm` WHERE `user_data` IS NOT NULL;"); final ResultSet selectResultSet = selectStatement.executeQuery()) { while (selectResultSet.next()) { final Long userVmId = selectResultSet.getLong(1); final String userData = selectResultSet.getString(2); if (Base64.isBase64(userData)) { final String newUserData = Base64.encodeBase64String(Base64.decodeBase64(userData.getBytes())); if (!userData.equals(newUserData)) { try (final PreparedStatement updateStatement = conn.prepareStatement( "UPDATE `cloud`.`user_vm` SET `user_data` = ? WHERE `id` = ? ;")) { updateStatement.setString(1, newUserData); updateStatement.setLong(2, userVmId); updateStatement.executeUpdate(); } catch (SQLException e) { LOG.error("Failed to update cloud.user_vm user_data for id:" + userVmId + " with exception: " + e.getMessage()); throw new CloudRuntimeException( "Exception while updating cloud.user_vm for id " + userVmId, e); }//www . j a v a2 s . co m } } else { // Update to NULL since it's invalid LOG.warn("Removing user_data for vm id " + userVmId + " because it's invalid"); LOG.warn("Removed data was: " + userData); try (final PreparedStatement updateStatement = conn .prepareStatement("UPDATE `cloud`.`user_vm` SET `user_data` = NULL WHERE `id` = ? ;")) { updateStatement.setLong(1, userVmId); updateStatement.executeUpdate(); } catch (SQLException e) { LOG.error("Failed to update cloud.user_vm user_data for id:" + userVmId + " to NULL with exception: " + e.getMessage()); throw new CloudRuntimeException( "Exception while updating cloud.user_vm for id " + userVmId + " to NULL", e); } } } } catch (SQLException e) { throw new CloudRuntimeException( "Exception while validating existing user_vm table's user_data column to be base64 valid with padding", e); } if (LOG.isDebugEnabled()) { LOG.debug("Done validating base64 content of user data"); } }
From source file:microsoft.exchange.webservices.data.misc.IFunctionsTest.java
@Test public void testBase64Encoder() { final byte[] value = StringUtils.getBytesUtf8("123"); final IFunctions.Base64Encoder f = IFunctions.Base64Encoder.INSTANCE; Assert.assertEquals(Base64.encodeBase64String(value), f.func(value)); }
From source file:com.comcast.video.dawg.show.key.SendKeyThread.java
protected KeyInput getIrClient(MetaStb stb, String remoteType) { KeyInput inp = remotePluginManager.getKeyInput(stb, remoteType); if ((inp instanceof IrClient) && (this.jwt != null)) { String b64 = Base64.encodeBase64String(this.jwt.getBytes()); ((IrClient) inp).getClient().addDefaultHeader("Authorization", "Bearer " + b64); }//from ww w. j av a2 s .c o m return inp; }
From source file:br.com.topsys.cd.applet.AssinaturaApplet.java
public String assinar(byte[] dados) { String retorno = null;/* ww w. j a va 2 s .c om*/ try { X509Certificado certificadoAux = new X509Certificado(Base64.decodeBase64(this.certificado)); if (certificadoAux.equals(this.certificadoDigital.getX509Certificado())) { retorno = Base64.encodeBase64String( new AssinaturaDigital().assinarDocumento(this.certificadoDigital, dados)); } else { JOptionPane.showMessageDialog(null, "Certificado digital diferente do usurio do sistema!", "Aviso", JOptionPane.ERROR_MESSAGE); } } catch (CertificadoDigitalException | ExcecaoX509 ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "Aviso", JOptionPane.ERROR_MESSAGE); this.closeError(); } return retorno; }
From source file:com.squid.kraken.v4.api.core.client.ClientServiceBaseImpl.java
private String encodeToPEM(byte[] keyBytes, String name) { String key = Base64.encodeBase64String(keyBytes); StringBuilder sb = new StringBuilder(); for (int i = 0; i < key.length(); i++) { if ((i % 65) == 0) { sb.append("\n"); }/*from www.j a va2 s . c o m*/ sb.append(key.charAt(i)); } String keyFormatted = sb.toString(); if (!keyFormatted.endsWith("\n")) { keyFormatted = keyFormatted + "\n"; } keyFormatted = "-----BEGIN RSA " + name + " KEY-----" + keyFormatted + "-----END RSA " + name + " KEY-----"; return keyFormatted; }
From source file:com.cprassoc.solr.auth.security.Sha256AuthenticationProvider.java
public static String sha256(String password, String saltKey) { MessageDigest digest;// w w w . ja v a 2s .c om try { digest = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { log.error(e.getMessage(), e); return null;//should not happen } if (saltKey != null) { digest.reset(); digest.update(Base64.decodeBase64(saltKey)); } byte[] btPass = digest.digest(password.getBytes(StandardCharsets.UTF_8)); digest.reset(); btPass = digest.digest(btPass); return Base64.encodeBase64String(btPass); }