List of usage examples for java.util Base64 getDecoder
public static Decoder getDecoder()
From source file:org.apache.pulsar.functions.worker.rest.api.FunctionsImpl.java
@POST @Path("/{tenant}/{namespace}/{functionName}/trigger") @Consumes(MediaType.MULTIPART_FORM_DATA) public Response triggerFunction(final @PathParam("tenant") String tenant, final @PathParam("namespace") String namespace, final @PathParam("name") String functionName, final @FormDataParam("data") String input, final @FormDataParam("dataStream") InputStream uploadedInputStream) { FunctionDetails functionDetails;/*from w w w . j a v a 2 s. c om*/ // validate parameters try { validateTriggerRequestParams(tenant, namespace, functionName, input, uploadedInputStream); } catch (IllegalArgumentException e) { log.error("Invalid trigger function request @ /{}/{}/{}", tenant, namespace, functionName, e); return Response.status(Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON) .entity(new ErrorData(e.getMessage())).build(); } FunctionMetaDataManager functionMetaDataManager = worker().getFunctionMetaDataManager(); if (!functionMetaDataManager.containsFunction(tenant, namespace, functionName)) { log.error("Function in getFunction does not exist @ /{}/{}/{}", tenant, namespace, functionName); return Response.status(Status.NOT_FOUND).type(MediaType.APPLICATION_JSON) .entity(new ErrorData(String.format("Function %s doesn't exist", functionName))).build(); } FunctionMetaData functionMetaData = functionMetaDataManager.getFunctionMetaData(tenant, namespace, functionName); String inputTopicToWrite; if (functionMetaData.getFunctionDetails().getInputsList().size() > 0) { inputTopicToWrite = functionMetaData.getFunctionDetails().getInputsList().get(0); } else { inputTopicToWrite = functionMetaData.getFunctionDetails().getCustomSerdeInputs().entrySet().iterator() .next().getKey(); } String outputTopic = functionMetaData.getFunctionDetails().getOutput(); Reader reader = null; Producer producer = null; try { if (outputTopic != null && !outputTopic.isEmpty()) { reader = worker().getClient().newReader().topic(outputTopic).startMessageId(MessageId.latest) .create(); } producer = worker().getClient().newProducer().topic(inputTopicToWrite).create(); byte[] targetArray; if (uploadedInputStream != null) { targetArray = new byte[uploadedInputStream.available()]; uploadedInputStream.read(targetArray); } else { targetArray = input.getBytes(); } MessageId msgId = producer.send(targetArray); if (reader == null) { return Response.status(Status.OK).build(); } long curTime = System.currentTimeMillis(); long maxTime = curTime + 1000; while (curTime < maxTime) { Message msg = reader.readNext(10000, TimeUnit.MILLISECONDS); if (msg == null) break; if (msg.getProperties().containsKey("__pfn_input_msg_id__") && msg.getProperties().containsKey("__pfn_input_topic__")) { MessageId newMsgId = MessageId.fromByteArray( Base64.getDecoder().decode((String) msg.getProperties().get("__pfn_input_msg_id__"))); if (msgId.equals(newMsgId) && msg.getProperties().get("__pfn_input_topic__").equals(inputTopicToWrite)) { return Response.status(Status.OK).entity(msg.getData()).build(); } } curTime = System.currentTimeMillis(); } return Response.status(Status.REQUEST_TIMEOUT).build(); } catch (Exception e) { return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } finally { if (reader != null) { reader.closeAsync(); } if (producer != null) { producer.closeAsync(); } } }
From source file:org.mycore.common.MCRUtils.java
/** * @deprecated use {@link Base64} instead *//*ww w. j av a 2s . com*/ @Deprecated public static byte[] fromBase64String(String base64) { return Base64.getDecoder().decode(base64); }
From source file:org.keycloak.testsuite.client.OIDCPairwiseClientRegistrationTest.java
private String getPayload(String token) { String payloadBase64 = token.split("\\.")[1]; return new String(Base64.getDecoder().decode(payloadBase64)); }
From source file:org.hyperledger.fabric_ca.sdk.HFCAClient.java
/** * Re-Enroll the user with member service * * @param user User to be re-enrolled//from w ww .j a v a2 s .c o m * @param req Enrollment request with the following fields: hosts, profile, csr, label * @return enrollment * @throws EnrollmentException * @throws InvalidArgumentException */ public Enrollment reenroll(User user, EnrollmentRequest req) throws EnrollmentException, InvalidArgumentException { if (cryptoSuite == null) { throw new InvalidArgumentException("Crypto primitives not set."); } if (user == null) { throw new InvalidArgumentException("reenrollment user is missing"); } if (user.getEnrollment() == null) { throw new InvalidArgumentException("reenrollment user is not a valid user object"); } logger.debug(format("re-enroll user: %s, url: %s", user.getName(), url)); try { setUpSSL(); PublicKey publicKey = cryptoSuite .bytesToCertificate(user.getEnrollment().getCert().getBytes(StandardCharsets.UTF_8)) .getPublicKey(); KeyPair keypair = new KeyPair(publicKey, user.getEnrollment().getKey()); // generate CSR String pem = cryptoSuite.generateCertificationRequest(user.getName(), keypair); // build request body req.setCSR(pem); if (caName != null && !caName.isEmpty()) { req.setCAName(caName); } String body = req.toJson(); // build authentication header JsonObject result = httpPost(url + HFCA_REENROLL, body, user); // get new cert from response Base64.Decoder b64dec = Base64.getDecoder(); String signedPem = new String(b64dec.decode(result.getString("Cert").getBytes(UTF_8))); logger.debug(format("[HFCAClient] re-enroll returned pem:[%s]", signedPem)); logger.debug(format("reenroll user %s done.", user.getName())); return new X509Enrollment(keypair, signedPem); } catch (EnrollmentException ee) { logger.error(ee.getMessage(), ee); throw ee; } catch (Exception e) { EnrollmentException ee = new EnrollmentException(format("Failed to re-enroll user %s", user), e); logger.error(e.getMessage(), e); throw ee; } }
From source file:com.att.ajsc.csilogging.common.CSILoggingUtils.java
private boolean processUserAndPassword(HttpServletRequest request) { String authHeader = request.getHeader(CommonNames.HTTP_AUTHORIZATION); boolean validUser = false; if (authHeader != null) { String[] split = authHeader.split("\\s+"); if (split.length > 0) { String basic = split[0]; if (basic.equalsIgnoreCase("Basic")) { String credentials = split[1]; String userPass = new String(Base64.getDecoder().decode(credentials)); int p = userPass.indexOf(":"); if (p != -1) { validUser = true;// www. ja va2 s. c o m request.setAttribute(CommonNames.CSI_USER_NAME, userPass.substring(0, p)); logger.info("Username: " + request.getAttribute(CommonNames.CSI_USER_NAME)); } } } } return validUser; }
From source file:com.traffitruck.web.HtmlController.java
@RequestMapping(value = "/approval/licenseimage/{truckId}", method = RequestMethod.GET, produces = MediaType.IMAGE_PNG_VALUE) public byte[] getTruckLicenseImage(@PathVariable String truckId) { String b64dataUrl = new String(dao.getTruckById(truckId).getVehicleLicensePhoto().getData()); byte[] bytes = b64dataUrl.substring(b64dataUrl.indexOf(',') + 1).getBytes(); return Base64.getDecoder().decode(bytes); }
From source file:com.joyent.manta.http.EncryptionHttpHelper.java
/** * Builds a {@link Map} of decrypted metadata keys and values. * * @param encryptionType encryption type header value * @param metadataIvBase64 metadata ciphertext iv header value * @param metadataCiphertextBase64 metadata ciphertext header value * @param hmacId hmac identifier header value * @param metadataHmacBase64 metadata hmac header value * @param request http request object//from www . j ava2 s . c o m * @param response http response object * @return decrypted map of encrypted metadata */ @SuppressWarnings("ParameterNumber") private Map<String, String> buildEncryptedMetadata(final String encryptionType, final String metadataIvBase64, final String metadataCiphertextBase64, final String hmacId, final String metadataHmacBase64, final HttpRequest request, final HttpResponse response) { try { EncryptionType.validateEncryptionTypeIsSupported(encryptionType); } catch (MantaClientEncryptionException e) { HttpHelper.annotateContextedException(e, request, response); throw e; } final byte[] metadataIv = Base64.getDecoder().decode(metadataIvBase64); final Cipher metadataCipher = buildMetadataDecryptCipher(metadataIv); if (metadataCiphertextBase64 == null) { String msg = "No encrypted metadata stored on object"; MantaClientEncryptionException e = new MantaClientEncryptionException(msg); HttpHelper.annotateContextedException(e, request, response); throw e; } final byte[] metadataCipherText = Base64.getDecoder().decode(metadataCiphertextBase64); // Validate Hmac if we aren't using AEAD if (!cipherDetails.isAEADCipher()) { if (hmacId == null) { String msg = "No HMAC algorithm specified for metadata ciphertext authentication"; MantaClientEncryptionException e = new MantaClientEncryptionException(msg); HttpHelper.annotateContextedException(e, request, response); throw e; } Supplier<HMac> hmacSupplier = SupportedHmacsLookupMap.INSTANCE.get(hmacId); if (hmacSupplier == null) { String msg = String.format("Unsupported HMAC specified: %s", hmacId); MantaClientEncryptionException e = new MantaClientEncryptionException(msg); HttpHelper.annotateContextedException(e, request, response); throw e; } final HMac hmac = hmacSupplier.get(); initHmac(this.secretKey, hmac); hmac.update(metadataCipherText, 0, metadataCipherText.length); byte[] actualHmac = new byte[hmac.getMacSize()]; hmac.doFinal(actualHmac, 0); if (metadataHmacBase64 == null) { String msg = "No metadata HMAC is available to authenticate metadata ciphertext"; MantaClientEncryptionException e = new MantaClientEncryptionException(msg); HttpHelper.annotateContextedException(e, request, response); throw e; } byte[] expectedHmac = Base64.getDecoder().decode(metadataHmacBase64); if (!Arrays.equals(expectedHmac, actualHmac)) { String msg = "The expected HMAC value for metadata ciphertext didn't equal the actual value"; MantaClientEncryptionException e = new MantaClientEncryptionException(msg); HttpHelper.annotateContextedException(e, request, null); e.setContextValue("expected", Hex.encodeHexString(expectedHmac)); e.setContextValue("actual", Hex.encodeHexString(actualHmac)); throw e; } } byte[] plaintext = decryptMetadata(metadataCipherText, metadataCipher); return EncryptedMetadataUtils.plaintextMetadataAsMap(plaintext); }
From source file:com.traffitruck.web.HtmlController.java
@RequestMapping(value = "/approval/driverlicenseimage/{truckId}", method = RequestMethod.GET, produces = MediaType.IMAGE_PNG_VALUE) public byte[] getDriverLicenseImage(@PathVariable String truckId) { Binary photo = dao.getTruckById(truckId).getDriverLicensePhoto(); if (photo == null) { return null; }//from w w w . jav a2s.com String b64dataUrl = new String(photo.getData()); byte[] bytes = b64dataUrl.substring(b64dataUrl.indexOf(',') + 1).getBytes(); return Base64.getDecoder().decode(bytes); }
From source file:org.apache.flink.table.runtime.functions.SqlFunctionUtils.java
public static byte[] fromBase64(BinaryString bs) { return Base64.getDecoder().decode(bs.getBytes()); }
From source file:com.traffitruck.web.HtmlController.java
@RequestMapping(value = "/approval/truckimage/{truckId}", method = RequestMethod.GET, produces = MediaType.IMAGE_PNG_VALUE) public byte[] getTruckImage(@PathVariable String truckId) { String b64dataUrl = new String(dao.getTruckById(truckId).getTruckPhoto().getData()); byte[] bytes = b64dataUrl.substring(b64dataUrl.indexOf(',') + 1).getBytes(); return Base64.getDecoder().decode(bytes); }