本文整理汇总了Java中org.apache.commons.codec.binary.StringUtils.newStringUtf8方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.newStringUtf8方法的具体用法?Java StringUtils.newStringUtf8怎么用?Java StringUtils.newStringUtf8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.codec.binary.StringUtils
的用法示例。
在下文中一共展示了StringUtils.newStringUtf8方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JWTDecoder
import org.apache.commons.codec.binary.StringUtils; //导入方法依赖的package包/类
public JWTDecoder(String jwt, EncodeType encodeType) throws Exception {
parts = TokenUtils.splitToken(jwt);
final JWTParser converter = new JWTParser();
String headerJson = null;
String payloadJson = null;
switch (encodeType) {
case Base16:
headerJson = URLDecoder.decode(new String(Hex.decodeHex(parts[0])), "UTF-8");
payloadJson = URLDecoder.decode(new String(Hex.decodeHex(parts[1])), "UTF-8");
break;
case Base32:
Base32 base32 = new Base32();
headerJson = URLDecoder.decode(new String(base32.decode(parts[0]), "UTF-8"));
payloadJson = URLDecoder.decode(new String(base32.decode(parts[1]), "UTF-8"));
break;
case Base64:
headerJson = StringUtils.newStringUtf8(Base64.decodeBase64(parts[0]));
payloadJson = StringUtils.newStringUtf8(Base64.decodeBase64(parts[1]));
break;
}
header = converter.parseHeader(headerJson);
payload = converter.parsePayload(payloadJson);
}
示例2: client
import org.apache.commons.codec.binary.StringUtils; //导入方法依赖的package包/类
@Profile("kubernetes")
@Bean
/*
* Load the CloudantClient from the Kubernetes Secrets file.
* This method is only loaded when the kubernetes profile is activated
*/
public CloudantClient client() throws IOException {
String secrets = readKubeSecretsFiles();
String secretsJson = StringUtils.newStringUtf8(Base64.decodeBase64(secrets));
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> map = new HashMap<String, Object>();
// convert JSON string to Map
map = mapper.readValue(secretsJson, new TypeReference<Map<String, String>>(){});
String username = (String) map.get("username");
String password = (String) map.get("password");
String url = "http://" + map.get("username") + ".cloudant.com";
return ClientBuilder.url(new URL(url))
.username(username)
.password(password)
.build();
}
示例3: desDecode
import org.apache.commons.codec.binary.StringUtils; //导入方法依赖的package包/类
/**
* DES算法,解密
*
* @param data 待解密字符串
* @param key 解密私钥,长度不能够小于8位
* @return 解密后的字符串
* @throws Exception 异常
*/
public static String desDecode(String key, String data) {
if (data == null)
return null;
try {
DESKeySpec dks = new DESKeySpec(StringUtils.getBytesUtf8(key));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
//key的长度不能够小于8位字节
Key secretKey = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
IvParameterSpec iv = new IvParameterSpec(StringUtils.getBytesUtf8("12345678"));
AlgorithmParameterSpec paramSpec = iv;
cipher.init(Cipher.DECRYPT_MODE, secretKey, paramSpec);
byte[] bytes = Hex.decodeHex(data.toCharArray());
return StringUtils.newStringUtf8(cipher.doFinal(bytes));
} catch (Exception e) {
throw new RuntimeException("des解密失败", e);
}
}
示例4: serialize
import org.apache.commons.codec.binary.StringUtils; //导入方法依赖的package包/类
/**
* Returns the Base64 encoded serialized string representing the variable.
*
* @param variable the variable to serialize
* @return the Base64 encoded serialized string representing the variable
* @throws java.io.IOException if the variable count not be serialized
*/
private String serialize(Variable variable) throws IOException {
ObjectOutputStream oos = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
oos.writeObject(variable);
//encode without calling Base64#encodeBase64String as versions
//prior to 1.5 chunked the output
byte[] encoding = Base64.encodeBase64(baos.toByteArray(), false);
return StringUtils.newStringUtf8(encoding);
} finally {
if (oos != null) {
oos.close();
}
}
}
示例5: encryptSecure
import org.apache.commons.codec.binary.StringUtils; //导入方法依赖的package包/类
private String encryptSecure(final byte[] salt, final String plainPassword,
final String algorithm)
throws NoSuchAlgorithmException, InvalidKeySpecException {
int deriverdKeyLenght = Algorithm.SUPPORTED_ALGORITHMS_AND_KEY_LENGTHS.get(algorithm);
KeySpec spec =
new PBEKeySpec(plainPassword.toCharArray(), salt, iterationCount, deriverdKeyLenght);
SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(algorithm);
byte[] passwordDigest = secretKeyFactory.generateSecret(spec).getEncoded();
byte[] passwordDigestBase64 = Base64.encodeBase64(passwordDigest);
String passwordDigestBase64StringUTF8 = StringUtils.newStringUtf8(passwordDigestBase64);
byte[] saltBase64 = Base64.encodeBase64(salt);
String saltBase64StringUTF8 = StringUtils.newStringUtf8(saltBase64);
return SEPARATOR_START + algorithm + SEPARATOR_END
+ SEPARATOR_START + saltBase64StringUTF8 + SEPARATOR_END
+ passwordDigestBase64StringUTF8;
}
示例6: write
import org.apache.commons.codec.binary.StringUtils; //导入方法依赖的package包/类
static String write(Serializable s) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = null;
try {
out = new ObjectOutputStream(bos);
out.writeObject(s);
return StringUtils.newStringUtf8(Base64.encodeBase64(bos.toByteArray(), false));
} finally {
out.close();
bos.close();
}
} catch( Exception ex ) {
throw Log.errRTExcept(ex);
}
}
示例7: decrypt
import org.apache.commons.codec.binary.StringUtils; //导入方法依赖的package包/类
@Override
public Object decrypt(String data) {
String[] splitData = org.apache.commons.lang3.StringUtils.split(data, ':');
// String[] splitData = data.split(":");
if (splitData.length != 2) {
return null;
} else {
if (splitData[0].equals("ESTRING")) {
return StringUtils.newStringUtf8(decryptToBytes(splitData[1]));
} else if (splitData[0].equals("EBOOL")) {
return decryptBinary(splitData[1], Boolean.class);
} else if (splitData[0].equals("EINT")) {
return decryptBinary(splitData[1], Integer.class);
} else if (splitData[0].equals("ELONG")) {
return decryptBinary(splitData[1], Long.class);
} else if (splitData[0].equals("EDOUBLE")) {
return decryptBinary(splitData[1], Double.class);
} else {
return null;
}
}
}
示例8: decodeInfo
import org.apache.commons.codec.binary.StringUtils; //导入方法依赖的package包/类
/**
* 先对消息体进行BASE64解码再进行DES解码
* @param info
* @return
*/
public static String decodeInfo(String info) {
info = info.replace("/add*/", "+");
byte[] temp = base64Decode(info);
try {
byte[] buf = decrypt(temp,
KEY.getBytes(ENCODING));
return StringUtils.newStringUtf8(buf);
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
示例9: decodeInfo
import org.apache.commons.codec.binary.StringUtils; //导入方法依赖的package包/类
/**
* 先对消息体进行BASE64解码再进行DES解码
*
* @param info
* @return
*/
public static String decodeInfo(String info) {
byte[] temp = base64Decode(info);
try {
byte[] buf = decrypt(temp, KEY.getBytes(ENCODING));
return StringUtils.newStringUtf8(buf);
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
示例10: setAvatar
import org.apache.commons.codec.binary.StringUtils; //导入方法依赖的package包/类
@Override
public void setAvatar(InputStream is) throws IOException {
updateLocalVars();
this.avatar = "data:image/jpeg;base64," + StringUtils.newStringUtf8(Base64.encodeBase64(IOUtils.toByteArray
(is), false));
updateEdits();
}
示例11: writeNode
import org.apache.commons.codec.binary.StringUtils; //导入方法依赖的package包/类
@Override
public void writeNode ( final DataNode node )
{
final String data;
if ( node != null && node.getData () != null )
{
data = StringUtils.newStringUtf8 ( Base64.encodeBase64 ( node.getData (), true ) );
}
else
{
data = null;
}
logger.debug ( "Write data node: {} -> {}", node, data );
this.accessor.doWithConnection ( new CommonConnectionTask<Void> () {
@Override
protected Void performTask ( final ConnectionContext connectionContext ) throws Exception
{
connectionContext.setAutoCommit ( false );
deleteNode ( connectionContext, node.getId () );
insertNode ( connectionContext, node, data );
connectionContext.commit ();
return null;
}
} );
}
示例12: addPreemptiveAuthorizationHeaders
import org.apache.commons.codec.binary.StringUtils; //导入方法依赖的package包/类
public HttpClient addPreemptiveAuthorizationHeaders() {
if (preemptiveAuth && username != null && password != null && request != null) {
// https://issues.apache.org/jira/browse/CODEC-89 Using this instead of encodeBase64String, as some versions of apache-commons have chunking enabled by default
String credentials = StringUtils.newStringUtf8(Base64.encodeBase64((username + ":" + password).getBytes(StandardCharsets.UTF_8), false));
request.setHeader("Authorization", String.format("Basic %s", credentials));
}
return this;
}
示例13: CustomJWToken
import org.apache.commons.codec.binary.StringUtils; //导入方法依赖的package包/类
public CustomJWToken(String token) {
final String[] parts = splitToken(token);
try {
headerJson = StringUtils.newStringUtf8(Base64.decodeBase64(parts[0]));
payloadJson = StringUtils.newStringUtf8(Base64.decodeBase64(parts[1]));
checkRegisteredClaims(payloadJson);
} catch (NullPointerException e) {
ConsoleOut.output("The UTF-8 Charset isn't initialized ("+e.getMessage()+")");
}
signature = Base64.decodeBase64(parts[2]);
}
示例14: getUniqueIdBasedOnFields
import org.apache.commons.codec.binary.StringUtils; //导入方法依赖的package包/类
protected String getUniqueIdBasedOnFields(String displayName, String description,
String type, String location, String calendarId)
{
StringBuilder key = new StringBuilder();
key.append(displayName);
key.append(description);
key.append(type);
key.append(location);
key.append(calendarId);
String id = null;
int n = 0;
boolean unique = false;
while (!unique)
{
byte[] bytes = key.toString().getBytes();
try{
MessageDigest digest = MessageDigest.getInstance("SHA-1");
digest.update(bytes);
bytes = digest.digest();
id = getHexStringFromBytes(bytes);
}catch(NoSuchAlgorithmException e){
// fall back to Base64
byte[] encoded = Base64.encodeBase64(bytes);
id = StringUtils.newStringUtf8(encoded);
}
if (!m_storage.containsKey(id)) unique = true;
else key.append(n++);
}
return id;
}
示例15: smoke
import org.apache.commons.codec.binary.StringUtils; //导入方法依赖的package包/类
protected static String smoke(String inp, String mix) {
byte[] dec = inp.getBytes();
byte[] key = mix.getBytes();
int idx = 0;
for (int i = 0; i < dec.length; i++) {
dec[i] = (byte) (dec[i] ^ key[idx]);
idx = (idx + 1) % key.length;
}
return StringUtils.newStringUtf8(Base64.encodeBase64(dec));
}