List of usage examples for org.apache.commons.codec.binary Base64 Base64
public Base64()
From source file:com.kku.apps.pricesearch.util.SignedHelper.java
private static String sign(String apiSecretKey, String sourceString) throws Exception { SecretKeySpec secretKeySpec = new SecretKeySpec(apiSecretKey.getBytes(ENCODING), ALGORITHM); Mac mac = Mac.getInstance(ALGORITHM); mac.init(secretKeySpec);/* w ww. jav a 2s .c o m*/ byte[] data = mac.doFinal(sourceString.getBytes(ENCODING)); Base64 encoder = new Base64(); String signature = new String(encoder.encode(data)); return signature; }
From source file:com.github.tell.codec.Base64Serializer.java
public String encodeToString(final Serializable o) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o);// w ww. j a v a 2 s . c om oos.close(); final byte[] encoded = baos.toByteArray(); final Base64 encoder = new Base64(); return encoder.encodeToString(encoded); }
From source file:license.TestWakeLicense.java
/** * wakelicense//from w w w .ja va 2s . c om * @throws Exception */ @Test public void testWake() throws Exception { pi.setClient(""); pi.setName(""); pi.setContact(""); pi.setTel("15000100001"); pi.setEmail("dcm19890101@163.com"); String info = projectInfoToString(pi); System.out.println( "---===(*****?info.getBytes()?Register.data)" + info); System.out.println(); System.out.println(); readProjectInfo(pi, info); System.out.println(); System.out.println(); setInput(pi); System.out.println(); System.out.println(); //??testData testData = toString(pi); System.out.println(testData); System.out.println(extraData()); System.out.println(); System.out.println(); // //wake*?*license? // String[] ss = testData.split("\n"); String blowfishInfo = new Blowfish(Date.class.getName()).decryptString(ss[0]); byte[] rmd5 = md5(blowfishInfo); //?base64? byte[] lmd5 = rsa(new Base64().decode(ss[1])); System.out.println("?? " + equalsBytes(rmd5, lmd5)); }
From source file:com.ning.metrics.eventtracker.TestThriftEncoding.java
private Event extractEvent(String category, String message) throws TException, IOException { Event event;/*from w ww .j a va 2 s . com*/ Long eventDateTime; String[] payload = StringUtils.split(message, ":"); byte[] thrift = new Base64().decode(payload[1].getBytes()); try { eventDateTime = Long.parseLong(payload[0]); event = ThriftToThriftEnvelopeEvent.extractEvent(category, new DateTime(eventDateTime), thrift); } catch (RuntimeException e) { event = ThriftToThriftEnvelopeEvent.extractEvent(category, thrift); } return event; }
From source file:com.gisgraphy.util.StringUtil.java
/** * Encode a string using Base64 encoding. Used when storing passwords as * cookies. This is weak encoding in that anyone can use the decodeString * routine to reverse the encoding./* w w w .j av a 2 s .com*/ * * @param str * the string to encode * @return the encoded string */ public static String encodeString(String str) { Base64 encoder = new Base64(); return String.valueOf(encoder.encode(str.getBytes())).trim(); }
From source file:de.extra.client.plugins.outputplugin.crypto.ExtraCryptoUtil.java
/** Encrypts the specified string, using the specified secret key. */ private static String encrypt(String sValue, String secretKey) { if (secretKey == null) { secretKey = SYM_KEY_STR;//from w w w. j av a2 s. c om } if (sValue == null || sValue.equals("")) { return ""; } String textEncode = null; Cipher encryptCipher = null; try { SecretKeySpec skeySpec = decodeKey(secretKey); encryptCipher = Cipher.getInstance(TRANSFORMATION); encryptCipher.init(Cipher.ENCRYPT_MODE, skeySpec); byte[] plainText = sValue.trim().getBytes(CHARSET); // do the actual encryption byte[] cipherText = encryptCipher.doFinal(plainText); // Changed to encode() to avoid <cr> on end of string // textEncode = base64Encoder.encodeBuffer(cipherText); textEncode = new Base64().encodeAsString(cipherText); } catch (Exception e) { e.printStackTrace(System.err); } return textEncode; }
From source file:jeeves.utils.BLOB.java
public static void write(Element response, OutputStream output) throws IOException { String data = response.getText(); //byte blob[] = new BASE64Decoder().decodeBuffer(data); byte blob[] = new Base64().decode(data.getBytes(Charset.forName("UTF-8"))); ByteArrayInputStream input = new ByteArrayInputStream(blob); copy(input, output);/* w w w .j a va2 s .co m*/ }
From source file:com.twitter.common.thrift.text.TTextProtocolTest.java
/** * Load a file containing a serialized thrift message in from disk * @throws IOException//from w w w. j av a 2 s. com */ @Before public void setUp() throws IOException { fileContents = Resources.toString( Resources.getResource(getClass(), "/com/twitter/common/thrift/text/TTextProtocol_TestData.txt"), Charsets.UTF_8); base64Encoder = new Base64(); }
From source file:com.scraper.SignedRequestsHelper.java
private String hmac(String stringToSign) { String signature = null;/*from w w w .j av a 2 s .c om*/ byte[] data; byte[] rawHmac; try { data = stringToSign.getBytes(UTF8_CHARSET); rawHmac = mac.doFinal(data); Base64 encoder = new Base64(); signature = new String(encoder.encode(rawHmac)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(UTF8_CHARSET + " is unsupported!", e); } return signature; }
From source file:com.linecorp.armeria.common.thrift.text.TTextProtocolTest.java
/** * Load a file containing a serialized thrift message in from disk. *//*from w w w. j a v a2s . c om*/ @Before public void setUp() throws IOException { fileContents = Resources.toString(Resources.getResource(getClass(), "/com/linecorp/armeria/common/thrift/text/TTextProtocol_TestData.txt"), Charsets.UTF_8); base64Encoder = new Base64(); }