當前位置: 首頁>>代碼示例>>Java>>正文


Java Base64.encodeBase64String方法代碼示例

本文整理匯總了Java中org.apache.commons.net.util.Base64.encodeBase64String方法的典型用法代碼示例。如果您正苦於以下問題:Java Base64.encodeBase64String方法的具體用法?Java Base64.encodeBase64String怎麽用?Java Base64.encodeBase64String使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.net.util.Base64的用法示例。


在下文中一共展示了Base64.encodeBase64String方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCommandString

import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
/**
 * Returns the Base64 encoded command string to be sent via the MAX! Cube.
 *
 * @return the string representing the command
 */
@Override
public String getCommandString() {

    StringBuilder commandConfigString = new StringBuilder();
    for (byte b : commandBytes) {
        commandConfigString.append(String.format("%02X", b));
    }

    String commandString = baseString + rfAddress;
    if (configCommandType == ConfigCommandType.SetRoom || configCommandType == ConfigCommandType.RemoveRoom) {
        commandString = commandString + commandConfigString + Utils.toHex(roomId);
    } else {
        commandString = commandString + Utils.toHex(roomId) + commandConfigString;
    }

    String encodedString = Base64.encodeBase64String(Utils.hexStringToByteArray(commandString));
    return "s:" + encodedString;
}
 
開發者ID:openhab,項目名稱:openhab2-addons,代碼行數:24,代碼來源:S_ConfigCommand.java

示例2: getCommandString

import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
/**
 * Returns the Base64 encoded command string to be sent via the MAX!
 * protocol.
 *
 * @return the string representing the command
 */
@Override
public String getCommandString() {

    String baseString = "";
    if (roomId == 0) {
        baseString = baseStringS;
    } else {
        baseString = baseStringG;
    }

    String commandString = baseString + rfAddress + Utils.toHex(roomId) + Utils.toHex(bits);

    String encodedString = Base64.encodeBase64String(Utils.hexStringToByteArray(commandString));

    return "s:" + encodedString;
}
 
開發者ID:openhab,項目名稱:openhab2-addons,代碼行數:23,代碼來源:S_Command.java

示例3: jsonAddKeyStore

import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
/**
 *
 * @param json
 * @param keyStore
 * @param keystorePwd
 */
private static void jsonAddKeyStore(JSONObject json, String keyStore, String keystorePwd) {
  json.append(Constants.JSON_KEYSTOREPWD, keystorePwd);

  try {
    FileInputStream kfin = new FileInputStream(new File(keyStore));
    byte[] kStoreBlob = ByteStreams.toByteArray(kfin);
    String keystorString = Base64.encodeBase64String(kStoreBlob);
    json.append(Constants.JSON_KEYSTORE, keystorString);
  } catch (IOException ex) {
    LOGGER.log(Level.SEVERE, null, ex);
  }
}
 
開發者ID:hopshadoop,項目名稱:hops-util,代碼行數:19,代碼來源:DelaHelper.java

示例4: encryptAes

import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
public static String encryptAes(String key, String strToEncrypt) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
	Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
	SecretKeySpec secretKey = new SecretKeySpec(Base64.decodeBase64(key), "AES");
	
	cipher.init(Cipher.ENCRYPT_MODE, secretKey);
	String encryptedString = Base64.encodeBase64String(cipher.doFinal(strToEncrypt.getBytes()));
	return encryptedString;
}
 
開發者ID:Transkribus,項目名稱:TranskribusSwtGui,代碼行數:9,代碼來源:TrpGuiPrefs.java

示例5: toAscii

import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
public static String toAscii(byte[] bytes) throws Exception {
	StringBuilder sb = new StringBuilder();
	String encodeBase64String = Base64.encodeBase64String(bytes);
	// remove extra \n
	String[] lines = encodeBase64String.split("\\r\\n");
	for (String s : lines) {
		sb.append(s);
	}
	return sb.toString();
}
 
開發者ID:frett27,項目名稱:osm-flink-tools,代碼行數:11,代碼來源:GeometryTools.java

示例6: encrypt

import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
/**
 *
 * @param key
 * @param plaintext
 * @return
 * @throws Exception
 */
public static String encrypt(String key, String plaintext, String masterEncryptionPassword)
    throws Exception {
  
  Key aesKey = generateKey(key, masterEncryptionPassword);
  Cipher cipher = Cipher.getInstance("AES");
  cipher.init(Cipher.ENCRYPT_MODE, aesKey);
  byte[] encrypted = cipher.doFinal(plaintext.getBytes());
  return Base64.encodeBase64String(encrypted);
}
 
開發者ID:hopshadoop,項目名稱:hopsworks,代碼行數:17,代碼來源:HopsUtils.java

示例7: encrypt

import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
public String encrypt(String input)
        throws InvalidKeyException, 
               BadPaddingException,
               IllegalBlockSizeException, 
               UnsupportedEncodingException 
{
	cipher.init(Cipher.ENCRYPT_MODE, key);
	byte[] utf8 = input.getBytes("UTF8");
	byte[] encryptedData = cipher.doFinal(utf8);
	return Base64.encodeBase64String(encryptedData);
}
 
開發者ID:thampiman,項目名稱:Android-Projects,代碼行數:12,代碼來源:Encrypter.java

示例8: encryptString

import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
public static String encryptString(String string) {
    try {
        byte[] text = string.getBytes("ISO-8859-1");
        cipher.init(Cipher.ENCRYPT_MODE, myDesKey);
        byte[] textEncrypted = cipher.doFinal(text);
        return Base64.encodeBase64String(textEncrypted);
    } catch (Exception e) {
        e.printStackTrace();
        return string;
    }
}
 
開發者ID:CodingBadgers,項目名稱:bUpload,代碼行數:12,代碼來源:CipherUtils.java

