List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64String
public static String encodeBase64String(final byte[] binaryData)
From source file:Models.UserModel.java
public static String HMAC_SHA256(String email, String password) { try {/*from www . jav a 2 s .co m*/ Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); SecretKeySpec secret_key = new SecretKeySpec(password.getBytes(), "HmacSHA256"); sha256_HMAC.init(secret_key); String auth = Base64.encodeBase64String(sha256_HMAC.doFinal(email.getBytes())); return auth; } catch (NoSuchAlgorithmException | InvalidKeyException | IllegalStateException e) { System.out.println("Error HS-256"); return ""; } }
From source file:com.cloudera.kitten.util.LocalDataHelper.java
public static <T> String serialize(Map<String, T> mapping) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {//ww w . java 2 s . co m ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(mapping); oos.close(); } catch (IOException e) { throw new RuntimeException(e); } return Base64.encodeBase64String(baos.toByteArray()); }
From source file:com.c9.dashboard.DashboardModule.java
public void start() { super.start(); baseUrl = getOptionalStringConfig("klipfolioBaseUrl", null); username = getOptionalStringConfig("username", null); password = getOptionalStringConfig("password", null); apiVersion = getOptionalStringConfig("apiVersion", "/api/1/"); if (baseUrl == null || username == null || password == null) { throw new RuntimeException("Mandatory Fields were not set!"); }//w ww. j a v a 2 s . co m encodedUserPwd = Base64.encodeBase64String(StringUtils.getBytesUtf8(username + ":" + password)); client = vertx.createHttpClient().setHost(baseUrl).setSSL(true).setPort(443).setMaxPoolSize(10); apiHandler = new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> event) { logger.debug("Recieved Event : " + event.body()); String action = getMandatoryString("action", event); try { if ("get".equalsIgnoreCase(action)) { doGet(event); } else if ("add".equalsIgnoreCase(action)) { // Call the getAPI and reply doPost(event); } else if ("update".equalsIgnoreCase(action)) { doPut(event); } else if ("delete".equalsIgnoreCase(action)) { doDelete(event); } } catch (Exception e) { sendError(event, e.getMessage(), e); } } }; vertx.eventBus().registerHandler("klipfolio.api", apiHandler); }
From source file:de.hybris.platform.b2b.punchout.PunchOutUtils.java
/** * Transforms a CXML into a Base64 String. * //from w w w.j av a 2 s. co m * @param cxml * the cxml object. * @return Base64 String */ public static String transformCXMLToBase64(final CXML cxml) { final String cXML = marshallFromBeanTree(cxml); final String cXMLEncoded = Base64.encodeBase64String(cXML.getBytes()); return cXMLEncoded; }
From source file:energy.usef.core.endpoint.EncryptionKeyEndpoint.java
/** * REST endpoint to create a new Encryption key pair in the system. Private key will be stored in a keystore and the public key * is returned in the HTTP response as a Base64-encoded String. * * @param seed - {@link String} password to generate the key pair. * @return a Base64 encoded {@link String} *///w ww . j av a2 s .c o m @POST @Path("/create") @Consumes({ TEXT_PLAIN }) public Response createNewEncryptionKeyPair(String seed) { LOGGER.warn("Creating a new NaCl secret key in the keystore."); byte[] publicKey = keystoreHelperService.createSecretKey(seed); LOGGER.info("Creation of the NaCl secret key is successful"); LOGGER.info("Associated public key: {}", Base64.encodeBase64String(publicKey)); return Response.status(Response.Status.OK).entity(Base64.encodeBase64String(publicKey)).build(); }
From source file:ch.fork.AdHocRailway.ui.utils.ImageTools.java
/** * Encode image to string/* w w w. j av a 2 s .c o m*/ * * @param image The image to encode * @param type jpeg, bmp, ... * @return encoded string */ public static String encodeToString(BufferedImage image, String type) { String imageString = null; ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { ImageIO.write(image, type, bos); byte[] imageBytes = bos.toByteArray(); imageString = Base64.encodeBase64String(imageBytes); bos.close(); } catch (IOException e) { e.printStackTrace(); } return imageString; }
From source file:cn.org.once.cstack.utils.CustomPasswordEncoder.java
@Override public String encode(CharSequence sequence) { Cipher cipher;//from w w w. j ava 2 s . c o m String encryptedString = null; try { cipher = Cipher.getInstance(ALGO); cipher.init(Cipher.ENCRYPT_MODE, generateKey()); encryptedString = Base64.encodeBase64String(cipher.doFinal(sequence.toString().getBytes())); } catch (Exception e) { e.printStackTrace(); } return encryptedString; }
From source file:com.cloud.utils.crypt.RSAHelper.java
public static String encryptWithSSHPublicKey(String sshPublicKey, String content) { String returnString = null;//from w w w.j av a 2s .co m try { RSAPublicKey publicKey = readKey(sshPublicKey); Cipher cipher = Cipher.getInstance("RSA/None/PKCS1Padding", BouncyCastleProvider.PROVIDER_NAME); cipher.init(Cipher.ENCRYPT_MODE, publicKey, new SecureRandom()); byte[] encrypted = cipher.doFinal(content.getBytes()); returnString = Base64.encodeBase64String(encrypted); } catch (Exception e) { } return returnString; }
From source file:com.monarchapis.driver.hash.HawkV1RequestHasher.java
/** * Creates a Hawk payload hash.// www . j ava 2 s .c o m */ @Override public String getRequestHash(ApiRequest request, String algorithm) { try { String digestAlgorithm = HasherUtils.getMessageDigestAlgorithm(algorithm); String mimeType = StringUtils.substringBefore(request.getContentType(), ";"); MessageDigest digest = MessageDigest.getInstance(digestAlgorithm); ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write("hawk.1.payload\n".getBytes("UTF-8")); if (mimeType != null) { baos.write(mimeType.getBytes("UTF-8")); } baos.write('\n'); baos.write(request.getBody()); baos.write('\n'); byte[] hash = digest.digest(baos.toByteArray()); return Base64.encodeBase64String(hash); } catch (Exception e) { throw new ApiException("Could not generate request hash", e); } }
From source file:com.aqnote.shared.cryptology.cert.io.PKCSTransformer.java
public static String getCRLFileB64(X509CRL x509CRL) throws Exception { return Base64.encodeBase64String(x509CRL.getEncoded()); }