List of usage examples for java.util Base64 getDecoder
public static Decoder getDecoder()
From source file:DataBase.java
/** * This class provides a basic mode to get the array of Bytes for the Private * key associated with the input hash certificate value. * @param certHash Contains the SHA1 hash of the certificate used to get private key. * @return Bytes array associates with the input hash value. Null if hash value is not found. * @since v0.1.0/*from w w w.j a v a 2s. c o m*/ */ public synchronized byte[] getPrivateForHash(String certHash) { if (this.isConnected && (!this.stopFlag)) { String response = dataBaseObj.get(certHash); LOGGER.debug("REDIS query: {} | REDIS response: {}", certHash, response); if (response != null) { // Decode from base64 to bytes and return array of values. return Base64.getDecoder().decode(response.trim()); } } return null; }
From source file:net.maritimecloud.identityregistry.utils.EmailUtil.java
public void sendBugReport(BugReport report) throws MailException, MessagingException { MimeMessage message = this.mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setTo(bugReportEmail);/* w w w . j av a 2s .co m*/ helper.setFrom(from); helper.setSubject(report.getSubject()); helper.setText(report.getDescription()); if (report.getAttachments() != null) { for (BugReportAttachment attachment : report.getAttachments()) { // Decode base64 encoded data byte[] data = Base64.getDecoder().decode(attachment.getData()); ByteArrayDataSource dataSource = new ByteArrayDataSource(data, attachment.getMimetype()); helper.addAttachment(attachment.getName(), dataSource); } } this.mailSender.send(message); }
From source file:ai.grakn.engine.tasks.manager.redisqueue.RedisTaskStorage.java
@Override @Nullable/*from w ww .j ava 2 s . c o m*/ public TaskState getState(TaskId id) throws GraknBackendException { try (Jedis jedis = redis.getResource(); Context ignore = getTimer.time()) { String value = jedis.get(encodeKey.apply(id.getValue())); if (value != null) { return (TaskState) deserialize(Base64.getDecoder().decode(value)); } else { LOG.info("Requested state {} was not found", id.getValue()); // TODO Don't use exceptions for an expected return like this throw GraknBackendException.stateStorageMissingId(id); } } }
From source file:com.thoughtworks.go.server.service.plugins.AnalyticsPluginAssetsService.java
private void cacheStaticAssets(String pluginId) { LOGGER.info("Caching static assets for plugin: {}", pluginId); String data = this.analyticsExtension.getStaticAssets(pluginId); if (StringUtils.isBlank(data)) { LOGGER.info("No static assets found for plugin: {}", pluginId); return;//from w w w . j a v a 2s. c om } try { byte[] payload = Base64.getDecoder().decode(data.getBytes()); byte[] pluginEndpointJsContent = IOUtils .toByteArray(getClass().getResourceAsStream("/" + PLUGIN_ENDPOINT_JS)); ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(payload)); String assetsHash = calculateHash(payload, pluginEndpointJsContent); String pluginAssetsRoot = currentAssetPath(pluginId, assetsHash); zipUtil.unzip(zipInputStream, new File(pluginAssetsRoot)); Files.write(Paths.get(pluginAssetsRoot, DESTINATION_JS), pluginEndpointJsContent); pluginAssetPaths.put(pluginId, Paths.get(pluginStaticAssetsPathRelativeToRailsPublicFolder(pluginId), assetsHash).toString()); } catch (Exception e) { LOGGER.error("Failed to extract static assets from plugin: {}", pluginId, e); ExceptionUtils.bomb(e); } }
From source file:org.apache.syncope.client.console.PreferenceManager.java
public void set(final Request request, final Response response, final Map<String, List<String>> prefs) { Map<String, String> current = new HashMap<>(); String prefString = COOKIE_UTILS.load(COOKIE_NAME); if (prefString != null) { current.putAll(getPrefs(new String(Base64.getDecoder().decode(prefString.getBytes())))); }//from ww w . j a va2 s .co m // after retrieved previous setting in order to overwrite the key ... prefs.entrySet().forEach(entry -> { current.put(entry.getKey(), StringUtils.join(entry.getValue(), ";")); }); try { COOKIE_UTILS.save(COOKIE_NAME, Base64.getEncoder().encodeToString(setPrefs(current).getBytes())); } catch (IOException e) { LOG.error("Could not save {} info: {}", getClass().getSimpleName(), current, e); } }
From source file:com.kitac.kinesissamples.consumer.Consumer.java
/** * Converts a byte array to a string object that is JSON format. *///from w ww.j a v a 2 s . c om private String toJsonString(byte[] source) { String retVal; byte[] src; try { // Decode Base64 encoded string. src = Base64.getDecoder().decode(source); } catch (IllegalArgumentException e) { LOG.severe(e.getMessage()); src = null; } if (src != null) { try { retVal = new String(src, "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex); retVal = new String(src); } } else { retVal = ""; } return retVal; }
From source file:io.gomint.server.network.packet.PacketLogin.java
private String parseBae64JSON(String data) throws ParseException { // Be able to "parse" the payload String[] tempBase64 = data.split("\\."); String payload = new String(Base64.getDecoder().decode(tempBase64[1])); JSONObject chainData = (JSONObject) new JSONParser().parse(payload); return (String) chainData.get("identityPublicKey"); }
From source file:com.baidu.rigel.biplatform.ac.util.AesUtil.java
/** * ??/*from www . jav a2 s.com*/ * * @param encryptedData * @param keyValue * @return ? * @throws IllegalArgumentException * @throws Exception */ public String decrypt(String encryptedData, String keyValue) throws Exception { if (StringUtils.isBlank(encryptedData)) { throw new IllegalArgumentException("decode string can not be blank!"); } Cipher cipher = Cipher.getInstance(KEY_ALGORITHM); ; Key key = generateKey(keyValue); cipher.init(Cipher.DECRYPT_MODE, key); byte[] decordedValue = Base64.getDecoder().decode(encryptedData); byte[] decValue = cipher.doFinal(decordedValue); String decryptedValue = new String(decValue); return decryptedValue; }
From source file:com.act.lcms.MzMLParser.java
protected static List<Double> base64ToDoubleList(String b64) { byte[] decodedBytes = Base64.getDecoder().decode(b64); ByteBuffer buf = ByteBuffer.wrap(decodedBytes).order(ByteOrder.LITTLE_ENDIAN); List<Double> values = new ArrayList<>(decodedBytes.length / 8); while (buf.hasRemaining()) { values.add(buf.getDouble());/*from w w w . ja va 2 s.c o m*/ } return values; }
From source file:com.adeptj.modules.security.jwt.internal.JwtKeys.java
static PublicKey createVerificationKey(SignatureAlgorithm signatureAlgo, String publicKey) { LOGGER.info("Creating RSA verification key!!"); Assert.isTrue(StringUtils.startsWith(publicKey, PUB_KEY_HEADER), INVALID_PUBLIC_KEY_MSG); try {/*w w w . ja v a2s . c o m*/ KeyFactory keyFactory = KeyFactory.getInstance(signatureAlgo.getFamilyName()); byte[] publicKeyData = Base64.getDecoder().decode(publicKey.replace(PUB_KEY_HEADER, EMPTY) .replace(PUB_KEY_FOOTER, EMPTY).replaceAll(REGEX_SPACE, EMPTY).trim().getBytes(UTF_8)); LOGGER.info("Creating X509EncodedKeySpec from public key !!"); return keyFactory.generatePublic(new X509EncodedKeySpec(publicKeyData)); } catch (GeneralSecurityException ex) { LOGGER.error(ex.getMessage(), ex); throw new KeyInitializationException(ex.getMessage(), ex); } }