示例9: arraysToBase64

import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
/**
 * Returns a tab delimited base 64
 * representation of the given arrays
 * @param arrays the arrays
 * @return
 * @throws IOException
 */
public static String arraysToBase64(INDArray[] arrays) throws IOException {
    StringBuilder sb = new StringBuilder();
    //tab separate the outputs for de serialization
    for (INDArray outputArr : arrays) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(bos);
        Nd4j.write(outputArr, dos);
        String base64 = Base64.encodeBase64String(bos.toByteArray());
        sb.append(base64);
        sb.append("\t");
    }

    return sb.toString();
}
 
開發者ID:deeplearning4j,項目名稱:nd4j,代碼行數:22,代碼來源:Nd4jBase64.java

示例10: keystoreEncode

import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
private static String keystoreEncode() throws IOException {
  FileInputStream kfin = new FileInputStream(new File(keyStore));
  byte[] kStoreBlob = ByteStreams.toByteArray(kfin);
  return Base64.encodeBase64String(kStoreBlob);
}
 
開發者ID:hopshadoop,項目名稱:hops-util,代碼行數:6,代碼來源:HopsUtil.java

示例11: downloadCerts

import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
@POST
@Path("{id}/downloadCert")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({AllowedProjectRoles.DATA_OWNER})
public Response downloadCerts(@PathParam("id") Integer id, @FormParam("password") String password,
    @Context HttpServletRequest req) throws AppException {
  Users user = userFacade.findByEmail(req.getRemoteUser());
  if (user == null || user.getEmail().equals(Settings.AGENT_EMAIL) || !authController.validatePassword(user, password,
      req)) {
    throw new AppException(Response.Status.FORBIDDEN.getStatusCode(), "Access to the certificat has been forbidden.");
  }
  Project project = projectController.findProjectById(id);
  String keyStorePath;
  String trustStorePath;
  String keyStore = "";
  String trustStore = "";
  try {
    //Read certs from database and stream them out
    certificateMaterializer.materializeCertificates(user.getUsername(), project.getName());
    keyStorePath = settings.getHopsworksTmpCertDir() + File.separator + HopsUtils.getProjectKeystoreName(project.
        getName(), user.getUsername());
    trustStorePath = settings.getHopsworksTmpCertDir() + File.separator + HopsUtils.
        getProjectTruststoreName(project.getName(), user.getUsername());
    keyStore = Base64.encodeBase64String(Files.readAllBytes(Paths.get(keyStorePath)));
    trustStore = Base64.encodeBase64String(Files.readAllBytes(Paths.get(trustStorePath)));
    //Send email with decrypted password to user
    String certPwd = projectController.getProjectSpecificCertPw(user, project.getName(),
        Base64.encodeBase64String(certsFacade.findUserCert(project.getName(), user.getUsername()).getUserKey()))
        .getKeyPw();
    //Pop-up a message from admin
    messageController.send(user, userFacade.findByEmail(Settings.SITE_EMAIL), "Certificate Info", "",
        "An email was sent with the password for your project's certificates. If an email does not arrive shortly, "
        + "please check spam first and then contact the HopsWorks administrator.", "");
    emailBean.sendEmail(user.getEmail(), Message.RecipientType.TO, "Hopsworks certificate information",
        "The password for keystore and truststore is:" + certPwd);
  } catch (IOException ioe) {
    logger.log(Level.SEVERE, ioe.getMessage());
    throw new AppException(Response.Status.BAD_REQUEST.getStatusCode(), ResponseMessages.DOWNLOAD_ERROR);
  } catch (Exception ex) {
    logger.log(Level.SEVERE, null, ex);
    throw new AppException(Response.Status.BAD_REQUEST.getStatusCode(), ResponseMessages.DOWNLOAD_ERROR);
  }
  CertsDTO certsDTO = new CertsDTO("jks", keyStore, trustStore);
  return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(certsDTO).build();
}
 
開發者ID:hopshadoop,項目名稱:hopsworks,代碼行數:46,代碼來源:ProjectService.java

示例12: keystoreEncode

import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
private static String keystoreEncode(String keyStorePath) throws IOException {
  FileInputStream keyStoreInStream = new FileInputStream(
      new File(keyStorePath));
  byte[] kStoreBlob = ByteStreams.toByteArray(keyStoreInStream);
  return Base64.encodeBase64String(kStoreBlob);
}
 
開發者ID:hopshadoop,項目名稱:hops,代碼行數:7,代碼來源:HopsUtil.java

示例13: getKeyDigestAsBase64

import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
public String getKeyDigestAsBase64() { 
  invalidUpdateState = true;
  return Base64.encodeBase64String(keyDigest.digest()); 
}
 
開發者ID:DemandCube,項目名稱:Scribengin,代碼行數:5,代碼來源:RecordChecksum.java

示例14: getDataDigestAsBase64

import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
public String getDataDigestAsBase64() {
  invalidUpdateState = true;
  return Base64.encodeBase64String(dataDigest.digest()); 
}
 
開發者ID:DemandCube,項目名稱:Scribengin,代碼行數:5,代碼來源:RecordChecksum.java

示例15: getCommandString

import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
/**
 * Returns the Base64 encoded command string to be sent via the MAX!
 * protocol.
 * 
 * @return the string representing the command
 */
public String getCommandString() {

	String commandString = baseString + rfAddress + Utils.toHex(roomId) + Utils.toHex(bits);

	String encodedString = Base64.encodeBase64String(Utils.hexStringToByteArray(commandString));

	return "s:" + encodedString;
}
 
開發者ID:Neulinet,項目名稱:Zoo,代碼行數:15,代碼來源:S_Command.java


注:本文中的org.apache.commons.net.util.Base64.encodeBase64String方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。