List of usage examples for org.apache.commons.net.util Base64 encodeBase64String
public static String encodeBase64String(byte[] binaryData)
From source file:com.mirth.connect.plugins.datatypes.dicom.test.DICOMSerializerTest.java
@Test public void testToXml1() throws Exception { String input = Base64 .encodeBase64String(FileUtils.readFileToByteArray(new File("tests/test-dicom-input-1.dcm"))); String output = FileUtils.readFileToString(new File("tests/test-dicom-output-1.xml")); DICOMSerializer serializer = new DICOMSerializer(); Assert.assertEquals(output, TestUtil.prettyPrintXml(serializer.toXML(input))); }
From source file:com.mirth.connect.plugins.datatypes.dicom.test.DICOMSerializerTest.java
@Test public void testToXml2() throws Exception { String input = Base64 .encodeBase64String(FileUtils.readFileToByteArray(new File("tests/test-dicom-input-2.dcm"))); String output = FileUtils.readFileToString(new File("tests/test-dicom-output-2.xml")); DICOMSerializer serializer = new DICOMSerializer(); Assert.assertEquals(output, TestUtil.prettyPrintXml(serializer.toXML(input))); }
From source file:com.os.util.PasswordDecoderEncoder.java
public static String encrypt(String plainPassword) throws Exception { Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); key = convertHexToBytes(keyst);//w w w . j a v a 2s . c o m final SecretKeySpec secretKey = new SecretKeySpec(key, "AES"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); final String encryptedString = Base64.encodeBase64String(cipher.doFinal(plainPassword.getBytes("UTF8"))); System.out.println(encryptedString); String passwordEncrypted = encryptedString.trim(); return passwordEncrypted; }
From source file:mysynopsis.ImageProcess.java
public static String toImageString(String path) throws FileNotFoundException, IOException { String imageString = ""; try {/*from ww w.j a v a 2s.c o m*/ File f = new File(path); try (FileInputStream fis = new FileInputStream(f)) { byte byteArray[] = new byte[(int) f.length()]; fis.read(byteArray); imageString = Base64.encodeBase64String(byteArray); fis.close(); } } catch (IOException iOException) { return ""; } return imageString; }
From source file:com.mirth.connect.plugins.datatypes.dicom.test.DICOMSerializerTest.java
@Test public void testToXml3() throws Exception { String input = Base64 .encodeBase64String(FileUtils.readFileToByteArray(new File("tests/test-dicom-input-3.dcm"))); String output = FileUtils.readFileToString(new File("tests/test-dicom-output-3.xml")); DICOMSerializer serializer = new DICOMSerializer(); Assert.assertEquals(output, TestUtil.prettyPrintXml(serializer.toXML(input))); }
From source file:com.jtechme.apphub.net.auth.HttpBasicCredentials.java
@Override public void authenticate(final HttpURLConnection connection) { if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(password)) { // add authorization header from username / password if set connection.setRequestProperty("Authorization", "Basic " + Base64.encodeBase64String((username + ":" + password).getBytes())); }/*from w w w.j av a2 s .c o m*/ }
From source file:com.sorception.jscrap.services.UserService.java
private String getAuthentication(String username, String password) { String creds = username + ":" + password; creds = Base64.encodeBase64String(creds.getBytes()).trim(); return "Basic " + creds; }
From source file:com.kodemore.test.TyRestfulMailActivity.java
public void test() throws Exception { _sender = new KmHttpPost(); _sender.setHost(HTTP_HOST_NAME);//w w w . j av a2s .c o m _sender.setPath(HTTP_PATH); _sender.setPort(HTTP_PORT); _sender.setContentType("application/x-www-form-urlencoded"); /* * assigns the HTTP basic authorization key user:pass encoded in Base64 */ String key = Base64.encodeBase64String(HTTP_AUTH_KEY.getBytes()).toString(); _sender.setHeader("Authorization", "Basic " + key); _sender.setHeader("to", DEFAULT_TO); _sender.setHeader("from", DEFAULT_FROM); _sender.setHeader("subject", DEFAULT_SUBJECT); _sender.setHeader("text", DEFAULT_BODY); _sender.setHttps(); _sender.submit(); alert(_sender.getException().toString()); /* * I was testing apache here (adam) * When we run this we get a "No peer certificate" exception. * URL location = _sender.getUrl(); //this is a hack try { HttpClient client = new DefaultHttpClient(); client.getConnectionManager().getSchemeRegistry().register( new Scheme("SSLSocketFactory", SSLSocketFactory.getSocketFactory(), 80)); HttpContext localContext = new BasicHttpContext(); HttpPost post = new HttpPost(location.toURI()); HttpResponse response = client.execute(post, localContext); } catch ( Exception e ) { alert(e.toString()); } */ }
From source file:com.qubit.solution.fenixedu.bennu.webservices.services.client.WebServiceClientHandler.java
public static String cypher(byte[] sessionKey, String informationToCipher) { Cipher cipher;/* www .j ava2 s. co m*/ try { cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(sessionKey, "AES")); byte[] cipherData = cipher.doFinal(informationToCipher.getBytes("UTF-8")); return Base64.encodeBase64String(cipherData); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.qubit.solution.fenixedu.bennu.webservices.services.client.WebServiceClientHandler.java
private String cypherSessionKey(Key publicKey, byte[] simetricKey) { Cipher cipher;/* w w w . j a va 2 s. com*/ try { cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.ENCRYPT_MODE, publicKey); return Base64.encodeBase64String(cipher.doFinal(simetricKey)); } catch (Exception e) { throw new RuntimeException(e); } }