List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64
public static byte[] encodeBase64(final byte[] binaryData)
From source file:cz.cvut.portal.kos.services.support.AuthorizeHttpRequestInterceptor.java
private String createBasicAuthHeader() { String credentials = username + ":" + password; byte[] encoded = Base64.encodeBase64(credentials.getBytes(ASCII_CHARSET)); return "Basic " + new String(encoded); }
From source file:eap.util.EDcodeUtil.java
public static String base64Encode(byte[] data) { return utf8Decode(Base64.encodeBase64(data)); }
From source file:com.kcs.core.actions.LoginAction.java
private String convertPasswordBase64(String password) throws Exception { String base64Password = ""; try {//from w w w .jav a2 s . co m if (password == null) { password = ""; } byte[] buf = Base64.encodeBase64(password.getBytes()); base64Password = new String(buf); } catch (Exception ex) { throw ex; } return base64Password; }
From source file:com.google.resting.rest.util.oauth.SignatureUtil.java
/** * Sign request.//from ww w . jav a 2 s. co m * * @param keyString Consumer key for request signing. * @param targetDomain Domain of the REST endpoint (Ex. login.yahoo.com) * @param verb Type of REST operation (GET/POST/PUT/DELETE) * @param isSecureInvocation HTTP/HTTPS * @param contextPathElement Path element in the base REST uri (Ex. /weather/india) * @param inputParams Collection of request params for REST request (Ex. city=calcutta ) * @return * @throws NoSuchAlgorithmException The exception is thrown if the encryption algorithm is not supported. * @throws InvalidKeyException The exception is thrown if the consumer key is invalid * @throws IllegalStateException * @throws UnsupportedEncodingException The exception is thrown if the URL encoding is incorrect. */ public static String getSignature(String keyString, String targetDomain, Verb verb, boolean isSecureInvocation, String contextPathElement, List<NameValuePair> inputParams, String messageEncoding) throws NoSuchAlgorithmException, InvalidKeyException, IllegalStateException, UnsupportedEncodingException { String baseString = getBaseString(targetDomain, verb.toString(), isSecureInvocation, contextPathElement, inputParams, messageEncoding).replace("+", "%20").replace("*", "%2A").replace("%7E", "~"); System.out.println("Base string is " + baseString); Mac mac = Mac.getInstance("HmacSHA1"); SecretKeySpec secret = new SecretKeySpec(keyString.getBytes(messageEncoding), mac.getAlgorithm()); mac.init(secret); byte[] digest = mac.doFinal(baseString.getBytes(messageEncoding)); return new String(Base64.encodeBase64(digest)).replace(RequestConstants.CARRIAGE_RETURN, RequestConstants.EMPTY_STRING); }
From source file:biospectra.lucene.SequenceCompressFilter.java
@Override public boolean incrementToken() throws IOException { if (this.input.incrementToken()) { char[] buffer = this.termAtt.buffer(); final int length = this.termAtt.length(); if (this.minStrand) { char[] reverseComplement = SequenceHelper.getReverseComplement(buffer, length); String originalSeq = String.valueOf(buffer, 0, length); String revcompSeq = String.valueOf(reverseComplement); if (originalSeq.compareTo(revcompSeq) > 0) { // use reverse-complement sequence for (int i = 0; i < length; i++) { buffer[i] = reverseComplement[i]; }//from ww w. j a v a2 s .co m } } if (this.base64Compress) { byte[] compressed = SequenceHelper.compress(buffer, length); byte[] encoded = Base64.encodeBase64(compressed); buffer = this.termAtt.resizeBuffer(encoded.length); for (int i = 0; i < buffer.length; i++) { if (i < encoded.length) { buffer[i] = (char) encoded[i]; } else { buffer[i] = 0; } } this.termAtt.setLength(encoded.length); //System.out.println("comp: " + String.valueOf(buffer)); } return true; } else { return false; } }
From source file:com.greenpepper.server.license.LicenceGenerator.java
private static void buildCommercial(int users, Date supportDate) throws Exception { File file = File.createTempFile("commercial", ".lic"); License license = License.commercial("My Paying Company", _2006, supportDate, users); LicenseManager lm = new LicenseManager(getLicenseParam()); lm.store(license, file);/*w w w .jav a 2 s. com*/ if (deleteFiles) file.deleteOnExit(); System.out.println( "# Commercial " + users + " USERS - Expery: " + new FormatedDate(supportDate).getFormatedDate()); System.out.println(new String(Base64.encodeBase64(FileUtils.readFileToByteArray(file)))); System.out.println(""); }
From source file:com.backbase.expert.extensions.sushi.util.Base64Serializer.java
@Override public String writeObject(Serializable serializable) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; String str = null;//from w w w. java 2 s. c om try { oos = new ObjectOutputStream(baos); oos.writeObject(serializable); byte[] data = baos.toByteArray(); str = new String(Base64.encodeBase64(data), "UTF-8"); } catch (IOException e) { LOG.error("Could not encode the object to a base64 string.", e); } finally { IOUtils.closeQuietly(oos); } return str; }
From source file:com.cedarsoft.crypt.CertTest.java
@Test public void testSupport() throws IOException, GeneralSecurityException { X509Support support = new X509Support(getClass().getResource("/test.crt"), getClass().getResource("/test.der")); assertEquals(SCRAMBLED, new String(Base64.encodeBase64(support.cipher(PLAINTEXT.getBytes())))); assertEquals(PLAINTEXT, new String(support.decipher(Base64.decodeBase64(SCRAMBLED.getBytes())))); }
From source file:com.emc.atmos.api.jersey.EsuApiJerseyAdapter.java
public EsuApiJerseyAdapter(AtmosConfig config) throws URISyntaxException, UnsupportedEncodingException, JAXBException { super(config.getEndpoints()[0].getHost(), config.getEndpoints()[0].getPort(), config.getTokenId(), new String(Base64.encodeBase64(config.getSecretKey()), "UTF-8")); adaptee = new AtmosApiClient(config); jaxbContext = JAXBContext.newInstance(com.emc.atmos.api.bean.ObjectInfo.class); }
From source file:com.rackspacecloud.blueflood.io.serializers.astyanax.TimerSerializationTest.java
@Test public void testV2RoundTrip() throws IOException { // build up a Timer BluefloodTimerRollup r0 = new BluefloodTimerRollup().withSum(Double.valueOf(42)).withCountPS(23.32d) .withAverage(56).withVariance(853.3245d).withMinValue(2).withMaxValue(987).withCount(345); r0.setPercentile("foo", 741.32d); r0.setPercentile("bar", 0.0323d); ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(Base64.encodeBase64(Serializers.timerRollupInstance.toByteBuffer(r0).array())); baos.write("\n".getBytes()); baos.close();// w ww . jav a 2 s . c om BufferedReader reader = new BufferedReader( new InputStreamReader(new ByteArrayInputStream(baos.toByteArray()))); ByteBuffer bb = ByteBuffer.wrap(Base64.decodeBase64(reader.readLine().getBytes())); BluefloodTimerRollup r1 = Serializers.timerRollupInstance.fromByteBuffer(bb); Assert.assertEquals(r0, r1); }