Example usage for java.util Base64 getDecoder

List of usage examples for java.util Base64 getDecoder

Introduction

In this page you can find the example usage for java.util Base64 getDecoder.

Prototype

public static Decoder getDecoder() 

Source Link

Document

Returns a Decoder that decodes using the Basic type base64 encoding scheme.

Usage

From source file:org.wso2.carbon.siddhi.editor.core.internal.EditorMicroservice.java

@GET
@Path("/workspace/list")
@Produces("application/json")
public Response directoriesInPath(@QueryParam("path") String path) {
    try {/*from  www  .ja va 2 s  .c  o  m*/
        return Response.status(Response.Status.OK)
                .entity(workspace.listDirectoriesInPath(
                        new String(Base64.getDecoder().decode(path), Charset.defaultCharset())))
                .type(MediaType.APPLICATION_JSON).build();
    } catch (IOException e) {
        return Response.serverError().entity("failed." + e.getMessage()).build();
    } catch (Throwable ignored) {
        return Response.serverError().entity("failed").build();
    }
}

From source file:org.openhab.binding.loxone.internal.core.LxWsSecurityToken.java

@Override
String decryptControl(String control) {
    String string = control;/*from   w  w w  .  j  a  v a2  s  .com*/
    if (!encryptionReady || !string.startsWith(CMD_ENCRYPT_CMD)) {
        return string;
    }
    string = string.substring(CMD_ENCRYPT_CMD.length());
    try {
        byte[] bytes = Base64.getDecoder().decode(string);
        bytes = aesDecryptCipher.doFinal(bytes);
        string = new String(bytes, "UTF-8");
        string = string.replaceAll("\0+.*$", "");
        string = string.replaceFirst("^salt/[^/]*/", "");
        string = string.replaceFirst("^nextSalt/[^/]*/[^/]*/", "");
        return string;
    } catch (IllegalArgumentException e) {
        logger.debug("[{}] Failed to decode base64 string: {}", debugId, string);
    } catch (IllegalBlockSizeException | BadPaddingException e) {
        logger.warn("[{}] Command decryption failed: {}", debugId, e.getMessage());
    } catch (UnsupportedEncodingException e) {
        logger.warn("[{}] Unsupported encoding for decrypted bytes to string conversion.", debugId);
    }
    return string;
}

From source file:org.wso2.is.portal.user.client.api.ChallengeQuestionManagerClientServiceImpl.java

@Override
public void deleteChallengeQuestionForUser(String userUniqueId, String questionId, String questionSetId)
        throws IdentityRecoveryException, IdentityStoreException, UserNotFoundException, UserPortalUIException {

    if (challengeQuestionManager == null || realmService == null) {
        throw new IdentityRecoveryException("Challenge question manager or Realm service is not available.");
    }//w  ww .  j  a v  a 2 s  . c  om
    int minNumOfSecurityQuestions = challengeQuestionManager.getMinimumNoOfChallengeQuestionsToAnswer();
    User user = realmService.getIdentityStore().getUser(userUniqueId);

    List<UserChallengeAnswer> existingAnswers = challengeQuestionManager
            .getChallengeAnswersOfUser(userUniqueId);
    if (minNumOfSecurityQuestions < existingAnswers.size()) {
        existingAnswers.removeIf(answer -> StringUtils.equals(answer.getQuestion().getQuestionId(), questionId)
                && StringUtils.equals(answer.getQuestion().getQuestionSetId(),
                        new String(Base64.getDecoder().decode(questionSetId.getBytes(StandardCharsets.UTF_8)),
                                StandardCharsets.UTF_8)));
        challengeQuestionManager.setChallengesOfUser(user, existingAnswers);
    } else {
        String error = "Cannot delete security question. You need to have at least" + minNumOfSecurityQuestions
                + "security questions";
        throw new UserPortalUIException(error);
    }
}

From source file:de.steilerdev.myVerein.server.model.User.java

@Transient
@JsonIgnore//  w  w  w  .  j av a  2 s .  co m
public boolean setDeviceTokenBase64Encoded(String deviceToken) {
    if (deviceToken != null && !deviceToken.isEmpty()) {
        byte[] decodedToken = Base64.getDecoder().decode(deviceToken);
        if (decodedToken.length == 32) {
            this.deviceToken = decodedToken;
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}

From source file:org.wso2.carbon.siddhi.editor.core.internal.EditorMicroservice.java

@GET
@Path("/workspace/exists")
@Produces("application/json")
public Response fileExists(@QueryParam("path") String path) {
    try {/*from ww  w  . j  a  va2s  .c o m*/
        return Response.status(Response.Status.OK)
                .entity(workspace.exists(
                        Paths.get(new String(Base64.getDecoder().decode(path), Charset.defaultCharset()))))
                .type(MediaType.APPLICATION_JSON).build();
    } catch (IOException e) {
        return Response.serverError().entity("failed." + e.getMessage()).build();
    } catch (Throwable ignored) {
        return Response.serverError().entity("failed").build();
    }
}

From source file:co.runrightfast.vertx.demo.testHarness.jmx.DemoMXBeanImpl.java

@Override
public String decrypt(final @NonNull String data) {
    return new String(decryption.apply(Base64.getDecoder().decode(data)), UTF_8);
}

From source file:org.wso2.carbon.siddhi.editor.core.internal.ServiceComponent.java

@GET
@Path("/workspace/listFilesInPath")
@Produces("application/json")
public Response listFilesInPath(@QueryParam("path") String path) {
    try {/*from  w  ww .j ava 2s.  co  m*/
        return Response.status(Response.Status.OK)
                .entity(workspace.listDirectoryFiles(new String(Base64.getDecoder().decode(path))))
                .type(MediaType.APPLICATION_JSON).build();
    } catch (IOException e) {
        return Response.serverError().entity("failed." + e.getMessage()).build();
    } catch (Throwable ignored) {
        return Response.serverError().entity("failed").build();
    }

}

From source file:org.apache.pulsar.websocket.ReaderHandler.java

private MessageId getMessageId() throws IOException {
    MessageId messageId = MessageId.latest;
    if (isNotBlank(queryParams.get("messageId"))) {
        if (queryParams.get("messageId").equals("earliest")) {
            messageId = MessageId.earliest;
        } else if (!queryParams.get("messageId").equals("latest")) {
            messageId = MessageIdImpl.fromByteArray(Base64.getDecoder().decode(queryParams.get("messageId")));
        }/* w  ww.java  2s . co m*/
    }
    return messageId;
}

From source file:com.dtolabs.rundeck.jetty.jaas.JettyCachingLdapLoginModule.java

boolean isBase64(String chkBase64) {
    if (isHex(chkBase64))
        return false;
    try {/*from   ww  w  .ja v  a  2 s  .co  m*/
        Base64.getDecoder().decode(chkBase64);
        return chkBase64.replace(" ", "").length() % 4 == 0;
    } catch (IllegalArgumentException iaex) {
    }
    return false;
}