本文整理了Java中org.apache.commons.codec.binary.Base64.encodeToString()
方法的一些代码示例,展示了Base64.encodeToString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base64.encodeToString()
方法的具体详情如下:
包路径:org.apache.commons.codec.binary.Base64
类名称:Base64
方法名:encodeToString
暂无
代码示例来源:origin: apache/usergrid
public static String base64( byte[] bytes ) {
return base64.encodeToString( bytes );
}
代码示例来源:origin: apache/hive
/**
* Get the signature of the input string based on SHA digest algorithm.
* @param str Input token
* @return Signed String
*/
private String getSignature(String str) {
try {
MessageDigest md = MessageDigest.getInstance(SHA_STRING);
md.update(str.getBytes());
md.update(secretBytes);
byte[] digest = md.digest();
return new Base64(0).encodeToString(digest);
} catch (NoSuchAlgorithmException ex) {
throw new RuntimeException("Invalid SHA digest String: " + SHA_STRING +
" " + ex.getMessage(), ex);
}
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public String createTamperProofSeal(String secretKey, String customerId, String orderId)
throws NoSuchAlgorithmException, InvalidKeyException {
//Create a URL-Safe Base64 encoder as some of these may get passed back as URL GET parameters
Base64 encoder = new Base64(true);
Mac sha1Mac = Mac.getInstance("HmacSHA1");
SecretKeySpec publicKeySpec = new SecretKeySpec(secretKey.getBytes(), "HmacSHA1");
sha1Mac.init(publicKeySpec);
String customerOrderString = customerId + orderId;
byte[] publicBytes = sha1Mac.doFinal(customerOrderString.getBytes());
String publicDigest = encoder.encodeToString(publicBytes);
return publicDigest.replaceAll("\\r|\\n", "");
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
/**
* Encode byte[] value to string representation with encoding.
* Values encoded as text strings are enclosed in double quotes (\"),
* while strings encoded as hexadecimal and base64 are prefixed with
* 0x and 0s, respectively.
* @param value byte[] value
* @param encoding
* @return String string representation of value
* @throws IOException
*/
public static String encodeValue(byte[] value, XAttrCodec encoding)
throws IOException {
Preconditions.checkNotNull(value, "Value can not be null.");
if (encoding == HEX) {
return HEX_PREFIX + Hex.encodeHexString(value);
} else if (encoding == BASE64) {
return BASE64_PREFIX + base64.encodeToString(value);
} else {
return "\"" + new String(value, "utf-8") + "\"";
}
}
}
代码示例来源:origin: apache/usergrid
public static String base64( UUID uuid ) {
return base64.encodeToString( bytes( uuid ) );
}
代码示例来源:origin: Javen205/IJPay
/**
* 私钥签名
*
* @param data
* @param privateKey
* @return
* @throws Exception
*/
public static String encryptByPrivateKey(String data, String privateKey) throws Exception {
PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(base64.decode(privateKey));
KeyFactory keyf = KeyFactory.getInstance("RSA");
PrivateKey priKey = keyf.generatePrivate(priPKCS8);
java.security.Signature signature = java.security.Signature.getInstance("SHA256WithRSA");
signature.initSign(priKey);
signature.update(data.getBytes("UTf-8"));
byte[] signed = signature.sign();
return base64.encodeToString(signed);
}
/**
代码示例来源:origin: Javen205/IJPay
return base64.encodeToString(encryptedData);
代码示例来源:origin: org.apache.hadoop/hadoop-common
/**
* Generate a string with the url-quoted base64 encoded serialized form
* of the Writable.
* @param obj the object to serialize
* @return the encoded string
* @throws IOException
*/
private static String encodeWritable(Writable obj) throws IOException {
DataOutputBuffer buf = new DataOutputBuffer();
obj.write(buf);
Base64 encoder = new Base64(0, null, true);
byte[] raw = new byte[buf.getLength()];
System.arraycopy(buf.getData(), 0, raw, 0, buf.getLength());
return encoder.encodeToString(raw);
}
代码示例来源:origin: chanjarster/weixin-java-tools
String base64Encrypted = base64.encodeToString(encrypted);
代码示例来源:origin: liyiorg/weixin-popular
String base64Encrypted = base64.encodeToString(encrypted);
代码示例来源:origin: commons-codec/commons-codec
@Test
public void testByteToStringVariations() throws DecoderException {
final Base64 base64 = new Base64(0);
final byte[] b1 = StringUtils.getBytesUtf8("Hello World");
final byte[] b2 = new byte[0];
final byte[] b3 = null;
final byte[] b4 = Hex.decodeHex("2bf7cc2701fe4397b49ebeed5acc7090"); // for
// url-safe
// tests
assertEquals("byteToString Hello World", "SGVsbG8gV29ybGQ=", base64.encodeToString(b1));
assertEquals("byteToString static Hello World", "SGVsbG8gV29ybGQ=", Base64.encodeBase64String(b1));
assertEquals("byteToString \"\"", "", base64.encodeToString(b2));
assertEquals("byteToString static \"\"", "", Base64.encodeBase64String(b2));
assertEquals("byteToString null", null, base64.encodeToString(b3));
assertEquals("byteToString static null", null, Base64.encodeBase64String(b3));
assertEquals("byteToString UUID", "K/fMJwH+Q5e0nr7tWsxwkA==", base64.encodeToString(b4));
assertEquals("byteToString static UUID", "K/fMJwH+Q5e0nr7tWsxwkA==", Base64.encodeBase64String(b4));
assertEquals("byteToString static-url-safe UUID", "K_fMJwH-Q5e0nr7tWsxwkA",
Base64.encodeBase64URLSafeString(b4));
}
代码示例来源:origin: javahongxi/whatsmars
public static String encryptToBase64(String data, String key){
try {
byte[] valueByte = encrypt(data.getBytes(DEFAULT_ENCODING), key.getBytes(DEFAULT_ENCODING));
return new Base64().encodeToString(valueByte);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("encrypt fail!", e);
}
}
代码示例来源:origin: wstrange/GoogleAuth
/**
* This method calculates the secret key given a random byte buffer.
*
* @param secretKey a random byte buffer.
* @return the secret key.
*/
private String calculateSecretKey(byte[] secretKey)
{
switch (config.getKeyRepresentation())
{
case BASE32:
return new Base32().encodeToString(secretKey);
case BASE64:
return new Base64().encodeToString(secretKey);
default:
throw new IllegalArgumentException("Unknown key representation type.");
}
}
代码示例来源:origin: sd4324530/fastweixin
String base64Encrypted = base64.encodeToString(encrypted);
代码示例来源:origin: borball/weixin-sdk
return base64.encodeToString(encrypted);
} catch (Exception e) {
logger.error("MessageDecryption encrypt failed.", e);
代码示例来源:origin: Netflix/hollow
break;
case BYTES:
fieldValue = base64.encodeToString(typeDataAccess.readBytes(effigy.ordinal, i));
break;
case DOUBLE:
代码示例来源:origin: oVirt/ovirt-engine
private static String generateClientSecret() {
byte[] s = new byte[32];
secureRandom.nextBytes(s);
return new Base64(0, new byte[0], true).encodeToString(s);
}
代码示例来源:origin: org.apache.knox/gateway-spi
protected void writeCertificateToFile( Certificate cert, final File file ) throws CertificateEncodingException, IOException {
byte[] bytes = cert.getEncoded();
Base64 encoder = new Base64( 76, "\n".getBytes( StandardCharsets.US_ASCII ) );
try( final FileOutputStream out = new FileOutputStream( file ) ) {
out.write( "-----BEGIN CERTIFICATE-----\n".getBytes( StandardCharsets.US_ASCII ) );
out.write( encoder.encodeToString( bytes ).getBytes( StandardCharsets.US_ASCII ) );
out.write( "-----END CERTIFICATE-----\n".getBytes( StandardCharsets.US_ASCII ) );
}
}
代码示例来源:origin: org.apache.knox/gateway-spi
public static void writeCertificateToFile(Certificate cert, final File file)
throws CertificateEncodingException, IOException {
byte[] bytes = cert.getEncoded();
Base64 encoder = new Base64( 76, "\n".getBytes( StandardCharsets.US_ASCII ) );
try( final FileOutputStream out = new FileOutputStream( file ) ) {
out.write( "-----BEGIN CERTIFICATE-----\n".getBytes( StandardCharsets.US_ASCII ) );
out.write( encoder.encodeToString( bytes ).getBytes( StandardCharsets.US_ASCII ) );
out.write( "-----END CERTIFICATE-----\n".getBytes( StandardCharsets.US_ASCII ) );
}
}
代码示例来源:origin: apache/oozie
private static String computeSignature(byte[] secret, String str) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(str.getBytes());
md.update(secret);
byte[] digest = md.digest();
return new Base64(0).encodeToString(digest);
}
内容来源于网络,如有侵权,请联系作者删除!