Java Code Examples for net.iharder.Base64#decode()

The following examples show how to use net.iharder.Base64#decode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MusicController.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
@BotCommandHandler
private void deserialize(Message message, String content) throws IOException {
  outputChannel.set((TextChannel) message.getChannel());
  connectToFirstVoiceChannel(guild.getAudioManager());

  byte[] bytes = Base64.decode(content);

  MessageInput inputStream = new MessageInput(new ByteArrayInputStream(bytes));
  DecodedTrackHolder holder;

  while ((holder = manager.decodeTrack(inputStream)) != null) {
    if (holder.decodedTrack != null) {
      scheduler.addToQueue(holder.decodedTrack);
    }
  }
}
 
Example 2
Source File: ChaiHelpdeskAnswer.java    From ldapchai with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static String decryptValue( final String value, final String key )
{
    try
    {
        if ( value == null || value.length() < 1 )
        {
            return "";
        }

        final SecretKey secretKey = makeKey( key );
        final byte[] decoded = Base64.decode( value, Base64.URL_SAFE | Base64.GZIP );
        final Cipher cipher = Cipher.getInstance( "AES" );
        cipher.init( Cipher.DECRYPT_MODE, secretKey );
        final byte[] decrypted = cipher.doFinal( decoded );
        return new String( decrypted );
    }
    catch ( Exception e )
    {
        final String errorMsg = "unexpected error performing helpdesk answer decrypt operation: " + e.getMessage();
        throw new IllegalArgumentException( errorMsg );
    }
}
 
Example 3
Source File: KeyGenerator.java    From syndesis with Apache License 2.0 5 votes vote down vote up
/**
 * Used to extract the time information that is encoded to each
 * generated key.
 */
public static long getKeyTimeMillis(String key) throws IOException {
    byte[] decoded = Base64.decode(stripPreAndSuffix(key), Base64.ORDERED);
    if (decoded.length != 15) {
        throw new IOException("Invalid key: size is incorrect.");
    }
    ByteBuffer buffer = ByteBuffer.allocate(8);
    buffer.position(2);
    buffer.put(decoded, 0 ,6);
    buffer.flip();
    return buffer.getLong();
}
 
Example 4
Source File: IndexerDefinitionJsonSerDeser.java    From hbase-indexer with Apache License 2.0 5 votes vote down vote up
private byte[] getByteArrayProperty(ObjectNode node, String property) {
    try {
        String string = JsonUtil.getString(node, property, null);
        if (string == null)
            return null;
        return Base64.decode(string);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 5
Source File: Utils.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static byte[] base64decode(@Nonnull final String text) throws IOException {
  return Base64.decode(text);
}
 
Example 6
Source File: JsonRpcBasicServer.java    From jsonrpc4j with MIT License 4 votes vote down vote up
/**
 * Returns parameters into an {@link InputStream} of JSON data.
 *
 * @param method the method
 * @param id     the id
 * @param params the base64 encoded params
 * @return the {@link InputStream}
 * @throws IOException on error
 */
static InputStream createInputStream(String method, String id, String params) throws IOException {
	
	StringBuilder envelope = new StringBuilder();
	
	envelope.append("{\"");
	envelope.append(JSONRPC);
	envelope.append("\":\"");
	envelope.append(VERSION);
	envelope.append("\",\"");
	envelope.append(ID);
	envelope.append("\":");
	
	// the 'id' value is assumed to be numerical.
	
	if (null != id && !id.isEmpty()) {
		envelope.append(id);
	} else {
		envelope.append("null");
	}
	
	envelope.append(",\"");
	envelope.append(METHOD);
	envelope.append("\":");
	
	if (null != method && !method.isEmpty()) {
		envelope.append('"');
		envelope.append(method);
		envelope.append('"');
	} else {
		envelope.append("null");
	}
	envelope.append(",\"");
	envelope.append(PARAMS);
	envelope.append("\":");
	
	if (null != params && !params.isEmpty()) {
		String decodedParams;
		
		// some specifications suggest that the GET "params" query parameter should be Base64 encoded and
		// some suggest not.  Try to deal with both scenarios -- the code here was previously only doing
		// Base64 decoding.
		// http://www.simple-is-better.org/json-rpc/transport_http.html
		// http://www.jsonrpc.org/historical/json-rpc-over-http.html#encoded-parameters
		
		if (BASE64_PATTERN.matcher(params).matches()) {
			decodedParams = new String(Base64.decode(params), StandardCharsets.UTF_8);
		} else {
			switch (params.charAt(0)) {
				case '[':
				case '{':
					decodedParams = params;
					break;
				
				default:
					throw new IOException("badly formed 'param' parameter starting with; [" + params.charAt(0) + "]");
			}
		}
		
		envelope.append(decodedParams);
	} else {
		envelope.append("[]");
	}
	
	envelope.append('}');
	
	return new ByteArrayInputStream(envelope.toString().getBytes(StandardCharsets.UTF_8));
}