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


Java StringUtils.getBytesUtf8方法代碼示例

本文整理匯總了Java中org.apache.commons.codec.binary.StringUtils.getBytesUtf8方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils.getBytesUtf8方法的具體用法?Java StringUtils.getBytesUtf8怎麽用?Java StringUtils.getBytesUtf8使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.codec.binary.StringUtils的用法示例。


在下文中一共展示了StringUtils.getBytesUtf8方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: desEncode

import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
/**
 * DES算法,加密
 *
 * @param data 待加密字符串
 * @param key  加密私鑰,長度不能夠小於8位
 * @return 加密後字符串
 * @throws Exception
 */
public static String desEncode(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.ENCRYPT_MODE, secretKey, paramSpec);
        byte[] bytes = cipher.doFinal(StringUtils.getBytesUtf8(data));
        return Hex.encodeHexString(bytes);
    } catch (Exception e) {
        throw new RuntimeException("des加密失敗", e);
    }
}
 
開發者ID:yangshuai0711,項目名稱:dingding-app-server,代碼行數:27,代碼來源:EncryptUtils.java

示例2: 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

示例3: deflate

import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
public static byte[] deflate(final String data) throws SCSException {
    final byte[] toDeflate = StringUtils.getBytesUtf8(data);
    final Deflater deflater = new Deflater();
    final byte[] tmp = new byte[4096];

    deflater.setInput(toDeflate);
    deflater.finish();
    final int outSize = deflater.deflate(tmp);
    if(!deflater.finished()) {
        throw new SCSException("Can not deflate session data. Data is too large.");
    }
    deflater.end();

    final byte[] out = new byte[outSize];
    System.arraycopy(tmp, 0, out, 0, outSize);
    return out;
}
 
開發者ID:brainysmith,項目名稱:scs-lib,代碼行數:18,代碼來源:DeflateUtils.java

示例4: createHmac

import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
@Override
public byte[] createHmac(String tid, String msg) {
    final byte[] result = new byte[mac.getMacSize()];
    final byte[] in = StringUtils.getBytesUtf8(msg);
    mac.update(in, 0, in.length);
    mac.doFinal(result, 0);
    return result;
}
 
開發者ID:brainysmith,項目名稱:scs-lib,代碼行數:9,代碼來源:SimpleCryptoService.java

示例5: testDecodeNibbleHex

import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
@Test
public void testDecodeNibbleHex() throws DecoderException {
    byte[] bytes = StringUtils
            .getBytesUtf8("F0F1F0F0723C440188E18008F1F9F5F4F0F5F6F2F0F0F0F0F0F0F0F0F0F0F0F1F4F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F5F0F5F0F1F2F0F1F3F0F3F0F9F5F8F9F2F7F8F1F3F0F3F0F9F0F1F2F0F1F5F1F1F5F4F1F1F8F1F2F0F6F0F1F3F4F0F1F0F6F2F0F0F3F5F0F0F1F2F0F1F4F5F4F9F3F5F482F0F0F0F0F0F0F1D9C5E3D382F0F0F0F0F0F0F1404040C3C3C240E3F140E28899A340D581948540404040404040C3C3C240E3F140E28899A340D340D7C1D5F0F6F0E3F6F1F0F5F0F0F0F0F1F9F2F0F35C5C5CF4F2F0F7F0F1F0F3F2F1F2F4F3F2F891C982A884F6E38581889492C1C2C5C1C1C1C699D894A8E7A694F07EF9F7F8F0F2F1F1F0F2F5F1F0F0F0F0F6F0F0F0F5F9F1D7C1D5F1F2");
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < bytes.length; i++) {
    }
    Hex hexer = new Hex();
    byte[] bytesDec = hexer.decode(bytes);
    for (int i = 0; i < bytesDec.length; i++) {
        sb.append(String.format("%01X", bytesDec[i]));
    }
}
 
開發者ID:wakantanka,項目名稱:get_iso_8583,代碼行數:14,代碼來源:SplitMsgPartsTest.java

示例6: sendPostRequest

import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
/**
 * @param requestURL Ссылка на получателя
 * @param data POST-данные
 * @return Возвращает строку содержащую ответ сервера. Если отправить запрос
 *         или получить ответ не удалось, возвращается строка BAD_CONNECTION
 * @throws IOException
 */
