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


Java StringUtils.newStringUtf8方法代碼示例

本文整理匯總了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);
}
 
開發者ID:GJWT,項目名稱:javaOIDCMsg,代碼行數:24,代碼來源:JWTDecoder.java

示例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();
}
 
開發者ID:IBM,項目名稱:spring-boot-continuous-delivery,代碼行數:26,代碼來源:Application.java

示例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);
    }
}
 
開發者ID:yangshuai0711,項目名稱:dingding-app-server,代碼行數:27,代碼來源:EncryptUtils.java

示例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();
		}
	}
}
 
開發者ID:Matsemann,項目名稱:eamaster,代碼行數:26,代碼來源:ResultFileWriter.java

示例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;
}
 
開發者ID:everit-org,項目名稱:password-encryptor-pbkdf2,代碼行數:17,代碼來源:PBKDF2PasswordEncryptorImpl.java

示例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);
  }
}
 
開發者ID:h2oai,項目名稱:h2o-2,代碼行數:17,代碼來源:VM.java

示例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;
        }
    }
}
 
開發者ID:inbloom,項目名稱:secure-data-service,代碼行數:23,代碼來源:AesCipher.java

示例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 "";
}
 
開發者ID:wp521,項目名稱:MyFire,代碼行數:18,代碼來源:DESBase64Util.java

示例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 "";
}
 
開發者ID:by-syk,項目名稱:SchTtableServer,代碼行數:17,代碼來源:DESBase64Util.java

示例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();
}
 
開發者ID:discord-java,項目名稱:discord.jar,代碼行數:8,代碼來源:AccountManagerImpl.java

示例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;
        }
    } );

}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:33,代碼來源:JdbcStorageDaoBase64Impl.java

示例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;
}
 
開發者ID:xtf-cz,項目名稱:xtf,代碼行數:9,代碼來源:HttpClient.java

示例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]);
}
 
開發者ID:mvetsch,項目名稱:JWT4B,代碼行數:12,代碼來源:CustomJWToken.java

示例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;
}
 
開發者ID:sakaiproject,項目名稱:sakai,代碼行數:32,代碼來源:BaseExternalCalendarSubscriptionService.java

示例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));
}
 
開發者ID:onyxbits,項目名稱:raccoon4,代碼行數:11,代碼來源:Traits.java


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