List of usage examples for javax.xml.bind DatatypeConverter printBase64Binary
public static String printBase64Binary(byte[] val)
Converts an array of bytes into a string.
From source file:org.apache.storm.common.AbstractAutoCreds.java
@Override public void populateCredentials(Map<String, String> credentials) { credentials.put(getCredentialKey(StringUtils.EMPTY), DatatypeConverter.printBase64Binary("dummy place holder".getBytes())); }
From source file:org.apache.storm.common.AbstractHadoopNimbusPluginAutoCreds.java
@Override public void populateCredentials(Map<String, String> credentials, Map<String, Object> topologyConf, final String topologyOwnerPrincipal) { try {/* www . j a v a 2s. c om*/ List<String> configKeys = getConfigKeys(topologyConf); if (!configKeys.isEmpty()) { for (String configKey : configKeys) { credentials.put(getCredentialKey(configKey), DatatypeConverter.printBase64Binary(getHadoopCredentials(topologyConf, configKey))); } } else { credentials.put(getCredentialKey(StringUtils.EMPTY), DatatypeConverter .printBase64Binary(getHadoopCredentials(topologyConf, topologyOwnerPrincipal))); } LOG.info("Tokens added to credentials map."); } catch (Exception e) { LOG.error("Could not populate credentials.", e); } }
From source file:org.bunkr.core.descriptor.PBKDF2Descriptor.java
@SuppressWarnings("unchecked") @Override/* w w w .j av a 2s.c o m*/ public JSONObject getParams() { JSONObject out = new JSONObject(); out.put("encryptionAlgorithm", this.encryptionAlgorithm.toString()); out.put("timeComboBox", this.pbkdf2Iterations); out.put("salt", DatatypeConverter.printBase64Binary(this.pbkdf2Salt)); return out; }
From source file:org.bunkr.core.descriptor.ScryptDescriptor.java
@SuppressWarnings("unchecked") @Override// ww w . ja v a 2s. co m public JSONObject getParams() { JSONObject out = new JSONObject(); out.put("encryptionAlgorithm", this.encryptionAlgorithm.toString()); out.put("scryptSalt", DatatypeConverter.printBase64Binary(this.scryptSalt)); out.put("scryptN", this.scryptN); out.put("scryptR", this.scryptR); out.put("scryptP", this.scryptP); return out; }
From source file:org.bunkr.core.inventory.FileInventoryItemJSON.java
@SuppressWarnings("unchecked") public static JSONAware encodeO(FileInventoryItem input) { JSONObject out = new JSONObject(); out.put(KEY_NAME, input.getName());/*www .j a v a 2 s . co m*/ out.put(KEY_UUID, input.getUuid().toString()); out.put(KEY_BLOCKS, FragmentedRangeJSON.encodeO(input.getBlocks())); out.put(KEY_SIZE_ON_DISK, input.getSizeOnDisk()); out.put(KEY_ACTUAL_SIZE, input.getActualSize()); out.put(KEY_MODIFIED_AT, input.getModifiedAt()); out.put(KEY_ENCRYPTION_ALGORITHM, input.getEncryptionAlgorithm().toString()); if (input.getEncryptionData() != null) out.put(KEY_ENCRYPTION_DATA, DatatypeConverter.printBase64Binary(input.getEncryptionData())); else out.put(KEY_ENCRYPTION_DATA, null); if (input.getIntegrityHash() != null) out.put(KEY_INTEGRITY_HASH, DatatypeConverter.printBase64Binary(input.getIntegrityHash())); else out.put(KEY_INTEGRITY_HASH, null); out.put(KEY_MEDIA_TYPE, input.getMediaType()); return out; }
From source file:org.carlspring.strongbox.storage.metadata.nuget.TempNupkgFile.java
/** * Creates a temporary file based on the stream. * * @param inputStream/* www.j ava2s . com*/ * data stream * @param targetFile * file to copy the package to * @return data file * @throws IOException * read / write error * @throws NoSuchAlgorithmException * the system does not have an algorithm for calculating the * value of HASH */ private static String copyDataAndCalculateHash(InputStream inputStream, File targetFile) throws IOException, NoSuchAlgorithmException { MessageDigest messageDigest = MessageDigest.getInstance(MessageDigestAlgorithms.SHA_512); DigestInputStream digestInputStream = new DigestInputStream(inputStream, messageDigest); try (FileOutputStream fileOutputStream = new FileOutputStream(targetFile); ReadableByteChannel src = Channels.newChannel(digestInputStream); FileChannel dest = fileOutputStream.getChannel();) { fastChannelCopy(src, dest); byte[] digest = digestInputStream.getMessageDigest().digest(); return DatatypeConverter.printBase64Binary(digest); } }
From source file:org.codice.ddf.spatial.kml.transformer.DescriptionTemplateHelper.java
public String prettyPrint(Attribute attribute, AttributeFormat format) { switch (format) { case BINARY:/* w w w . j a va 2s.c o m*/ return DatatypeConverter.printBase64Binary((byte[]) attribute.getValue()); case DATE: if (attribute != null && attribute.getValue() != null) { return dateFormat.format((Date) attribute.getValue()); } else { return dateFormat.format(new Date()); } // There is no way to prettyPrint these case GEOMETRY: case OBJECT: case XML: return null; // Nothing to do case STRING: case BOOLEAN: case DOUBLE: case FLOAT: case INTEGER: case LONG: case SHORT: default: return attribute.getValue().toString(); } }
From source file:org.codice.ddf.spatial.kml.transformer.DescriptionTemplateHelper.java
public String base64Thumbnail(Metacard context) { if (null != context && context.getThumbnail() != null && context.getThumbnail().length != 0) { return DatatypeConverter.printBase64Binary(context.getThumbnail()); } else {/*from w w w . j a v a2 s . co m*/ return null; } }
From source file:org.eclipse.birt.data.oda.mongodb.impl.MDbResultSet.java
private static String convertToString(byte[] value) { try {/*from www . ja v a2 s.c om*/ return DatatypeConverter.printBase64Binary(value); } catch (Exception ex) { // DatatypeConverter could be un-initialized; retry with Base64Codec return (new String(Base64.encodeBase64(value))); } }
From source file:org.fejoa.library.messages.PublicCryptoEnvelope.java
static public InputStream encrypt(InputStream data, boolean isRawData, KeyId keyId, PublicKey key, FejoaContext context) throws JSONException, CryptoException, IOException { JSONObject object = new JSONObject(); object.put(Envelope.PACK_TYPE_KEY, CRYPTO_TYPE); if (isRawData) object.put(Envelope.CONTAINS_DATA_KEY, 1); ICryptoInterface crypto = context.getCrypto(); CryptoSettings.Asymmetric pubKeySettings = context.getCryptoSettings().publicKey; CryptoSettings.Symmetric symSettings = context.getCryptoSettings().symmetric; byte[] iv = crypto.generateInitializationVector(symSettings.ivSize); String base64IV = DatatypeConverter.printBase64Binary(iv); SecretKey symKey = crypto.generateSymmetricKey(symSettings); // encrypt the key byte[] encSymKey = crypto.encryptAsymmetric(symKey.getEncoded(), key, pubKeySettings); String base64EncSymKey = DatatypeConverter.printBase64Binary(encSymKey); object.put(PUBLIC_KEY_ID_KEY, keyId.getKeyId()); object.put(PUBLIC_KEY_SETTINGS_KEY, JsonCryptoSettings.toJson(pubKeySettings)); object.put(IV_KEY, base64IV);/*from www . j av a 2 s .co m*/ object.put(ENC_SYMMETRIC_KEY_KEY, base64EncSymKey); object.put(SYMMETRIC_SETTINGS_KEY, JsonCryptoSettings.toJson(symSettings)); String header = object.toString() + "\n"; InputStream crytoStream = crypto.encryptSymmetric(data, symKey, iv, symSettings); return new SequenceInputStream(new ByteArrayInputStream(header.getBytes()), crytoStream); }