public static final String sendPostRequest(URL requestURL, String data) throws IOException {
	byte[] bytes = StringUtils.getBytesUtf8(data);

	HttpURLConnection conn = (HttpURLConnection) requestURL.openConnection();
	conn.setRequestMethod("POST");
	conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
	conn.setRequestProperty("Content-Length", Integer.toString(bytes.length));

	conn.setUseCaches(false);
	conn.setDoInput(true);
	conn.setDoOutput(true);

	conn.connect();

	OutputStream wr = conn.getOutputStream();
	wr.write(bytes);
	wr.flush();
	wr.close();

	StringBuffer s = new StringBuffer();
	BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
	String line;

	while ((line = reader.readLine()) != null) {
		s.append(line);
	}
	reader.close();

	return s.toString();
}
 
開發者ID:Sinrel,項目名稱:SinrelLauncherEngine-Dev,代碼行數:38,代碼來源:NetManager.java

示例7: setKey

import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
public void setKey(String k) {
    key = StringUtils.getBytesUtf8(k);
}
 
開發者ID:runhwguo,項目名稱:GeneratePasswordWithOneKey,代碼行數:4,代碼來源:Util.java

示例8: appendPredicate

import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
private static void appendPredicate(final Statement statement, final Text keyText) {
       final Value statementValue = new Value(StringUtils.getBytesUtf8(StatementSerializer.writePredicate(statement)));
       final byte[] hashOfValue = uniqueFromValueForKey(statementValue);
       appendBytes(HASH_PREFIX, keyText); // prefix the hash with a zero byte.
       appendBytes(hashOfValue, keyText);
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:7,代碼來源:KeyParts.java

示例9: appendSubjectPredicate

import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
private static void appendSubjectPredicate(final Statement statement, final Text keyText) {
       final Value statementValue = new Value(StringUtils.getBytesUtf8(StatementSerializer.writeSubjectPredicate(statement)));
       final byte[] hashOfValue = uniqueFromValueForKey(statementValue);
       appendBytes(HASH_PREFIX, keyText); // prefix the hash with a zero byte.
       appendBytes(hashOfValue, keyText);
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:7,代碼來源:KeyParts.java

示例10: getAsKeyBytes

import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
@Override
public byte[] getAsKeyBytes() {
    return StringUtils.getBytesUtf8(getAsKeyString());
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:5,代碼來源:TemporalInstantRfc3339.java

示例11: getBytesUtf8

import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
private static byte[] getBytesUtf8(String data)
/*  28:    */   {
/*  29: 69 */     return StringUtils.getBytesUtf8(data);
/*  30:    */   }
 
開發者ID:xiwc,項目名稱:confluence.keygen,代碼行數:5,代碼來源:DigestUtils.java

示例12: createHmac

import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
@Override
public byte[] createHmac(String tid, String msg) {
    final byte[] in = StringUtils.getBytesUtf8(msg);
    return mac.get().doFinal(in);
}
 
開發者ID:brainysmith,項目名稱:scs-lib,代碼行數:6,代碼來源:BasicCryptoService.java

示例13: getBytesUtf8

import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
private static byte[] getBytesUtf8(String paramString)
{
  return StringUtils.getBytesUtf8(paramString);
}
 
開發者ID:zhangjianying,項目名稱:12306-android-Decompile,代碼行數:5,代碼來源:DigestUtils.java

示例14: testBase64Encoder

import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
@Test
public void testBase64Encoder() {
  final byte[] value = StringUtils.getBytesUtf8("123");
  final IFunctions.Base64Encoder f = IFunctions.Base64Encoder.INSTANCE;
  Assert.assertEquals(Base64.encodeBase64String(value), f.func(value));
}
 
開發者ID:OfficeDev,項目名稱:ews-java-api,代碼行數:7,代碼來源:IFunctionsTest.java

示例15: getIVSpec

import org.apache.commons.codec.binary.StringUtils; //導入方法依賴的package包/類
private static IvParameterSpec getIVSpec() {
	return new IvParameterSpec(StringUtils.getBytesUtf8("%jUS*(Aol(-y)lC/"));
}
 
開發者ID:Sinrel,項目名稱:SinrelLauncherEngine-Dev,代碼行數:4,代碼來源:AES.java


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