List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64
public static byte[] encodeBase64(final byte[] binaryData)
From source file:edu.ncu.csie.oolab.CommandTest.java
@Test public void testExit() { HashMap<String, Object> args = new HashMap<String, Object>(); args.put("command", "exit"); 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());//from ww w.java 2 s . c o m assertEquals(args, null); }
From source file:com.aerohive.nms.engine.admin.task.licensemgr.common.AerohiveEncryptTool.java
/** * @param arg_OriginalStr// w w w .ja v a 2 s .c o m * @param arg_Type * @return */ public String encrypt(String arg_OriginalStr) { try { // Encode the string into bytes using utf-8 byte[] byte_Utf8 = arg_OriginalStr.getBytes("UTF8"); // Encrypt byte[] byte_Enc = m_Cipher_Ecipher.doFinal(byte_Utf8); // Encode bytes to base64 to get a string return new String(Base64.encodeBase64(byte_Enc)); } catch (Exception e) { //DebugUtil.commonDebugWarn(e.getMessage()); } return null; }
From source file:co.mitro.twofactor.CryptoForBackupCodes.java
public static String digestToStringEncode(byte[] saltCode) { String toStore = new String(Base64.encodeBase64(saltCode), Charsets.UTF_8); //assert toBytes = Base64.decode(saltCode.getBytes()) is toStore return toStore; }
From source file:jp.co.yahoo.yconnect.core.oauth2.RefreshTokenClient.java
public void fetch() throws TokenException, Exception { HttpParameters parameters = new HttpParameters(); parameters.put("grant_type", OAuth2GrantType.REFRESH_TOKEN); parameters.put("refresh_token", refreshToken); String credential = clientId + ":" + clientSecret; String basic = new String(Base64.encodeBase64(credential.getBytes())); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.put("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); requestHeaders.put("Authorization", "Basic " + basic); client = new YHttpClient(); client.requestPost(endpointUrl, parameters, requestHeaders); YConnectLogger.debug(TAG, client.getResponseHeaders().toString()); YConnectLogger.debug(TAG, client.getResponseBody().toString()); String json = client.getResponseBody(); JsonReader jsonReader = Json.createReader(new StringReader(json)); JsonObject jsonObject = jsonReader.readObject(); jsonReader.close();// www . j a v a 2s.co m int statusCode = client.getStatusCode(); checkErrorResponse(statusCode, jsonObject); String accessTokenString = (String) jsonObject.getString("access_token"); long expiresIn = Long.parseLong((String) jsonObject.getString("expires_in")); accessToken = new BearerToken(accessTokenString, expiresIn, refreshToken); }
From source file:com.cyberninjas.xerobillableexpenses.util.Settings.java
public Settings() { try {//from w w w .java2s. co m String parentClass = new Exception().getStackTrace()[1].getClassName(); this.prefs = Preferences.userNodeForPackage(Class.forName(parentClass)); Random r = new SecureRandom(); //Set IV this.iv = prefs.getByteArray("DRUGS", null); //Pick Random PWD byte[] b = new byte[128]; r.nextBytes(b); MessageDigest sha = MessageDigest.getInstance("SHA-1"); sha.update(b); String sHash = new String(Base64.encodeBase64(sha.digest())); String password = prefs.get("LAYOUT", sHash); if (password.equals(sHash)) prefs.put("LAYOUT", sHash); //Keep 'em Guessing r.nextBytes(b); sha.update(b); prefs.put("PASSWORD", new String(Base64.encodeBase64(sha.digest()))); //Set Random Salt byte[] tSalt = new byte[8]; r.nextBytes(tSalt); byte[] salt = prefs.getByteArray("HIMALAYAN", tSalt); if (Arrays.equals(salt, tSalt)) prefs.putByteArray("HIMALAYAN", salt); /* Derive the key, given password and salt. */ SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, 65536, 128); SecretKey tmp = factory.generateSecret(spec); this.secret = new SecretKeySpec(tmp.getEncoded(), "AES"); cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(RSAx509CertGen.class.getName()).log(Level.SEVERE, null, ex); } catch (InvalidKeySpecException ex) { Logger.getLogger(RSAx509CertGen.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(RSAx509CertGen.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:io.appium.java_client.ios.ImagesComparisonTest.java
@Test public void verifyOccurrencesSearch() { byte[] screenshot = Base64.encodeBase64(driver.getScreenshotAs(OutputType.BYTES)); OccurrenceMatchingResult result = driver.findImageOccurrence(screenshot, screenshot, new OccurrenceMatchingOptions().withEnabledVisualization()); assertThat(result.getVisualization().length, is(greaterThan(0))); assertNotNull(result.getRect());//from w w w .j a va 2 s . c om }
From source file:fr.ms.tomcat.manager.TomcatManagerUrl.java
private static String toAuthorization(final String username, final String password) { final StringBuilder buffer = new StringBuilder(); buffer.append(username).append(':'); if (password != null) { buffer.append(password);/*from ww w.j ava 2s . co m*/ } return "Basic " + new String(Base64.encodeBase64(buffer.toString().getBytes())); }
From source file:com.ecyrd.jspwiki.util.Serializer.java
/** * Serializes a Map and formats it into a Base64-encoded String. For ease of serialization, the Map contents * are first copied into a HashMap, then serialized into a byte array that is encoded as a Base64 String. * @param map the Map to serialize/*w w w . j av a 2 s . c om*/ * @return a String representing the serialized form of the Map * @throws IOException If serialization cannot be done */ public static String serializeToBase64(Map<String, Serializable> map) throws IOException { // Load the Map contents into a defensive HashMap HashMap<String, Serializable> serialMap = new HashMap<String, Serializable>(); serialMap.putAll(map); // Serialize the Map to an output stream ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bytesOut); out.writeObject(serialMap); out.close(); // Transform to Base64-encoded String byte[] result = Base64.encodeBase64(bytesOut.toByteArray()); return new String(result); }
From source file:io.appium.java_client.android.ImagesComparisonTest.java
@Test public void verifyOccurrencesLookup() { byte[] screenshot = Base64.encodeBase64(driver.getScreenshotAs(OutputType.BYTES)); OccurrenceMatchingResult result = driver.findImageOccurrence(screenshot, screenshot, new OccurrenceMatchingOptions().withEnabledVisualization()); assertThat(result.getVisualization().length, is(greaterThan(0))); assertNotNull(result.getRect());//from ww w . j av a 2 s . c o m }
From source file:com.threerings.getdown.tools.Digester.java
/** * Creates a digest file in the specified application directory. *//* w w w. ja v a 2 s .c om*/ public static void signDigest(File appdir, File storePath, String storePass, String storeAlias) throws IOException, GeneralSecurityException { File inputFile = new File(appdir, Digest.DIGEST_FILE); File signatureFile = new File(appdir, Digest.DIGEST_FILE + Application.SIGNATURE_SUFFIX); FileInputStream storeInput = null, dataInput = null; FileOutputStream signatureOutput = null; try { // initialize the keystore KeyStore store = KeyStore.getInstance("JKS"); storeInput = new FileInputStream(storePath); store.load(storeInput, storePass.toCharArray()); PrivateKey key = (PrivateKey) store.getKey(storeAlias, storePass.toCharArray()); // sign the digest file Signature sig = Signature.getInstance("SHA1withRSA"); dataInput = new FileInputStream(inputFile); byte[] buffer = new byte[8192]; int length; sig.initSign(key); while ((length = dataInput.read(buffer)) != -1) { sig.update(buffer, 0, length); } // Write out the signature signatureOutput = new FileOutputStream(signatureFile); String signed = new String(Base64.encodeBase64(sig.sign())); signatureOutput.write(signed.getBytes("utf8")); } finally { StreamUtil.close(signatureOutput); StreamUtil.close(dataInput); StreamUtil.close(storeInput); } }