本文整理匯總了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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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;
}
}
示例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();
}
示例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);
}
示例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();
}
示例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);
}
示例13: getKeyDigestAsBase64
import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
public String getKeyDigestAsBase64() {
invalidUpdateState = true;
return Base64.encodeBase64String(keyDigest.digest());
}
示例14: getDataDigestAsBase64
import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
public String getDataDigestAsBase64() {
invalidUpdateState = true;
return Base64.encodeBase64String(dataDigest.digest());
}
示例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;
}