List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64
public static byte[] encodeBase64(final byte[] binaryData)
From source file:info.bonjean.beluga.util.CryptoUtil.java
public static String passwordEncrypt(String text, String strKey) { return new String(Base64.encodeBase64(encryptBlowfish(text, strKey))); }
From source file:com.sonatype.nexus.repository.nuget.internal.odata.NugetPackageUtils.java
/** * Determine the metadata for a nuget package. * - nuspec data (comes from .nuspec)//from www. j a v a 2s .c o m * - size (package size) * - hash(es) (package hash sha-512) */ public static Map<String, String> packageMetadata(final InputStream inputStream) throws IOException, NugetPackageException { try (MultiHashingInputStream hashingStream = new MultiHashingInputStream( Arrays.asList(HashAlgorithm.SHA512), inputStream)) { final byte[] nuspec = extractNuspec(hashingStream); Map<String, String> metadata = NuspecSplicer.extractNuspecData(new ByteArrayInputStream(nuspec)); ByteStreams.copy(hashingStream, ByteStreams.nullOutputStream()); metadata.put(PACKAGE_SIZE, String.valueOf(hashingStream.count())); HashCode code = hashingStream.hashes().get(HashAlgorithm.SHA512); metadata.put(PACKAGE_HASH, new String(Base64.encodeBase64(code.asBytes()), Charsets.UTF_8)); metadata.put(PACKAGE_HASH_ALGORITHM, "SHA512"); return metadata; } catch (XmlPullParserException e) { throw new NugetPackageException("Unable to read .nuspec from package stream", e); } }
From source file:de.mpg.escidoc.services.aa.crypto.RSAEncoder.java
public static String rsaEncrypt(String string) throws Exception { StringWriter resultWriter = new StringWriter(); byte[] bytes = string.getBytes("UTF-8"); PublicKey pubKey = (PublicKey) readKeyFromFile(Config.getProperty("escidoc.aa.public.key.file"), true); Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.ENCRYPT_MODE, pubKey); int blockSize = 245; for (int i = 0; i < bytes.length; i += blockSize) { byte[] result = cipher.doFinal(bytes, i, (i + blockSize < bytes.length ? blockSize : bytes.length - i)); if (i > 0) { resultWriter.write("&"); }/*from w w w . j ava 2s . c om*/ resultWriter.write("auth="); resultWriter.write(URLEncoder.encode(new String(Base64.encodeBase64(result)), "ISO-8859-1")); } return resultWriter.toString(); }
From source file:com.appdynamics.common.RESTClient.java
public static void sendPost(String urlString, String input, String apiKey) { try {//from ww w . j a v a 2s .c o m URL url = new URL(urlString); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Authorization", "Basic " + new String(Base64.encodeBase64((apiKey).getBytes()))); OutputStream os = conn.getOutputStream(); os.write(input.getBytes()); os.flush(); if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) { throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); String output; logger.info("Output from Server .... \n"); while ((output = br.readLine()) != null) { logger.info(output); } conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:net.sourceforge.atunes.kernel.modules.proxy.Proxy.java
public URLConnection getConnection(URL u) throws IOException { URLConnection con = u.openConnection(this); String encodedUserPwd = new String( Base64.encodeBase64((StringUtils.getString(user, ':', password)).getBytes())); con.setRequestProperty("Proxy-Authorization", "Basic " + encodedUserPwd); return con;//ww w . j a v a 2s . com }
From source file:com.hobba.hobaserver.services.security.ChallengeUtil.java
public String getChallenge(String kid, long expirationTime) { HobaKeys hk = new HobaKeys(); HobaKeysFacadeREST hkfrest = new HobaKeysFacadeREST(); HobaChallengesFacadeREST hcfrest = new HobaChallengesFacadeREST(); hk = hkfrest.findHKIDbyKID(kid);//w w w. j a va 2 s . c o m SecureRandom random = new SecureRandom(); String rand = new BigInteger(130, random).toString(32); HobaChallenges hc = new HobaChallenges(); hc.setIdKeys(hk); hc.setChalenge(rand); if (expirationTime > 0) { Date date = new Date(new Date().getTime() + (expirationTime * 100)); hc.setExpiration(date); } hc.setExpiration(null); hc.setIsValid(Boolean.TRUE); hcfrest.create(hc); return new String(Base64.encodeBase64(rand.getBytes())); }
From source file:com.alu.e3.auth.executor.HttpBasicExecutorTest.java
@Test public void testWin() { Exchange exchange = new DefaultExchange(context); Api api = new Api(); api.setId("123"); // Setting the username = "win" should succeed exchange.getIn().setHeader(AuthHttpHeaders.Authorization.toString(), "Basic " + new String(Base64.encodeBase64("win:blarg".getBytes()))); HttpBasicExecutor executor = new HttpBasicExecutor(new MockAuthDataAccess(null, "win:blarg", null)); AuthReport authReport = executor.checkAllowed(exchange, api); assertNotNull("This authentication should have succeeded", authReport.getAuthIdentity()); }
From source file:edu.ncu.csie.oolab.CommandTest.java
@Test public void testExecute() { HashMap<String, Object> args = new HashMap<String, Object>(); args.put("command", "execute"); args.put("script", "print \'Hello, world!\'\n"); String b64Data = this.json_.toJson(args); b64Data = new String(Base64.encodeBase64(b64Data.getBytes(Charset.forName("UTF-8"))), Charset.forName("UTF-8")); b64Data = this.parser_.execute(b64Data); b64Data = new String(Base64.decodeBase64(b64Data.getBytes(Charset.forName("UTF-8"))), Charset.forName("UTF-8")); args = this.json_.fromJson(b64Data, (new TypeToken<HashMap<String, Object>>() { }).getType());/* ww w . j a v a2 s . co m*/ assertTrue((Boolean) args.get("success")); }
From source file:com.moss.bdbadmin.api.util.AuthenticationHeader.java
public static String encode(IdProof a) { VeracityIdProof assertion = (VeracityIdProof) a; // only veracity is supported at present String profileName = ""; String profileLastModified = ""; if (assertion.getProfileDesc() != null && assertion.getProfileDesc().getName() != null) { profileName = assertion.getProfileDesc().getName(); profileLastModified = Long.toString(assertion.getProfileDesc().getWhenLastModified()); }//from w w w .j av a2s.co m return new StringBuilder().append(assertion.getIdentity().toString()).append(":") .append(assertion.getExpiration()).append(":") .append(new String(Base64.encodeBase64(assertion.getKeyDigest()))).append(":").append(profileName) .append(":").append(profileLastModified).append(":") .append(new String(Base64.encodeBase64(assertion.getSignature()))).toString(); }
From source file:com.jennifer.ui.util.dom.Svg.java
public String toDataURL() { try {/*from w w w . ja v a 2 s. c om*/ return "data:image/svg+xml;base64," + new String(Base64.encodeBase64(toXml().getBytes("UTF-8")), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return ""; }