Example usage for org.apache.commons.codec.binary StringUtils getBytesUtf8

List of usage examples for org.apache.commons.codec.binary StringUtils getBytesUtf8

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary StringUtils getBytesUtf8.

Prototype

public static byte[] getBytesUtf8(final String string) 

Source Link

Document

Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result into a new byte array.

Usage

From source file:at.supp.JsonTokenUtil2.java

public static String convertToBase64(String source) {
    return Base64.encodeBase64URLSafeString(StringUtils.getBytesUtf8(source));
}

From source file:de.pawlidi.openaletheia.utils.Converter.java

public static byte[] getBytesUtf8(final String string) {
    return StringUtils.getBytesUtf8(string);
}

From source file:mvm.rya.indexing.accumulo.Md5Hash.java

public static String md5Base64(String string) {
    return md5Base64(StringUtils.getBytesUtf8(string));
}

From source file:com.smartitengineering.cms.spi.impl.hbase.Utils.java

public static byte[] toBytes(final Date date) {
    if (date == null) {
        return new byte[0];
    }// w  w  w  .j a v a 2s.  co m
    try {
        return StringUtils.getBytesUtf8(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(date));
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.ro.ssc.app.client.licensing.TrialKeyValidator.java

public static String decodeKey(String encodedEncrypted) {
    String decoded = "";
    try {/*from w ww .  j a v  a 2s .com*/
        byte[] saltDecrypt = SALT_DECRYPT.getBytes(StandardCharsets.UTF_8);
        SecretKeyFactory factoryKeyDecrypt = SecretKeyFactory.getInstance(SECRET_KEY_FACTORY);
        SecretKey tmp2 = factoryKeyDecrypt.generateSecret(
                new PBEKeySpec(PASS_DECRYPT.toCharArray(), saltDecrypt, ITERATIONS_DECRYPT, KEY_LENGTH));
        SecretKeySpec decryptKey = new SecretKeySpec(tmp2.getEncoded(), ALGORITHM);
        Cipher aesCipherDecrypt = Cipher.getInstance(CIPHER);
        aesCipherDecrypt.init(Cipher.DECRYPT_MODE, decryptKey);
        byte[] e64bytes = StringUtils.getBytesUtf8(encodedEncrypted);
        byte[] eBytes = Base64.decodeBase64(e64bytes);
        byte[] cipherDecode = aesCipherDecrypt.doFinal(eBytes);
        decoded = StringUtils.newStringUtf8(cipherDecode);
    } catch (Exception e) {
        LOGGER.error("Error while decoding the trial key", e);
    }
    return decoded;
}

From source file:com.itemanalysis.jmetrik.workspace.JmetrikPassword.java

public String encodePassword(String pw) {
    byte[] encodedBytes = Base64.encodeBase64(StringUtils.getBytesUtf8(pw));
    String encodedContent = StringUtils.newStringUtf8(encodedBytes);
    return encodedContent;
}

From source file:de.alpharogroup.crypto.aes.HexDumpTest.java

/**
 * Test method for {@link de.alpharogroup.crypto.aes.HexDump#decodeHex(char[])}
 *
 * @throws DecoderException/*from   ww  w  .j a  v  a 2  s  .  c o m*/
 *             the decoder exception
 */
@Test
public void testDecodeHex() throws DecoderException {
    final String expected = "Secret message";
    final char[] actualCharArray = HexDump.encodeHex(StringUtils.getBytesUtf8(expected));
    final byte[] decoded = HexDump.decodeHex(actualCharArray);
    final String actual = new String(decoded);
    assertEquals(expected, actual);
}

From source file:de.micromata.tpsb.doc.sources.JavaSourceFileHolder.java

public InputStream getAsInputStream() {
    return new ByteArrayInputStream(StringUtils.getBytesUtf8(content));
}

From source file:com.google.code.commons.checksum.binary.TestBinaryUtils.java

@Test
public void getBytesUtf8() {
    Assert.assertArrayEquals(StringUtils.getBytesUtf8(HELLO_WORLD_STRING),
            BinaryUtils.getBytesUtf8(HELLO_WORLD_STRING));
    Assert.assertNull(BinaryUtils.getBytesUtf8(null));
}

From source file:mvm.rya.indexing.accumulo.temporal.TemporalInstantTest.java

@Test
public void constructorTest() throws Exception {
    TemporalInstant instant = new TemporalInstantRfc3339(2014, 12, 30, //
            12, 59, 59);//  w w w.  j av a  2 s. co m
    // YYYY-MM-DDThh:mm:ssZ
    String stringTestDate01 = "2014-12-30T12:59:59Z";
    Date dateTestDate01 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(stringTestDate01);
    Assert.assertEquals(stringTestDate01, instant.getAsKeyString());
    Assert.assertArrayEquals(StringUtils.getBytesUtf8(instant.getAsKeyString()), instant.getAsKeyBytes());
    Assert.assertTrue("Key must be normalized to time zone Zulu", instant.getAsKeyString().endsWith("Z"));
    // show the local time us.
    // Warning, if test is run in the London, or Zulu time zone, this test will be same as above, with the Z.
    // TimeZone.setDefault(TimeZone.getTimeZone("UTC")); // this does not affect the library, don't use.
    String stringLocalTestDate01 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(dateTestDate01);
    // for ET, will be: "2014-12-30T07:59:59-05:00"
    //instant.getAsDateTime().withZone(null);
    //      System.out.println("===System.getProperty(user.timezone)="+System.getProperty("user.timezone")); //=ET
    //      System.out.println("===============TimeZone.getDefault()="+TimeZone.getDefault());            //=ET
    //      System.out.println("===========DateTimeZone.getDefault()="+DateTimeZone.getDefault());         //=UTC (wrong!)
    // the timezone default gets set to UTC by some prior test, fix it here.
    DateTimeZone newTimeZone = null;
    try {
        String id = System.getProperty("user.timezone");
        if (id != null) {
            newTimeZone = DateTimeZone.forID(id);
        }
    } catch (RuntimeException ex) {
        // ignored
    }
    if (newTimeZone == null) {
        newTimeZone = DateTimeZone.forTimeZone(TimeZone.getDefault());
    }
    DateTimeZone.setDefault(newTimeZone);
    // null timezone means use the default:
    Assert.assertEquals("Joda time library (actual) should use same local timezone as Java date (expected).",
            stringLocalTestDate01, instant.getAsReadable(null));
}