本文整理了Java中org.apache.commons.codec.binary.Base64.encodeBase64String()
方法的一些代码示例,展示了Base64.encodeBase64String()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base64.encodeBase64String()
方法的具体详情如下:
包路径:org.apache.commons.codec.binary.Base64
类名称:Base64
方法名:encodeBase64String
[英]Encodes binary data using the base64 algorithm but does not chunk the output. NOTE: We changed the behaviour of this method from multi-line chunking (commons-codec-1.4) to single-line non-chunking (commons-codec-1.5).
[中]使用base64算法对二进制数据进行编码,但不分块输出。注意:我们将此方法的行为从多行分块(commons-codec-1.4)更改为单行非分块(commons-codec-1.5)。
代码示例来源:origin: SonarSource/sonarqube
@Override
public String encrypt(String clearText) {
return Base64.encodeBase64String(clearText.getBytes(StandardCharsets.UTF_8));
}
代码示例来源:origin: SonarSource/sonarqube
@Override
public String encrypt(String clearText) {
return Base64.encodeBase64String(clearText.getBytes(StandardCharsets.UTF_8));
}
代码示例来源:origin: hs-web/hsweb-framework
protected String encodeAuthorization(String auth) {
return "basic ".concat(Base64.encodeBase64String(auth.getBytes()));
}
代码示例来源:origin: gocd/gocd
private String getAgentExtraProperties() {
if (agentExtraProperties == null) {
String base64OfSystemProperty = encodeBase64String(systemEnvironment.get(AGENT_EXTRA_PROPERTIES).getBytes(UTF_8));
String base64OfEmptyString = encodeBase64String("".getBytes(UTF_8));
this.agentExtraProperties = base64OfSystemProperty.length() >= MAX_HEADER_LENGTH ? base64OfEmptyString : base64OfSystemProperty;
}
return agentExtraProperties;
}
代码示例来源:origin: twosigma/beakerx
protected String[] getPy4jCommand() {
return new String[]{
"beakerx",
"py4j_server",
"--port", port == null ? DEFAULT_PORT : String.valueOf(port),
"--pyport", pythonPort == null ? DEFAULT_PYTHON_PORT : String.valueOf(pythonPort),
"--kernel", kernelName,
"--context", Base64.encodeBase64String(this.context.getBytes(StandardCharsets.UTF_8))
};
}
代码示例来源:origin: SonarSource/sonarqube
String generateRandomSecretKey() {
try {
KeyGenerator keyGen = KeyGenerator.getInstance(CRYPTO_KEY);
keyGen.init(KEY_SIZE_IN_BITS, new SecureRandom());
SecretKey secretKey = keyGen.generateKey();
return Base64.encodeBase64String(secretKey.getEncoded());
} catch (Exception e) {
throw new IllegalStateException("Fail to generate secret key", e);
}
}
代码示例来源:origin: SonarSource/sonarqube
String generateRandomSecretKey() {
try {
KeyGenerator keyGen = KeyGenerator.getInstance(CRYPTO_KEY);
keyGen.init(KEY_SIZE_IN_BITS, new SecureRandom());
SecretKey secretKey = keyGen.generateKey();
return Base64.encodeBase64String(secretKey.getEncoded());
} catch (Exception e) {
throw new IllegalStateException("Fail to generate secret key", e);
}
}
代码示例来源:origin: SonarSource/sonarqube
@Override
public String encrypt(String clearText) {
try {
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(CRYPTO_KEY);
cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, loadSecretFile());
return Base64.encodeBase64String(cipher.doFinal(clearText.getBytes(StandardCharsets.UTF_8.name())));
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
代码示例来源:origin: SonarSource/sonarqube
@Override
public String encrypt(String clearText) {
try {
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(CRYPTO_KEY);
cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, loadSecretFile());
return Base64.encodeBase64String(cipher.doFinal(clearText.getBytes(UTF_8)));
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
代码示例来源:origin: twitter/distributedlog
/**
* Serialize the DLSN into base64 encoded string with given <code>version</code>.
*
* @param version
* version to serialize the DLSN
* @return the serialized base64 string
* @see #serializeBytes(byte)
*/
public String serialize(byte version) {
return Base64.encodeBase64String(serializeBytes(version));
}
代码示例来源:origin: gocd/gocd
protected void doHead(HttpServletRequest request, HttpServletResponse response) {
try {
response.setHeader("Content-MD5", resource.getMd5());
response.setHeader("Cruise-Server-Ssl-Port", String.valueOf(fakeGoServer.getSecurePort()));
final String extraPropertiesHeaderValue = fakeGoServer.getExtraPropertiesHeaderValue();
if (extraPropertiesHeaderValue != null) {
response.setHeader(AGENT_EXTRA_PROPERTIES_HEADER, Base64.encodeBase64String(extraPropertiesHeaderValue.getBytes(StandardCharsets.UTF_8)));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: gocd/gocd
@RequestMapping(value = "/admin/agent/token", method = RequestMethod.GET)
public ResponseEntity getToken(@RequestParam("uuid") String uuid) {
if (StringUtils.isBlank(uuid)) {
String message = "UUID cannot be blank.";
LOG.error("Rejecting request for token. Error: HttpCode=[{}] Message=[{}] UUID=[{}]", CONFLICT, message, uuid);
return new ResponseEntity<>(message, CONFLICT);
}
final AgentInstance agentInstance = agentService.findAgent(uuid);
if ((!agentInstance.isNullAgent() && agentInstance.isPending()) || goConfigService.hasAgent(uuid)) {
String message = "A token has already been issued for this agent.";
LOG.error("Rejecting request for token. Error: HttpCode=[{}] Message=[{}] Pending=[{}] UUID=[{}]",
CONFLICT, message, agentInstance.isPending(), uuid);
return new ResponseEntity<>(message, CONFLICT);
}
return new ResponseEntity<>(encodeBase64String(hmac().doFinal(uuid.getBytes())), OK);
}
代码示例来源:origin: apache/hive
private static String serializeToken(Token<JobTokenIdentifier> token) {
byte[] bytes = null;
try {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
token.write(out);
bytes = out.toByteArray();
} catch (IOException e) {
// This shouldn't really happen on a byte array.
throw new RuntimeException(e);
}
return Base64.encodeBase64String(bytes);
}
代码示例来源:origin: testcontainers/testcontainers-java
@Override
protected void configure() {
withCreateContainerCmdModifier(it -> it.withEntrypoint("/bin/sh"));
setCommand(
"-c",
"echo '" + Base64.encodeBase64String(vncPassword.getBytes()) + "' | base64 -d > /vnc_password && " +
"flvrec.py -o " + RECORDING_FILE_NAME + " -d -r " + frameRate + " -P /vnc_password " + targetNetworkAlias + " " + vncPort
);
}
代码示例来源:origin: gocd/gocd
private void assertExtraProperties(String actualHeaderValueBeforeBase64, Map<String, String> expectedProperties) {
String headerValueInBase64 = Base64.encodeBase64String(actualHeaderValueBeforeBase64.getBytes(UTF_8));
assertExtraPropertiesWithoutBase64(headerValueInBase64, expectedProperties);
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldFailQuietlyWhenExtraPropertiesHeaderValueIsInvalid() throws Exception {
setupForNoChangesToMD5();
final Map<Object, Object> before = System.getProperties().entrySet().stream().collect(toMap(Entry::getKey, Entry::getValue));
expectHeaderValue(SystemEnvironment.AGENT_EXTRA_PROPERTIES_HEADER, encodeBase64String("this_is_invalid".getBytes(UTF_8)));
agentUpgradeService.checkForUpgradeAndExtraProperties();
final Map<Object, Object> after = System.getProperties().entrySet().stream().collect(toMap(Entry::getKey, Entry::getValue));
assertThat(after, is(before));
}
代码示例来源:origin: commons-codec/commons-codec
private void testEncodeDecode(final String plainText) {
final String encodedText = Base64.encodeBase64String(StringUtils.getBytesUtf8(plainText));
final String decodedText = StringUtils.newStringUsAscii(Base64.decodeBase64(encodedText));
assertEquals(plainText, decodedText);
}
代码示例来源:origin: commons-codec/commons-codec
private void testDecodeEncode(final String encodedText) {
final String decodedText = StringUtils.newStringUsAscii(Base64.decodeBase64(encodedText));
final String encodedText2 = Base64.encodeBase64String(StringUtils.getBytesUtf8(decodedText));
assertEquals(encodedText, encodedText2);
}
代码示例来源:origin: apache/hive
public static String toKryo(SearchArgument sarg) {
Output out = new Output(4 * 1024, 10 * 1024 * 1024);
new Kryo().writeObject(out, sarg);
out.close();
return Base64.encodeBase64String(out.toBytes());
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldSetAnyExtraPropertiesSentByTheServer() throws Exception {
setupForNoChangesToMD5();
expectHeaderValue(SystemEnvironment.AGENT_EXTRA_PROPERTIES_HEADER, encodeBase64String("abc=def%20ghi jkl%20mno=pqr%20stu".getBytes(UTF_8)));
agentUpgradeService.checkForUpgradeAndExtraProperties();
assertThat(System.getProperty("abc"), is("def ghi"));
assertThat(System.getProperty("jkl mno"), is("pqr stu"));
}
内容来源于网络,如有侵权,请联系作者删除!