List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64String
public static String encodeBase64String(final byte[] binaryData)
From source file:de.decoit.visa.protocol.Request.java
/** * Construct a new Request object using the specified command and arguments. * The command is converted to String. The argument map will only be * accepted if its keyset matches the keyset of an empty map requested from * {@link Commands#getEmptyArgumentMap Command.getEmptyArgumentMap()}. * * @param pCommand Command to send// ww w. j a v a2s.co m * @param pArguments Arguments for the command * @see Commands */ public Request(Commands pCommand, Map<String, String> pArguments) { // Check if the provided argument map contains all required keys (and // only these keys) if (pArguments.keySet().equals(Commands.getEmptyArgumentMap(pCommand).keySet())) { command = Base64.encodeBase64String(pCommand.toString().getBytes()); arguments = new HashMap<>(); for (Map.Entry<String, String> s : pArguments.entrySet()) { String key = Base64.encodeBase64String(s.getKey().getBytes()); String value = Base64.encodeBase64String(s.getValue().getBytes()); arguments.put(key, value); } } else { throw new IllegalArgumentException("Invalid argument map provided"); } }
From source file:net.mc_cubed.msrp.MsrpUtil.java
/** * Generate a RFC 4975 Section 7.1 compliant transaction identifier * <p>/*ww w . j a va 2s . c o m*/ * To form a new request, the sender creates a transaction identifier and * uses this and the method name to create an MSRP request start line. The * transaction identifier MUST NOT collide with that of other transactions * that exist at the same time. Therefore, it MUST contain at least 64 bits * of randomness. */ public static String generateMsrpTransactionId() { SecureRandom secure = new SecureRandom(); byte[] bytes = new byte[MSRP_TX_ID_LENGTH]; secure.nextBytes(bytes); return Base64.encodeBase64String(bytes); }
From source file:com.clustercontrol.commons.util.CryptUtil.java
private static String encrypt(String key, String word) { if (word == null) { return null; }//from ww w. j av a2 s . c om // ? SecretKeySpec sksSpec = new SecretKeySpec(key.getBytes(), algorithm); Cipher cipher = null; try { cipher = Cipher.getInstance(algorithm); } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { m_log.warn("encrypt : " + (e.getClass().getName()) + "," + e.getMessage(), e); return null; } try { cipher.init(Cipher.ENCRYPT_MODE, sksSpec); } catch (InvalidKeyException e) { m_log.warn("encrypt : " + (e.getClass().getName()) + "," + e.getMessage(), e); return null; } byte[] encrypted = null; try { encrypted = cipher.doFinal(word.getBytes()); } catch (IllegalBlockSizeException | BadPaddingException e) { m_log.warn("encrypt : " + (e.getClass().getName()) + "," + e.getMessage(), e); return null; } return Base64.encodeBase64String(encrypted); }
From source file:com.willetinc.hadoop.mapreduce.dynamodb.BinarySplitterTest.java
@Test public void testSplitInteger() { final int NUM_RANGE_SPLITS = 2; final String VALUE = "007"; final Types hashKeyType = Types.NUMBER; final AttributeValue hashKeyValue = new AttributeValue().withN(VALUE); final Types rangeKeyType = Types.STRING; final AttributeValue minRangeKeyValue = new AttributeValue() .withB(ByteBuffer.wrap(new byte[] { 0x0, 0x0 })); final AttributeValue maxRangeKeyValue = new AttributeValue() .withB(ByteBuffer.wrap(new byte[] { 0x0, 0xF })); Configuration conf = createMock(Configuration.class); BinarySplitter splitter = new BinarySplitter(); List<InputSplit> inputSplits = new ArrayList<InputSplit>(); splitter.generateRangeKeySplits(conf, inputSplits, hashKeyType, hashKeyValue, rangeKeyType, minRangeKeyValue, maxRangeKeyValue, NUM_RANGE_SPLITS); assertEquals(2, inputSplits.size()); for (InputSplit inputSplit : inputSplits) { DynamoDBQueryInputFormat.DynamoDBQueryInputSplit split = (DynamoDBQueryInputFormat.DynamoDBQueryInputSplit) inputSplit; Iterator<AttributeValue> itr = split.getRangeKeyValues().iterator(); System.out.print(split.getRangeKeyOperator() + " "); System.out.print(Base64.encodeBase64String(itr.next().getB().array()) + " AND "); System.out.println(Base64.encodeBase64String(itr.next().getB().array())); }/*from w w w .j av a2 s . com*/ }
From source file:com.github.aynu.mosir.core.standard.util.SecurityHelper.java
/** * RSA???/*www . j ava 2s . c o m*/ * <dl> * <dt>? * <dd>RSA??????2048?????? * </dl> * @return RSA? */ public static KeyPair createKeyPair() { try { final KeyPairGenerator generator = KeyPairGenerator.getInstance(ALGO_KEY); generator.initialize(2048); final KeyPair pair = generator.generateKeyPair(); if (LOG.isDebugEnabled()) { final RSAPublicKey publicKey = (RSAPublicKey) pair.getPublic(); final RSAPrivateKey privateKey = (RSAPrivateKey) pair.getPrivate(); LOG.debug("public-modulus={}", Base64.encodeBase64String(publicKey.getModulus().toByteArray())); LOG.debug("public-exponent={}", Base64.encodeBase64String(publicKey.getPublicExponent().toByteArray())); LOG.debug("private-modulus={}", Base64.encodeBase64String(privateKey.getModulus().toByteArray())); LOG.debug("private-exponent={}", Base64.encodeBase64String(privateKey.getPrivateExponent().toByteArray())); } return pair; } catch (final NoSuchAlgorithmException e) { throw new StandardRuntimeException(e); } }
From source file:com.fujitsu.dc.test.utils.RelationUtils.java
/** * Relation??(Basic?).//from w w w.j a v a 2 s . c o m * @param cellName ?? * @param accountName Basic???Account?? * @param password Basic??? * @param body Body * @param code ? * @return ? */ public static TResponse createWithBasic(final String cellName, final String accountName, final String password, final JSONObject body, int code) { String credentials = Base64.encodeBase64String((accountName + ":" + password).getBytes()); TResponse response = Http.request("relation-create.txt").with("token", "Basic " + credentials) .with("cellPath", cellName).with("body", body.toString()).returns().statusCode(code); return response; }
From source file:net.jmhertlein.mcanalytics.plugin.listener.writer.AddUserTask.java
@Override protected void write(Connection c, StatementProvider stmts) throws SQLException { byte[] salt = SSLUtil.newSalt(); byte[] pass;/* w w w .jav a2 s . c om*/ try { pass = password.getBytes("UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.getLogger(AddUserTask.class.getName()).log(Level.SEVERE, null, ex); return; } byte[] hash; try { hash = SSLUtil.hash(pass, salt); } catch (NoSuchAlgorithmException | NoSuchProviderException ex) { Logger.getLogger(AddUserTask.class.getName()).log(Level.SEVERE, null, ex); return; } try (PreparedStatement addUser = c.prepareStatement(stmts.get(SQLString.ADD_NEW_USER))) { addUser.setString(1, username); addUser.setString(2, Base64.encodeBase64String(hash)); addUser.setString(3, Base64.encodeBase64String(salt)); addUser.executeUpdate(); } catch (SQLException ex) { Bukkit.getScheduler().callSyncMethod(p, () -> { sender.sendMessage(ChatColor.RED + "Error adding player: " + ex.getMessage()); return null; }); throw ex; } Bukkit.getScheduler().callSyncMethod(p, () -> { sender.sendMessage(ChatColor.GREEN + "Player added."); return null; }); }
From source file:fitmon.WorkoutApi.java
public StringBuilder apiGetInfo() throws ClientProtocolException, IOException, NoSuchAlgorithmException, InvalidKeyException { HttpClient client = new DefaultHttpClient(); //HttpGet request = new HttpGet("http://platform.fatsecret.com/rest/server.api&" // + "oauth_consumer_key=5f2d9f7c250c4d75b9807a4f969363a7&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1408230438&" // + "oauth_nonce=abc&oauth_version=1.0&method=food.get&food_id=4384"); //HttpResponse response = client.execute(request); //BufferedReader rd = new BufferedReader (new InputStreamReader(response.getEntity().getContent())); //StringBuilder sb = new StringBuilder(); String base = URLEncoder.encode("GET") + "&"; base += "http%3A%2F%2Fplatform.fatsecret.com%2Frest%2Fserver.api&"; String params;// w w w. j a v a 2 s . c o m params = "format=json&"; params += "method=exercises.get&"; params += "oauth_consumer_key=5f2d9f7c250c4d75b9807a4f969363a7&"; // ur consumer key params += "oauth_nonce=123&"; params += "oauth_signature_method=HMAC-SHA1&"; Date date = new java.util.Date(); Timestamp ts = new Timestamp(date.getTime()); params += "oauth_timestamp=" + ts.getTime() + "&"; params += "oauth_version=1.0"; //params += "search_expression=apple"; String params2 = URLEncoder.encode(params); base += params2; //System.out.println(base); String line = ""; String secret = "76172de2330a4e55b90cbd2eb44f8c63&"; Mac sha256_HMAC = Mac.getInstance("HMACSHA1"); SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(), "HMACSHA1"); sha256_HMAC.init(secret_key); String hash = Base64.encodeBase64String(sha256_HMAC.doFinal(base.getBytes())); //$url = "http://platform.fatsecret.com/rest/server.api?".$params."&oauth_signature=".rawurlencode($sig); HttpGet request = new HttpGet("http://platform.fatsecret.com/rest/server.api?" + params + "&oauth_signature=" + URLEncoder.encode(hash)); HttpResponse response = client.execute(request); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuilder sb = new StringBuilder(); //$url = "http://platform.fatsecret.com/rest/server.api?"+params+"&oauth_signature="+URLEncoder.encode(hash); //return url; while ((line = rd.readLine()) != null) { sb.append(line); //System.out.println(line); } //System.out.println(sb.toString()); return sb; }
From source file:com.hazelcast.simulator.probes.probes.impl.HdrLatencyDistributionResult.java
@Override public void writeTo(XMLStreamWriter writer) { Histogram tmp = histogram.copy();/*from w ww. ja v a 2s . co m*/ int size = tmp.getNeededByteBufferCapacity(); ByteBuffer byteBuffer = ByteBuffer.allocate(size); int bytesWritten = tmp.encodeIntoCompressedByteBuffer(byteBuffer); byteBuffer.rewind(); byteBuffer.limit(bytesWritten); String encodedData = Base64.encodeBase64String(byteBuffer.array()); try { writer.writeStartElement(ProbesResultXmlElements.HDR_LATENCY_DATA.getName()); writer.writeCData(encodedData); writer.writeEndElement(); } catch (XMLStreamException e) { throw new RuntimeException(e); } }
From source file:baggage.BaseTestCase.java
protected String randomString(int byteLength) { byte[] bytes = makeRandomBytes(byteLength); return Base64.encodeBase64String(bytes); }