List of usage examples for java.util Base64 getEncoder
public static Encoder getEncoder()
From source file:Algorithm.ImageEncoder.java
public static String getImageStringRaw(InputStream img) { String theString = null;//from w ww .j av a2 s . c o m try { byte[] barr = IOUtils.toByteArray(img); Base64.Encoder en = Base64.getEncoder(); theString = en.encodeToString(barr); } catch (Exception iOException) { System.out.println("err"); } //item.write(f); return theString; }
From source file:nu.yona.server.crypto.CryptoUtil.java
public static String getRandomString(int length) { byte[] bytes = getRandomBytes(length * 256 / 64); String randomString = Base64.getEncoder().encodeToString(bytes); return randomString.substring(0, Math.min(length, randomString.length())); }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConfigMount.java
public static VaultConfigMount fromLocalFile(File localFile, String desiredPath) { String contents;//w w w .j a v a2 s .co m try { String unencodedContents = IOUtils.toString(new FileInputStream(localFile)); contents = Base64.getEncoder().encodeToString(unencodedContents.getBytes()); } catch (IOException e) { throw new HalException(Problem.Severity.FATAL, "Failed to read local config file: " + localFile, e); } return new VaultConfigMount().setContents(contents).setFile(desiredPath); }
From source file:com.esri.geoportal.harvester.api.base.SimpleScrambler.java
/** * Encodes string./* w ww . j ava2 s . co m*/ * @param txt string to encode * @return encoded string or <code>null</code> if error encoding string */ public static String encode(String txt) { txt = StringUtils.defaultIfEmpty(txt, ""); try { CRC32 crC32 = new CRC32(); crC32.update(txt.getBytes("UTF-8")); long crc = crC32.getValue(); String crctxt = String.format("%10d%s", crc, txt); Base64.Encoder encoder = Base64.getEncoder(); return encoder.encodeToString(crctxt.getBytes("UTF-8")); } catch (UnsupportedEncodingException ex) { return null; } }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConfigMount.java
public static VaultConfigMount fromString(String contents, String desiredPath) { contents = Base64.getEncoder().encodeToString(contents.getBytes()); return new VaultConfigMount().setContents(contents).setFile(desiredPath); }
From source file:org.opencb.commons.utils.CryptoUtils.java
public static byte[] encryptAES(String strToEncrypt, byte[] key) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException { try {/*from w w w .j ava 2s . co m*/ Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); SecretKeySpec secretKey = new SecretKeySpec(key, "AES"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); return Base64.getEncoder().encode(cipher.doFinal(strToEncrypt.getBytes())); } catch (NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException ex) { Logger.getLogger(CryptoUtils.class.getName()).log(Level.SEVERE, "This should not happen", ex); throw ex; } }
From source file:org.silverpeas.core.util.SerializationUtil.java
/** * <p>Serializes an {@code Object} to a string forstorage/serialization.</p> * @param obj the object to serialize to bytes * @return a string with the converted Serializable * @throws SerializationException (runtime) if the serialization fails *///w w w. j av a2 s.co m public static String serializeAsString(Serializable obj) { return Base64.getEncoder().encodeToString(serialize(obj)); }
From source file:os4.serv.XMLTools.java
public static String encodeByteArray(byte[] array) { return Base64.getEncoder().encodeToString(array); }
From source file:com.github.sebhoss.identifier.service.ServiceConfiguration.java
/** * @return A Base64 encoder. */ @Bean @SuppressWarnings("static-method") public Encoder encoder() { return Base64.getEncoder(); }
From source file:com.web.mavenproject6.utility.EncryptionUtil.java
@Autowired public EncryptionUtil(Environment env) { this.env = env; String key = Base64.getEncoder().encodeToString(this.env.getProperty("aes.key").getBytes()); this.skeySpec = new SecretKeySpec(key.getBytes(), "AES"); }