List of utility methods to do XML Data Type Converter
String | deCrypt(String property) de Crypt SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); SecretKey key = keyFactory.generateSecret(new PBEKeySpec(PASSWORD)); Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); return new String(pbeCipher.doFinal(DatatypeConverter.parseBase64Binary(property)), "UTF-8"); |
Object | deserializeFromString(String x) deserialize From String try { byte[] A = DatatypeConverter.parseBase64Binary(x); ByteArrayInputStream bin = new ByteArrayInputStream(A); ObjectInputStream in = new ObjectInputStream(bin); return in.readObject(); } catch (Exception t) { throw new RuntimeException(t); |
Object | deserializeLogic(String logicString) deserialize Logic byte[] data = DatatypeConverter.parseBase64Binary(logicString); try { ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data)); return ois.readObject(); } catch (IOException e) { throw new RuntimeException(e); |
String | encodeBasicHeader(final String username, final String password) encode Basic Header return new String(DatatypeConverter.printBase64Binary( (username + ":" + Objects.requireNonNull(password)).getBytes(StandardCharsets.UTF_8))); |
String | encodeDoubleArray(double[] noData) encode Double Array ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; byte[] rawBytes; try { oos = new ObjectOutputStream(baos); oos.writeInt(noData.length); for (int i = 0; i < noData.length; i++) { oos.writeDouble(noData[i]); ... |
String | encodeJavaOpts(String javaOpts) Encode the JVM options 1. String javaOptsBase64 = DatatypeConverter.printBase64Binary(javaOpts.getBytes(Charset.forName("UTF-8"))); return String.format("\"%s\"", javaOptsBase64.replace("=", "=")); |
String | encrypt(String plainText, String password) encrypt byte[] salt = new byte[8]; SecureRandom random = new SecureRandom(); random.nextBytes(salt); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); SecretKey key = keyFactory.generateSecret(new PBEKeySpec(password.toCharArray())); Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(salt, 20)); return ENCODE + DatatypeConverter.printBase64Binary(salt) ... |
String | encryptPassword(String unencrypted) encrypt Password MessageDigest md = MessageDigest.getInstance(SHA_256);
md.update(unencrypted.getBytes());
return DatatypeConverter.printHexBinary(md.digest()).toLowerCase();
|
InputStream | fetchUrl(String url, String username, String password) fetch Url notNull(url); notNull(username); notNull(password); URLConnection conn = new URL(url).openConnection(); if (!username.isEmpty()) { conn.setRequestProperty("Authorization", "Basic " + DatatypeConverter.printBase64Binary((username + ":" + password).getBytes())); return conn.getInputStream(); |
String | formatFriendlyName(final byte[] addressBytes) format Friendly Name final String base64 = DatatypeConverter.printBase64Binary(addressBytes); final String slashToMinus = base64.replace('/', '-'); return slashToMinus; |