List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64
public static byte[] encodeBase64(final byte[] binaryData)
From source file:com.tesora.dve.common.PECryptoUtils.java
public static String encrypt(String str) throws PEException { if (StringUtils.isBlank(str)) return str; try {/*from w w w . j ava 2s . co m*/ Cipher cipher = createCrypter(Cipher.ENCRYPT_MODE); byte[] enc = cipher.doFinal(str.getBytes("UTF8")); return new String(Base64.encodeBase64(enc)); } catch (Exception e) { throw new PEException("Failed to encrypt '" + str + "'", e); } }
From source file:com.photon.phresco.service.AuthServiceTest.java
public void testAuthenticate() throws PhrescoException { String userName = "demouser"; String password = "phresco"; byte[] encodeBase64 = Base64.encodeBase64(password.getBytes()); String encodedPassword = new String(encodeBase64); Credentials credentials = new Credentials(userName, encodedPassword); User user = ldapManager.authenticate(credentials); assertNotNull(user);//from ww w . j av a2 s . c o m }
From source file:de.scrubstudios.srvmon.agent.classes.Crypt.java
/** * This function is used to encrypt the outgoing data. * @param key Encryption key/*from w w w . j a va2s.c o m*/ * @param data Data which will be encrypted. * @return The encrypted data string. */ public static String encrypt(String key, String data) { byte[] encryptedData = null; SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES"); try { Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, keySpec); encryptedData = cipher.doFinal(data.getBytes()); return new String(Base64.encodeBase64(encryptedData)); } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException ex) { Logger.getLogger(Crypt.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:io.hawkcd.agent.services.SecurityService.java
public String encrypt(String raw) { try {//w w w .j ava2s . c om Cipher cipher = getCipher(Cipher.ENCRYPT_MODE); byte[] encryptedVal = cipher.doFinal(getBytes(raw)); byte[] encodedValue = Base64.encodeBase64(encryptedVal); String result = getString(encodedValue); return result; } catch (Throwable t) { throw new RuntimeException(t); } }
From source file:beans.HmacImpl.java
@Override public String sign(Object... objs) { try {// w w w . ja v a2 s .c om List objects = CollectionUtils.addTo(new LinkedList(), objs); objects.add(conf.application.secret); // add the secret so no-one can reproduce this string. String joined = StringUtils.join(objs, SEPARATOR); byte[] base64Result = Base64.encodeBase64(joined.getBytes()); byte[] md5s = MessageDigest.getInstance("MD5").digest(base64Result); StringBuffer sb = new StringBuffer(); for (byte md5 : md5s) { sb.append(Integer.toString((md5 & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); } catch (Exception e) { throw new RuntimeException("unable to sign Hmac for " + ArrayUtils.toString(objs), e); } }
From source file:com.streamsets.pipeline.stage.processor.base64.TestBase64DecodingProcessor.java
public TestBase64DecodingProcessor() { super(new Base64DecodingProcessor(ORIGINAL_PATH, RESULT_PATH), Base64DecodingDProcessor.class, Base64.encodeBase64("testString".getBytes())); }
From source file:com.github.veithen.visualwas.connector.security.BasicAuthCredentials.java
@Override public void configure(HttpURLConnection connection) { try {/*from w w w. jav a2 s.c o m*/ connection.setRequestProperty("Authorization", "Basic " + new String(Base64.encodeBase64((username + ":" + password).getBytes("utf-8")), "ascii")); } catch (UnsupportedEncodingException ex) { throw new Error("Unexpected exception", ex); } }
From source file:edu.kit.scc.cdmi.rest.AuthorizationTest.java
@Test public void testBasicAuthorization() { String auth = restUser + ":" + restPassword; byte[] authZheader = auth.getBytes(); String authorizationHeader = "Basic " + new String(Base64.encodeBase64(authZheader), StandardCharsets.UTF_8); // assertTrue(controller.verifyAuthorization(authorizationHeader)); }
From source file:com.twitter.common.net.ProxyAuthorizer.java
public void authorize(HttpURLConnection httpCon) { httpCon.setRequestProperty("Proxy-Authorization", "Basic " + new String( Base64.encodeBase64(new String(config.getProxyUser() + ":" + config.getProxyPassword()).getBytes())) .trim());//from w w w . j a v a 2 s . co m }
From source file:ca.uhn.fhir.model.primitive.Base64BinaryDt.java
@Override protected String encode(byte[] theValue) { return new String(Base64.encodeBase64(theValue), Constants.CHARSET_UTF8); }